({{, (RefLink[Interpreter, paclet:ref/Interpreter])[form] 
represents an interpreter object that can be applied to an input to try to interpret it as an object of the specified form. }, {, (RefLink[Interpreter, paclet:ref/Interpreter])[form,test]
returns the interpreted object only if applying test to it yields (RefLink[True, paclet:ref/True]); otherwise it returns a (RefLink[Failure, paclet:ref/Failure]) object.}, {, (RefLink[Interpreter, paclet:ref/Interpreter])[form,test,fail]
returns the result of applying the function fail if the test fails.}})

OpenersNotesSection(Spacer1)Details and Options

(RefLink[Interpreter, paclet:ref/Interpreter])[…][input] applies the interpreter to a particular input, which is typically a string.

Possible form specifications include:

(RefLink[$InterpreterTypes, paclet:ref/$InterpreterTypes]) gives a complete list of possible interpreter types.

(RefLink[Interpreter, paclet:ref/Interpreter])[…][input] returns an interpreted value, (RefLink[Missing, paclet:ref/Missing])["NoInput"] if input is effectively blank, or (RefLink[Failure, paclet:ref/Failure])[…].

In the case of "entity", any domain supported by (RefLink[EntityValue, paclet:ref/EntityValue]) can be used.

(RefLink[Interpreter, paclet:ref/Interpreter])["format"]["input"] is effectively equivalent to (RefLink[ImportString, paclet:ref/ImportString])["input","format"].

(RefLink[Interpreter, paclet:ref/Interpreter])[choices] allows a list of rules or an association for choices. A pure list of values can also be used when there is no ambiguity.

(RefLink[Interpreter, paclet:ref/Interpreter])[form,test][input] applies test to the result of interpreting input using the specified form.

If the result of applying test is (RefLink[True, paclet:ref/True]), then the interpretation of input is returned.

If the result of applying test is a (RefLink[Failure, paclet:ref/Failure]) object, this object is immediately returned.

If the result of applying test is (RefLink[False, paclet:ref/False]) or anything else, then in (RefLink[Interpreter, paclet:ref/Interpreter])[form,test,fail][input] the result of applying fail to the interpretation of input is returned. If no fail is given, then a (RefLink[Failure, paclet:ref/Failure]) object is returned.

If (RefLink[Interpreter, paclet:ref/Interpreter]) directly generates a (RefLink[Failure, paclet:ref/Failure]) object, the following tags are used:

(RefLink[Interpreter, paclet:ref/Interpreter]) supports the following options:

(RefLink[Interpreter, paclet:ref/Interpreter])[spec][{(Subscript[input, 1]),(Subscript[input, 2]),…}] is equivalent to {Interpreter[spec][(Subscript[input, 1])],Interpreter[spec][(Subscript[input, 2]]),…}, except insofar as spec contains constructs such as (RefLink[CompoundElement, paclet:ref/CompoundElement]) or (RefLink[RepeatingElement, paclet:ref/RepeatingElement]) that directly interpret the structure given.

(RefLink[Interpreter, paclet:ref/Interpreter])[form]["(Subscript[string, 1])"|"(Subscript[string, 2])"|…] yields as a result the interpretation of the first of the (Subscript[string, i]) that can be interpreted using the specified form.

Typically, (RefLink[Interpreter, paclet:ref/Interpreter])[form][(RefLink[CloudObject, paclet:ref/CloudObject])[…]], (RefLink[Interpreter, paclet:ref/Interpreter])[form][(RefLink[File, paclet:ref/File])[…]], and (RefLink[Interpreter, paclet:ref/Interpreter])[form][(RefLink[URL, paclet:ref/URL])[…]] yield the result of interpreting the contents of the cloud object, file, or URL according to the specified form.

For other expressions, (RefLink[Interpreter, paclet:ref/Interpreter])[form][expr] returns expr if expr conforms to the specification for form, and returns (RefLink[Failure, paclet:ref/Failure])[…] otherwise.

