Python 斯坦福NLP:如何获取块
因此,在nltk中,我们可以指定一个POS标记的正则表达式来提取文本块Python 斯坦福NLP:如何获取块,python,regex,nltk,stanford-nlp,Python,Regex,Nltk,Stanford Nlp,因此,在nltk中,我们可以指定一个POS标记的正则表达式来提取文本块 sentence = [("the", "DT"), ("little", "JJ"), ("yellow", "JJ"), ... ("dog", "NN"), ("barked", "VBD"), ("at", "IN"), ("the", "DT"), ("cat", "NN")] grammar = "NP: {<DT>?<JJ>*<NN>}" cp = nltk.R
sentence = [("the", "DT"), ("little", "JJ"), ("yellow", "JJ"),
... ("dog", "NN"), ("barked", "VBD"), ("at", "IN"), ("the", "DT"), ("cat", "NN")]
grammar = "NP: {<DT>?<JJ>*<NN>}"
cp = nltk.RegexpParser(grammar)
result = cp.parse(sentence)
print(result)
(S
(NP the/DT little/JJ yellow/JJ dog/NN)
barked/VBD
at/IN
(NP the/DT cat/NN))
句子=[(“the”,“DT”),(“little”,“JJ”),(“yellow”,“JJ”),
狗、狗、狗吠、狗吠、狗吠、狗吠、狗吠、狗吠、狗吠、狗吠、狗吠、狗吠、狗吠、狗吠、狗吠、狗吠、狗吠、狗吠、狗吠、狗吠、狗吠、狗吠
grammar=“NP:{?*}”
cp=nltk.RegexpParser(语法)
结果=cp.parse(句子)
打印(结果)
(S)
(NP/DT little/JJ yellow/JJ dog/NN)
吠叫/VBD
在/在
(NP/DT类/NN类)
使用斯坦福nlp可以做类似的事情吗?我想做的是使用stanford POS tagger标记我的文本,因为我发现它比nltk的tagger更准确。我想一旦我有了标记的句子,我就可以使用上面的代码了。斯坦福NLP还提供了一些现成的东西来创建文本块吗
另外,我知道nltk 3提供斯坦福NLP支持。那么,我如何结合这两种方法来获得文本块呢?我希望在Python中这样做。 < P>如果你知道你想把这些块看作是块,你可以用它们来组合它们。