次の文字列を検討してください。
I am mad and will not ever set foot in that store again
POS-tagger を使用して、次のように文字列にタグを付けています。
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
ここで、正規表現を使用して「not」を ao、動詞に連結し、否定語 (never、none など) を無視しています。
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
ただし、私が望むのは、(最初の) 否定語の後に現れる動詞にのみ「not」を連結することです。mad
andwill
の代わりにnotmad
andに注意してくださいnotwill
:
I am mad and will notever notset foot in that store notagain
したがって、最初に文内の否定語 (never|neither|dont|wont|not|no) を探し、そこから正規表現のみを実行する必要があると思います。しかし、これについてどうすればよいでしょうか?