【发布时间】:2016-04-13 20:42:03
【问题描述】:
所以在 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.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))
是否可以使用 stanford nlp 做类似的事情?我想做的是使用 stanford POS 标记器来标记我的文本,因为我发现它比 nltk 的标记器更准确。我想一旦我有了标记的句子,我无论如何都可以使用上面的代码。斯坦福 NLP 是否仍然提供开箱即用的东西来创建文本块?
另外,我知道 nltk 3 提供了 stanford NLP 支持。那么我怎样才能将两者结合起来得到大块的文本呢?我更喜欢在 python 中执行此操作。
【问题讨论】:
标签: python regex nltk stanford-nlp