[Language Processing and Python] 10.1 natural language understanding \ 10.2 Proposition Logic

Source: Internet
Author: User
Tags nltk

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.