Skip links

Sentence Negation

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:

Parse Tree
Parse Tree

It can be visualized as follows:

Visualizing Parse Tree
Visualizing Parse Tree

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:

Top-Level Logic
Top-Level Logic

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:

Handling Declarative Sentence
Handling Declarative Sentence

Similarly, “imperative” sentences are handled this way:

Handling Imperative Sentence
Handling Imperative Sentence

Here I have shown just a few of the possible patterns.

Let us look at some actual outputs. First, some declarative sentences:

Example Output
Example Output

What about sentences that contain negation?

Handling Negative Sentences
Handling Negative Sentences

Here are some examples of imperative sentences:

Imperative Sentences
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!

Leave a comment