|35||Natural Language Understanding|
We saw earlier how to use Ctrl+= to enter natural language input. Now we’re going to talk about how to set up functions that understand natural language.
Interpreter is the key to much of this. You tell Interpreter what type of thing you want to get, and it will take any string you provide, and try to interpret it that way.
“The big apple” is a nickname for New York City:
Interpreter converts natural language to Wolfram Language expressions that you can compute with. Here’s an example involving currency amounts.
Interpret various currency amounts:
Interpreter gives the geo location of the White House:
Interpreter handles many hundreds of different types of objects.
Interpreter interprets whole strings. TextCases, on the other hand, tries to pick out instances of what you request from a string.
Pick out currency amounts:
You can use TextCases to pick out particular kinds of things from a piece of text. Here we pick out instances of country names in a Wikipedia article.
Generate a word cloud of country names from the Wikipedia article on the EU:
TextStructure shows you the whole structure of a piece of text.
Find how a sentence of English can be parsed into grammatical units:
|Interpreter["type"]||specify a function to interpret natural language|
|TextCases["text","type"]||find cases of a given type of object in text|
|TextStructure["text"]||find the grammatical structure of text|
35.5Find universities that can be referred to as “U of X”, where x is any letter of the alphabet. »
35.6Find which US state capital names can be interpreted as movie titles (use CommonName to get the string versions of entity names). »
35.7Find cities that can be referred to by permutations of the letters a, i, l and m. »
35.8Make a word cloud of country names in the Wikipedia article on “gunpowder”. »
35.9Find all nouns in “She sells seashells by the sea shore.” »
35.10Use TextCases to find the number of nouns, verbs and adjectives in the first 1000 characters of the Wikipedia article on computers. »
35.11Find the grammatical structure of the first sentence of the Wikipedia article about computers. »
35.13Make a community graph plot of the graph representation of the text structure of the first sentence of the Wikipedia article about language. »
What possible types of interpreters are there?
Does Interpreter need a network connection?
In simple cases, such as dates or basic currency, no. But for full natural-language input, yes.
When I say “4 dollars”, how does it know if I want US dollars or something else?
Can Interpreter deal with arbitrary natural language?
If something can be expressed in the Wolfram Language, then Interpreter should be able to interpret it. Interpreter["SemanticExpression"] takes any input, and tries to understand its meaning so as to get a Wolfram Language expression that captures it. What it’s doing is essentially the first stage of what Wolfram|Alpha does.
Yes. GrammarRules lets you build up your own grammar, making use of whatever existing interpreters you want.
Interpreter mostly works only with English. But for example WordTranslation translates words to and from many languages.
WordDefinition gives dictionary definitions.
More to Explore