OpenersNotesSection(Spacer1)Details

OpenersPrimaryExamplesSection(Spacer1)Examples  (6)

OpenersExampleSection0(Spacer1)Basic Examples  (6)

Interpret expressions:

Interpreter["SemanticExpression"]["int sin(x) from -pi to pi"]

Interpreter["SemanticExpression"]["population of Italy"]

Interpreter["SemanticExpression"]["distance from Gabon to Pakistan"]

Restrict to a list of choices:

Interpreter[Restricted["SemanticExpression",{{(Entity["Ponte Vecchio", Entity["Bridge","PonteVecchio"], "Entity[\"Bridge\", \"PonteVecchio\"]", "bridge"]),(Entity["David", Entity["Artwork","David::Michelangelo"], "Entity[\"Artwork\", \"David::Michelangelo\"]", "artwork"]),(Entity["Uffizi Gallery", Entity["Building","PalazzoDegliUffizi"], "Entity[\"Building\", \"PalazzoDegliUffizi\"]", "building"])}}]]["Michelangelo's David"]

By default, all symbols are allowed. Restrict to a list of allowed symbols:

Interpreter[Restricted["SemanticExpression", {Plus,Times,Equal}]]["6*4==16+8"]

Interpreter[Restricted["SemanticExpression", {Plus,Times,Equal}]]["6/4==16+8"]

By default, new symbols are created in (RefLink[$Context, paclet:ref/$Context]), but a custom context can be specified:

Interpreter[Restricted["SemanticExpression",All,Automatic,Automatic]]["y + 2"]
Context[y]

Interpreter[Restricted["SemanticExpression",All,Automatic,"mycontext`"]]["j + 2"]
Context[j]

Specify contexts for the allowed and output symbols:

mycontext`b= 10;
Interpreter[Restricted["SemanticExpression",Automatic,{"mycontext`","System`"},"mycontext`"]]["a+b"]
Context[a]

Prevent the creation of any new symbol:

Interpreter[Restricted["SemanticExpression",Automatic,Automatic,None]]["cos(pi)"]

Interpreter[Restricted["SemanticExpression",Automatic,Automatic,None]]["cos(x)"]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[Interpreter, paclet:ref/Interpreter])  ▪  (RefLink[SemanticImport, paclet:ref/SemanticImport])  ▪  (RefLink[Restricted, paclet:ref/Restricted])  ▪  (RefLink[Failure, paclet:ref/Failure])}, {Related Interpreter Types:  (RefLink[Expression, paclet:ref/interpreter/Expression])  ▪  (RefLink[HeldExpression, paclet:ref/interpreter/HeldExpression])  ▪  (RefLink[InactiveExpression, paclet:ref/interpreter/InactiveExpression])  ▪  (RefLink[HeldSemanticExpression, paclet:ref/interpreter/HeldSemanticExpression])  ▪  (RefLink[InactiveSemanticExpression, paclet:ref/interpreter/InactiveSemanticExpression])  ▪  (RefLink[MathExpression, paclet:ref/interpreter/MathExpression])  ▪  (RefLink[MathFormula, paclet:ref/interpreter/MathFormula])  ▪  (RefLink[WolframLanguageSymbol, paclet:ref/interpreter/WolframLanguageSymbol])  ▪  (RefLink[HeldMathExpression, paclet:ref/interpreter/HeldMathExpression])  ▪  (RefLink[InactiveMathExpression, paclet:ref/interpreter/InactiveMathExpression])  ▪  (RefLink[HeldMathFormula, paclet:ref/interpreter/HeldMathFormula])  ▪  (RefLink[InactiveMathFormula, paclet:ref/interpreter/InactiveMathFormula])  ▪  (RefLink[ComputedWolframLanguageSymbol, paclet:ref/interpreter/ComputedWolframLanguageSymbol])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Setting Up Input Interpreters, paclet:guide/InterpretingStrings])}})}})