Interpreter[form]
represents an interpreter object that can be applied to a string to try to interpret it as an object of the specified form.

Interpreter[form,test]
returns the interpreted object only if applying test to it yields True; otherwise it returns a Failure object.

Interpreter[form,test,fail]
returns the result of applying the function fail if the test fails.

Details and OptionsDetails and Options

  • Interpreter[]["input"] applies the interpreter to a particular string .
  • Possible form specifications include:
  • "Expression"any Wolfram Language expression
    "HeldExpression"expression to be returned held
    "InactiveExpression"expression to be returned inactivated
    "SemanticExpression"expression derived semantically from free-form input
    "Number"any number in a standard format
    "SemanticNumber"number derived semantically (e.g "half")
    "ComputedNumber"number derived by computation (e.g. "2+2")
    "Integer"integer
    "SemanticInteger"integer derived semantically (e.g. "six")
    "ComplexNumber"real or complex number
    "MathExpression"mathematical expression (e.g. "sin(2x)+1")
    "MathFormula"mathematical formula (e.g. "2x+3y=0")
    "HeldMathFormula"mathematical formula to be returned held
    "HexInteger"integer in hexadecimal
    "Integer32",etc.integers etc. consistent with particular binary formats
    "Boolean"Boolean value (true/false, 1/0, etc., giving True/False)
    "String"pure string
    "TextArea"text of any length (rendered in forms as a text area)
    "TextLine"single line of text
    "URLString"URL-encoded string
    "URL"correctly formatted URL
    "URLQueryString"URL query string
    "SemanticURL"URL derived semantically (e.g. from company name)
    "IPAddress"correctly formatted IP address
    "FileName"name of a file on your computer
    "UploadedFile"file to be uploaded to the cloud
    "CachedFile"file to be cached in a temporary directory
    "EmailAddress"correctly formatted email address
    "PhoneNumber"correctly formatted phone number
    "Date"date in any standard format
    "StructuredDate"date obtained from a picker
    "DateTime"date and time
    "Time"time of day
    "ComputedDate",etc.date derived by computation (e.g. "next tuesday")
    "Location"anything that yields a geo location
    "GeoCoordinates"geo position specifed as latitude, longitude
    "StreetAddress"any standard street address
    "Country"country or country-like territory
    "AdministrativeDivision"state, province, county, etc.
    "USState"US state
    "USCounty"US county
    "Quantity"quantity with units
    "ComputedQuantity"quantity derived by computation
    "StructuredQuantity"quantity given purely as number followed by unit
    "PhysicalQuantity"physical quantity (e.g. "mass")
    "CurrencyAmount"currency amount (e.g. "$7.50")
    "CurrencyName"name of a currency (e.g. "US dollars")
    "Company"company
    "TickerSymbol"financial instrument ticker symbol
    "Image"image
    "Color"color in any standard format
    "StructuredColor"color obtained from a picker
    "Sound"sound
    "entity"any Wolfram Language entity type (e.g. )
    "format"any standard Wolfram Language import format
    Restricted[form,spec]a form restricted in the specified way
    DelimitedSequence[form,]a delimited sequence of forms returned as a list
    form1|form2|several possible forms, tried in order
    {"s1"->val1,"s2"->val2,}a literal set of choices , yielding values
    {"s1","s2",}a literal set of choices , yielding values
  • $InterpreterTypes gives a complete list of possible interpreter types.
  • Interpreter[]["input"] returns either an interpreted value, Missing["NoInput"] if input is effectively blank, or Failure[].
  • In the case of , any domain supported by EntityValue can be used.
  • Interpreter["format"]["input"] is effectively equivalent to ImportString["input","format"].
  • 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.
  • Interpreter[form,test]["input"] applies test to the result of interpreting input using the specified form.
  • If the result of applying test is True, then the interpretation of input is returned.
  • If the result of applying test is a Failure object, this object is immediately returned.
  • If the result of applying test is False or anything else, then in Interpreter[form,test,fail]["input"] the result of applying fail to the interpretation of input is returned. If no fail is given, then a Failure object is returned.
  • If Interpreter directly generates a Failure object, the following tags are used:
  • "InterpretationFailure"the string given could not be interpreted in the form specified
    "RestrictionFailure"interpretation succeeded, but a restriction failed
    "ConditionFailure"interpretation and restrictions succeeded, but explicit test failed
    "ConnectionFailure"required cloud connection could not be made
  • Interpreter supports the following options:
  • AmbiguityFunctionAutomaticfunction to apply to ambiguous semantic results
    DateFormat$DateStringFormatdefault format to assume for dates
    DigitBlockInfinitynumber of digits between breaks to assume
    GeoLocation$GeoLocationgeo location to assume for semantic interpretation
    NumberPoint"."string to assume for decimal points
    NumberSeparator{",", " "}string to assume at breaks between number blocks
    NumberSigns{"-",""}strings to assume for signs of negative and positive numbers
    TimeZone$TimeZonetime zone to assume for semantic interpretation
  • Interpreter[][{"input1","input2",}] is equivalent to .
  • Interpreter[form]["string1"|"string2"|] yields as a result the interpretation of the first of the that can be interpreted using the specified form.
  • Interpreter[form][File["filename"]] or Interpreter[form][CloudObject[]] yields the result of interpreting the contents of the file or cloud object according to the specified form.
  • For other expressions, Interpreter[form][expr] returns expr if expr conforms to the specification for form, and returns Failure[] otherwise.

ExamplesExamplesopen allclose all

Basic Examples  (4)Basic Examples  (4)

Interpret a number in any standard explicit format:

In[1]:=
Click for copyable input
Out[1]=

Interpret a number given linguistically:

In[2]:=
Click for copyable input
Out[2]=

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

In[3]:=
Click for copyable input
Out[3]=

Interpret a date, generating a DateObject:

In[1]:=
Click for copyable input
Out[1]=

Interpret a city, generating an Entity object:

In[2]:=
Click for copyable input
Out[2]=

Interpret a university:

In[3]:=
Click for copyable input
Out[3]=

Interpret a location, returning a GeoPosition:

In[4]:=
Click for copyable input
Out[4]=

Interpret a list of numbers:

In[1]:=
Click for copyable input
Out[1]=

Interpret a number restricted to be between 1 and 10:

In[1]:=
Click for copyable input
Out[1]=

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

In[2]:=
Click for copyable input
Out[2]=

Interpret a city restricted to a geographical region:

In[3]:=
Click for copyable input
Out[3]=
Introduced in 2014
(10.0)