behavior of "!" in pattern.search and dealing with negation

21 views
Skip to first unread message

Nassim Haddad

unread,
Mar 27, 2015, 3:56:11 AM3/27/15
to pattern-f...@googlegroups.com
Hello,

I am starting to use the pattern library and really love it.

One thing that bothers me though is the behavior of "!". As I understood, when used for instance in "!not", it matches any word that is not "not". The problem is that it has to match a word, which makes the constraint problematic: not only must the word "not" not be there, but another word must exist.

As an example of where this makes trouble, consider the code below. My goal is to match sentences comparing Chuck Norris to Dolph Lundgren without using the negation. For the reason explained above, it doesn't work. Is there another way ?

from pattern.search import Pattern
from pattern.en import parsetree
t = parsetree('Chuck Norris is cooler than Dolph Lundgren.', lemmata=True)
p = Pattern.fromstring('{NP} be {!not} JJ* than {NP}')
m = p.search(t)

Thanks in advance

Nassim Haddad

unread,
Mar 27, 2015, 3:56:11 AM3/27/15
to pattern-f...@googlegroups.com
Thanks in advance for any help !

Phil Gooch

unread,
May 15, 2015, 4:15:46 PM5/15/15
to pattern-f...@googlegroups.com
{!not?} seems to work in this example, i.e.

p = Pattern.fromstring('{NP} be {!not?} JJ* than {NP}')

Phil
Reply all
Reply to author
Forward
0 new messages