OpenersPrimaryExamplesSection(Spacer1)Examples  (27)

OpenersExampleSection0(Spacer1)Basic Examples  (8)

Interpret a number in any standard explicit format:

Interpreter["Number"]["4.5e7"]

Interpret a number given linguistically:

Interpreter["SemanticNumber"]["seventy-five"]

Flag a failure if the input given is not of the type specified:

Interpreter["Number"]["January 14"]

Interpret a date, generating a (RefLink[DateObject, paclet:ref/DateObject]):

Interpreter["Date"]["June 23, 1988"]

Interpret a city, generating an (RefLink[Entity, paclet:ref/Entity]) object:

Interpreter["City"]["NYC"]

Interpret a university:

Interpreter["University"]["oxford u."]

Interpret a location, returning a (RefLink[GeoPosition, paclet:ref/GeoPosition]):

Interpreter["Location"]["eiffel tower"]

Interpret a list of numbers:

Interpreter[DelimitedSequence["Number"]]["2,4,5,7,11,15,20"]

Interpret a (RefLink[File, paclet:ref/File]) object:

Interpreter["Image"][File["ExampleData/spikey.tiff"]]

Interpret a (RefLink[URL, paclet:ref/URL]) object:

Interpreter["Sound"][URL["https://www.wolframcloud.com/objects/user-b0c28e9f-876d-4478-9d8b-9e7d18a9ea81/car.mp3"]]

Interpret a number restricted to be between 1 and 10:

Interpreter[Restricted["Number",{1,10}]]["6"]

If the number is outside the range, a failure is generated:

Interpreter[Restricted["Number",{1,10}]]["11"]

Interpret a city restricted to a geographical region:

Interpreter[Restricted["City",(Entity["Italy", Entity["Country","Italy"], "Entity[\"Country\", \"Italy\"]", "country"])]]["london"]

Run a test on the result:

Interpreter["Number",Positive]["3"]

