In the last article, I talked about determining sentence types automatically. Another interesting task is to generate the “negation” of a given sentence.
Example-1:
Sentence => “My teacher lives nearby”
Negation => “My teacher does not live nearby”
Example-2:
Sentence => “She did not like that speech”
Negation => “She liked that speech”
I have implemented this idea using “iLexicon” and a DCG-based parser for English Grammar in Sicstus Prolog.
The parser first parses the given sentence and emits a “parse tree”. The sentence Negator then manipulates the parse tree and derives the negation of the given sentence.
For example, the sentence “Jack teaches at Harvard” results in the following parse tree:
It can be visualized as follows:
The sentence Negator applies various rules and patterns to detect the appropriate Verb and handle its negation.
The top-level logic can be expressed thus:
The actual negation depends on the sentence type, for example is it “declarative” or “imperative”, and so on.
A part of the core patterns that apply to “declarative” sentences is shown here:
Similarly, “imperative” sentences are handled this way:
Here I have shown just a few of the possible patterns.
Let us look at some actual outputs. First, some declarative sentences:
What about sentences that contain negation?
Here are some examples of imperative sentences:
Once we parse a sentence and obtain its “syntactic structure”, it is possible to analyze and manipulate the structure to suit our requirements.
Have a great weekend!
Recent Comments