Open live version
Deploy an Age-Guessing Website
Make a website that guesses people’s ages from their names.
code
CloudDeploy[FormFunction[{"name", "Enter name"} -> "GivenName",
Row[{"You are probably ", #name["MostCommonAge"], " old"}] &,
"PNG"]]
Specify the name in a URL query string rather than in a form:
CloudDeploy[APIFunction[{"name" -> "GivenName"},
Row[{"You are probably ", #name["MostCommonAge"], " old"}] &,
"PNG"]]
how it works
This example was live-coded at the Wolfram Research booth at SXSW, March 11, 2014.
The “MostCommonAge” predictor for given names is built into the Wolfram Language. It analyzes statistical distributions of ages to determine the most common age for a given name:
\!\(\*
NamespaceBox["LinguisticAssistant",
DynamicModuleBox[{WolframAlphaClient`Private`query$$ = "Erin",
WolframAlphaClient`Private`boxes$$ = TemplateBox[{"\"Erin\"",
RowBox[{"Entity", "[",
RowBox[{"\"GivenName\"", ",",
RowBox[{"{",
RowBox[{"\"Erin\"", ",", "\"UnitedStates\"", ",", "\"female\""}],
"}"}]}], "]"}],
"\"Entity[\\\"GivenName\\\", {\\\"Erin\\\", \\\"UnitedStates\\\
\", \\\"female\\\"}]\"", "\"given name\""}, "Entity"],
WolframAlphaClient`Private`allassumptions$$ = {{
"type" -> "Clash", "word" -> "Erin",
"template" -> "Assuming \"${word}\" is ${desc1}. Use as \
${desc2} instead", "count" -> "3",
"Values" -> {{
"name" -> "GivenName", "desc" -> "a given name",
"input" -> "*C.Erin-_*GivenName-"}, {
"name" -> "SolarSystemFeature",
"desc" -> "a solar system feature",
"input" -> "*C.Erin-_*SolarSystemFeature-"}, {
"name" -> "Word", "desc" -> "a word",
"input" -> "*C.Erin-_*Word-"}}}, {
"type" -> "SubCategory", "word" -> "Erin",
"template" -> "Assuming ${desc1}. Use ${desc2} instead",
"count" -> "2",
"Values" -> {{
"name" -> "{Erin, UnitedStates, female}",
"desc" -> "Erin (female)",
"input" -> "*DPClash.GivenNameE.Erin-_**Erin.UnitedStates.\
female--"}, {
"name" -> "{Erin, UnitedStates, male}",
"desc" -> "Erin (male)",
"input" -> "*DPClash.GivenNameE.Erin-_**Erin.UnitedStates.\
male--"}}}}, WolframAlphaClient`Private`assumptions$$ = {},
WolframAlphaClient`Private`open$$ = {1, 2}},
DynamicBox[ToBoxes[
AlphaIntegration`LinguisticAssistantBoxes["", 1,
Dynamic[WolframAlphaClient`Private`query$$],
Dynamic[WolframAlphaClient`Private`boxes$$],
Dynamic[WolframAlphaClient`Private`allassumptions$$],
Dynamic[WolframAlphaClient`Private`assumptions$$],
Dynamic[WolframAlphaClient`Private`open$$]], StandardForm],
ImageSizeCache->{160., {7., 15.}},
TrackedSymbols:>{
WolframAlphaClient`Private`query$$,
WolframAlphaClient`Private`boxes$$,
WolframAlphaClient`Private`allassumptions$$,
WolframAlphaClient`Private`assumptions$$,
WolframAlphaClient`Private`open$$}],
DynamicModuleValues:>{},
UndoTrackedVariables:>{WolframAlphaClient`Private`open$$}],
BaseStyle->{"Deploy"},
DeleteWithContents->True,
Editable->False,
SelectWithContents->True]\)["MostCommonAge"]
Make a website that gives the most common age of a name entered into a form. Click the link in the resulting CloudObject to visit the website:
CloudDeploy[FormFunction[{"name", "Enter name"} -> "GivenName",
Row[{"You are probably ", #name["MostCommonAge"], " old"}] &,
"PNG"]]
Alternatively, you can make a URL whose query string specifies the name:
CloudDeploy[APIFunction[{"name" -> "GivenName"},
Row[{"You are probably ", #name["MostCommonAge"], " old"}] &,
"PNG"]]
This link visits the URL with the name “Erin”:
Hyperlink["https://www.wolframcloud.com/objects/1f3eb7bb-b687-4756-\
92cb-b16c45cec526\
?name=Erin"]