Function Repository Resource:

RandomEntityQuestion

Source Notebook

Generate a random quiz question from the Wolfram Knowledgebase

Contributed by: Jon McLoone

ResourceFunction["RandomEntityQuestion"][]

generates a QuestionObject about a random property of a random Entity.

ResourceFunction["RandomEntityQuestion"][type]

generates a QuestionObject about a random property of a random Entity of the specified type.

ResourceFunction["RandomEntityQuestion"][type,prop]

generates a QuestionObject about the property prop.

ResourceFunction["RandomEntityQuestion"][EntityProperty[type,prop]]

generates a QuestionObject about a property prop of a random Entity of the specified type.

Details and Options

The following options can be given:
"AnswerProperty""Name"which property is used in the answer choices
"ChoiceCount"3the number of choices to offer as the answer to the question
"QuestionText"Automaticthe text to appear as the question prompt
MaxRecursion4the number of times to seek nonduplicate, nonmissing answers
If the Entity values selected are Missing[] or duplicated, ResourceFunction["RandomEntityQuestion"] will generate more. If, after MaxRecursion attempts, it has not generated enough, it will return a shorter list of answers. If it fails to find two choices, it will return $Failed.
Use "QuestionText" to change the prompt. The prompt should typically be either a StringTemplate or TemplateExpression. The template can contain any of the following template slots: "AnswerProperty", "QuestionProperty", "EntityType", "QuestionValue", "AnswerPropertyLabel", "QuestionPropertyLabel".

Examples

Basic Examples (5) 

Ask a question about a random capital city from the "Country" Entity data:

In[1]:=
ResourceFunction["RandomEntityQuestion"]["Country", "CapitalCity"]
Out[1]=

Ask a question about a random director from the "Movie" Entity data:

In[2]:=
ResourceFunction["RandomEntityQuestion"]["Movie", "Director"]
Out[2]=

Ask a question about a random aspect of a movie:

In[3]:=
ResourceFunction["RandomEntityQuestion"]["Movie"]
Out[3]=

Generate a question about any topic known to the Wolfram Knowledgebase:

In[4]:=
ResourceFunction["RandomEntityQuestion"][]
Out[4]=

Generate a random question about dog breeds with images as answer choices:

In[5]:=
ResourceFunction["RandomEntityQuestion"]["DogBreed", "Name", "AnswerProperty" -> "Image"]
Out[5]=

Scope (1) 

The Entity type can also be specified with EntityClass or related EntityClass constructors:

In[6]:=
ResourceFunction["RandomEntityQuestion"][
 EntityClass["Mountain", "AtlasMountains"], "Elevation"]
Out[6]=

Options (5) 

AnswerProperty (3) 

By default, the property value is used in the question prompt and the entity labels are used as the choices:

In[7]:=
ResourceFunction["RandomEntityQuestion"]["Country", "CapitalCity"]
Out[7]=

To reverse the format, use the option "AnswerProperty":

In[8]:=
ResourceFunction["RandomEntityQuestion"]["Country", "AnswerProperty" -> "CapitalCity"]
Out[8]=

Use a specific property together with "AnswerProperty" to make questions that do not involve the Entity name:

In[9]:=
ResourceFunction["RandomEntityQuestion"]["Country", "Area", "AnswerProperty" -> "CapitalCity"]
Out[9]=

ChoiceCount (1) 

Use "ChoiceCount" to change the number of choices provided:

In[10]:=
ResourceFunction["RandomEntityQuestion"]["Airport", "Countries", "ChoiceCount" -> 6]
Out[10]=

QuestionText (1) 

Use "QuestionText" to change the prompt:

In[11]:=
ResourceFunction["RandomEntityQuestion"]["Airport", "Countries", "QuestionText" -> "Which of these airports would you find in `QuestionValue`?"]
Out[11]=

Possible Issues (1) 

If there are insufficient nonduplicate, nonmissing answers found, then RandomEntityQuestion will return $Failed:

In[12]:=
ResourceFunction["RandomEntityQuestion"][
 EntityClass["Country", "Oceania"], "CrimeRate"]
Out[12]=

Publisher

Jon McLoone

Version History

  • 1.0.1 – 30 August 2022
  • 1.0.0 – 01 April 2022

Related Resources

License Information