10.1 natural language understanding
Query a database
Country city_table City
Here is a syntax that converts sentences into SQL statements:
>>>nltk.data.show_cfg(%=(?np+ WHERE+ ?vp)] -> NP[SEM=?np]VP[SEM==(?v+ ?pp)] -> IV[SEM=?v] PP[SEM==(?v+ ?ap)] -> IV[SEM=?v] AP[SEM==(?det+ ?n)] -> Det[SEM=?det]N[SEM==(?p+ ?np)] -> P[SEM=?p]NP[SEM==?pp]-> A[SEM=?a]PP[SEM==]-> =]-> =]-> | =] -> =] -> =]-> =]-> >>> nltk >>>cp = load_parser(>>>query =>>>trees =>>>answer = trees[0].node[>>>q= >>>=
To achieve the ability to generate Database SQL statements from the sentence to the later generation, that is, to be independent of any query language, we should establish a standard interpretation of the classic logic.
The logic form is more abstract and more universal.
Natural Language, semantics, and logic
The model of a sentence set W is a formal representation of a situation where all the sentences in w are true.
See the figure below:
[Evi ran away]For example,
Replace the two clauses in (8) with and replace the logical operation of the corresponding English word and. This is the logic form of this sentence.
The following mark weight specifies the formula containing some operators as the true condition. Iff is short for if and only if (if and only if.
>>> SnF = lp. parse (>>> NotFnS = lp. parse (>>> R = lp. parse (>>> prover >>>
For a model of Proposition Logic, you must assign True or False values to each possible formula.
We can do a simple experiment:
1. assign a value to each proposition symbol first.
>>>val = nltk.Valuation([(,True),(, True),(, False)])
We can view the following values:
>>>val[
2. to simplify the experiment, we ignore dom and g settings.
>>>dom =>>>g= nltk.Assignment(dom)
3. Use val to initialize Model m
>>>m=nltk.Model(dom, val)
4. Each model has an evaluate () method to determine the logical expression. For example:
>>> m.evaluate(>>> m.evaluate(>>> m.evaluate(>>> m.evaluate(
Now, we are only limited to expressing atoms and sentences with letters such as P and Q. However, we need to go beyond the Proposition Logic to something more expressive and be able to see the basiC sentence in it, that is, the first-order logic.