I am new to NLTK. I would like to create the negative of a sentence (which will usually be in the present tense). For example, is there a function to allow me to convert: 'I run' to 'I do not run'

or

'She runs' to 'She does not run'.

I suppose I could use POS to detect the verb and its preceding pronoun but I just wondered if there was a simpler built in function

有帮助吗?

解决方案 2

You should use a parser to find the head (verb) of the predicate of the sentence.

In case you assume that the original sentence is grammatically correct you can overcome the agreement issue (don't vs. doesn't) by relying on the properties of the original head-verb.

If it's an auxiliary1, replace it with its negative counterpart (was > wasn't, will > won't, have > haven't, etc.). If it's not an auxiliary, add the correct negative form of supportive-do: didn't if the head-verb is in the past form (i.e., walked), don't if it is in the non-3rd-person-singular present form (i.e., think), and doesn't if in the 3rd-person-singular present form (i.e., runs). Immediately following the supportive-do use the base form of the original head-verb (walk, think, run).

A harder issue to solve is what ShaiCohen is discussing in his answer. Notice that you don't always have to replace these items. There are many cases where you shouldn't. For example: I am the one who saw someone at the office > I'm not the one who saw someone at the office.

Have a look at the Contextors API.

1 Be careful of lexical verbs which look like auxiliaries. She has a dog...

其他提示

No there is not. What is more important it is quite a complex problem, which can be a topic of research, and not something that "simple built in function" could solve. Such operation requires semantic analysis of the sentence, think about for example "I think that I could run faster" which of the 3 verbs should be negated? We know that "think", but for the algorithm they are just the same. Even the case of detection whether you should use "do" or "does" is not so easy. Consider "Mary and Jane walked down the road" and "Jane walked down the road", without parse tree you won't be able to distinguish the singular/plural problem. To sum up, there is no, and cannot be any simple solution. You can design any kind of heuristic you want (one of such is proposed POS-based negation) and if it fails, start a research in this area.

In addition to the challenges discussed in the previous answer, there is the challenge posed by negative polarity-items, lexical items that require a preceding non-affirmative element. Consider the following sentences:

a. I didn’t see anyone at the office
b. * I saw anyone at the office
c. I saw someone at the office  

The positive form of (a) is not (b) but (c), where anyone is replaced by someone.

Negative polarity items also present a challenge in the context of paraphrasing tasks like changing the voice of a sentence from active to passive and vice versa. You can read more about this topic in the post: Voice Alternation and Negative Polarity Items.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top