Interpreter["City",#["Population"]<Quantity[10^6,"People"]&]["paris"]

Use a custom failure mode when the test doesn't pass:

Interpreter["Number",OddQ,Style[ToString[#],Blue]&]["-10"]

OpenersExampleSection1(Spacer1)Scope  (3)

Interpret many types of entities:

Interpreter["Movie"]["avatar"]

Interpreter["Airport"]["ORD"]

Interpreter["ZIPCode"]["90210"]

Interpreter["Company"]["AAPL"]

Enable computations:

Interpreter["ComputedNumber"]["sin(pi/2)"]

Interpreter["ComputedCity"]["most populated city"]

Interpreter["ComputedLocation"]["birth place of Einstein"]

Interpret string representations of files:

Interpreter["JPEG"][Import["ExampleData/ocelot.jpg","String"]]

OpenersExampleSection2(Spacer1)Options  (8)

OpenersExampleSubsection0(Spacer1)AmbiguityFunction  (1)

Return all the possible interpretations:

Interpreter["City",AmbiguityFunction->All]["Boston"]

Interpreter["SemanticExpression",AmbiguityFunction->All]["Boston"]

OpenersExampleSubsection1(Spacer1)DateFormat  (1)

Specify a custom date format:

Interpreter["StructuredDate",DateFormat->{"Day","-","Month","-","Year"}]["9-3-2013"]

OpenersExampleSubsection2(Spacer1)DigitBlock  (1)

Change the maximum length of blocks of digits between separators:

Interpreter["Integer",DigitBlock->5]["12345,67890"]

Interpreter["Number",DigitBlock->2]["1,43.5"]

OpenersExampleSubsection3(Spacer1)GeoLocation  (1)

Set a location to use for semantic interpretations:

Interpreter["ComputedQuantity",GeoLocation->(Entity["Cape Town", Entity["City",{"CapeTown","WesternCape","SouthAfrica"}], "Entity[\"City\", {\"CapeTown\", \"WesternCape\", \"SouthAfrica\"}]", "city"])]["distance from Princeton, NJ"]

By default, the user's (RefLink[$GeoLocation, paclet:ref/$GeoLocation]) is used:

Interpreter["ComputedQuantity",GeoLocation->Automatic]["distance from Princeton, NJ"]

OpenersExampleSubsection4(Spacer1)NumberPoint  (1)

Set a custom decimal point:

Interpreter["Number",NumberPoint->"%"]["10%2"]

OpenersExampleSubsection5(Spacer1)NumberSeparator  (1)

Change the separator between blocks of digits:

Interpreter["StructuredQuantity",NumberSeparator->","]["3,500 Kilometers"]

OpenersExampleSubsection6(Spacer1)NumberSigns  (1)

Change the signs for negative and positive numbers:

Interpreter["Number",NumberSigns->{"neg ", "pos "}]["neg 15"]

Interpreter["Number",NumberSigns->{"neg ", "pos "}]["pos 5.3e4"]

OpenersExampleSubsection7(Spacer1)TimeZone  (1)

Set the time zone to use for semantic interpretations:

Interpreter["ComputedDateTime",TimeZone->-9]["current time"]

OpenersExampleSection3(Spacer1)Properties & Relations  (4)

(RefLink[Interpreter, paclet:ref/Interpreter]) specifications are used to create (RefLink[FormObject, paclet:ref/FormObject]), (RefLink[FormFunction, paclet:ref/FormFunction]), and (RefLink[APIFunction, paclet:ref/APIFunction]):

FormFunction["x" -> "Integer", #x^2&]["x" -> "2"]

The (RefLink[Interpreter, paclet:ref/Interpreter]) head is optional, but it can be useful to specify options:

APIFunction["time" -> Interpreter["DateTime", TimeZone-> -5], #time&]["time" -> "now"]

Use (RefLink[RepeatingElement, paclet:ref/RepeatingElement]) and (RefLink[CompoundElement, paclet:ref/CompoundElement]) to interpret complicated structures:

Interpreter[CompoundElement[<|"numbers" -> RepeatingElement["Integer"], "fruit" -> RepeatingElement[{"apple" -> "pomme", "orange" -> "orange", "grapefruit" -> "pamplemousse"}]|>]][<|"numbers" -> {"1","14", "-4"},"fruit" -> {"apple" , "pomme", "grapefruit"}|>]

(RefLink[Alternatives, paclet:ref/Alternatives]) can also be used to interpret data that can have different shapes:

Interpreter[CompoundElement[<|"x" -> RepeatingElement["City"|"Country"]|>]][<|"x" -> {"berlin", "portugal", "tegucigalpa"}|>]

Interpreter[CompoundElement[<|"x" -> RepeatingElement["AmusementPark"]|>]][<|"x" -> {"coliseum"|"disneyland", "six flags"|"central park" }|>]

OpenersExampleSection4(Spacer1)Possible Issues  (3)

The number and date options are not compatible with semantic interpreters:

Interpreter["Date",DateFormat->{"Month","/","Day","/","Year"}]["10/11/12"]

Interpreter["SemanticNumber",NumberPoint->":"]["10:12"]

If an (RefLink[AmbiguityFunction, paclet:ref/AmbiguityFunction]) is set that is not (RefLink[Automatic, paclet:ref/Automatic]), the test at the second argument is applied to its result, possibly leading to a failure:

Interpreter["ComputedNumber",Positive,AmbiguityFunction->All]["log 2"]

Interpreter["ComputedNumber",Positive]["log 2"]

Interpreter["ComputedNumber",AmbiguityFunction->All]["log 2"]

(RefLink[Interpreter, paclet:ref/Interpreter])[(StringTypeLink["String", paclet:ref/format/String])] accepts an empty string. This is not true for (RefLink[FormFunction, paclet:ref/FormFunction]), where the empty string and an empty field are considered equivalent:

Interpreter["String"][""]

form=FormFunction[{"a string"->"String"},f];
form[{"a string" -> ""}]

OpenersExampleSection5(Spacer1)Neat Examples  (1)

Obtain the (RefLink[GeoPosition, paclet:ref/GeoPosition]) for the White House:

position=Interpreter["Location"]["White House"]

Show it on a map:

GeoGraphics[GeoMarker@position,ImageSize->Medium,GeoRange->(Quantity[0.2`, "mi", miles, "Miles"])]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[SemanticInterpretation, paclet:ref/SemanticInterpretation])  ▪  (RefLink[GrammarToken, paclet:ref/GrammarToken])  ▪  (RefLink[ToExpression, paclet:ref/ToExpression])  ▪  (RefLink[ImportString, paclet:ref/ImportString])  ▪  (RefLink[SemanticImportString, paclet:ref/SemanticImportString])  ▪  (RefLink[Entity, paclet:ref/Entity])  ▪  (RefLink[DateObject, paclet:ref/DateObject])  ▪  (RefLink[APIFunction, paclet:ref/APIFunction])  ▪  (RefLink[FormFunction, paclet:ref/FormFunction])  ▪  (RefLink[$InterpreterTypes, paclet:ref/$InterpreterTypes])  ▪  (RefLink[Classify, paclet:ref/Classify])  ▪  (RefLink[TextCases, paclet:ref/TextCases])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Converting between Expressions & Strings, paclet:guide/ConvertingBetweenExpressionsAndStrings])}, {▪(RefLinkPlain[Date & Time, paclet:guide/DateAndTime])}, {▪(RefLinkPlain[Free-Form & External Input, paclet:guide/FreeFormAndExternalInput])}, {▪(RefLinkPlain[Text Manipulation, paclet:guide/ProcessingTextualData])}, {▪(RefLinkPlain[Setting Up Input Interpreters, paclet:guide/InterpretingStrings])}, {▪(RefLinkPlain[String Manipulation, paclet:guide/StringManipulation])}, {▪(RefLinkPlain[Creating Form Interfaces & Apps, paclet:guide/CreatingFormsAndApps])}, {▪(RefLinkPlain[Creating Instant APIs, paclet:guide/CreatingAnInstantAPI])}, {▪(RefLinkPlain[Geographic Data & Entities, paclet:guide/GeographicData])}, {▪(RefLinkPlain[Knowledge Representation & Access, paclet:guide/KnowledgeRepresentationAndAccess])}, {▪(RefLinkPlain[Locations, Paths, and Routing, paclet:guide/LocationsPathsAndRouting])}, {▪(RefLinkPlain[WDF (Wolfram Data Framework), paclet:guide/WDFWolframDataFramework])}, {▪(RefLinkPlain[Text Normalization, paclet:guide/TextNormalization])}, {▪(RefLinkPlain[Programmable Linguistic Interface, paclet:guide/ProgrammableLinguisticInterface])}, {▪(RefLinkPlain[External Interpreted Language Interfaces, paclet:guide/ExternalInterpretedLanguageInterfaces])}, {▪(RefLinkPlain[Linguistic Data, paclet:guide/LinguisticData])}})}})

({{(Spacer1), ({{(Spacer1)Related Links}, {(WebLink[DocumentationFooterIconsRelatedLinks-FastIntro.png(Spacer1)Fast Introduction for Programmers: Interpreters, http://www.wolfram.com/language/fast-introduction-for-programmers/interpreters/])}, {(WebLink[DocumentationFooterIconsRelatedLinks-EIWL.png(Spacer1)An Elementary Introduction to the Wolfram Language, https://www.wolfram.com/language/elementary-introduction/35-natural-language-understanding.html])(WebLink[: Natural Language Understanding, https://www.wolfram.com/language/elementary-introduction/35-natural-language-understanding.html])}})}})