考虑以下字符串:
I am mad and will not ever set foot in that store again
我正在使用 POS 标记器来标记这样的字符串:
I/NN am/VBP mad/JJ and/CC will/MD not/RB ever/RB set/VBN foot/NN in/IN that/IN
store/NN again/RB
现在,我使用正则表达式将“不”连接到、ao、动词,同时忽略否定词(从不,也不是等)
preg_replace(
"/(\s)(?:(?!never|neither|dont|wont|not|no)(\w*))\/(JJ|MD|RB|VB|VBG|VBN)\b/",
"$1not$2",
$sentence
);
这导致:
I am notmad and notwill notever notset foot in that store notagain
但是,我想要的只是将“不”连接到出现在(第一个)否定词之后的动词。注意mad
andwill
而不是notmad
and notwill
:
I am mad and will notever notset foot in that store notagain
所以我认为首先我应该在句子中寻找任何否定词 (never|neither|dont|wont|not|no),然后只从那里执行正则表达式。但是我该怎么做呢?