我试图在单词“but”(或任何其他协调连词词)处使用RegEx来分块句子。它不起作用。。。在
sentence = nltk.pos_tag(word_tokenize("There are no large collections present but there is spinal canal stenosis."))
result = nltk.RegexpParser(grammar).parse(sentence)
DigDug = nltk.RegexpParser(r'CHUNK: {.*<CC>.*}')
for subtree in DigDug.parse(sentence).subtrees():
if subtree.label() == 'CHUNK': print(subtree.node())
我需要把"There are no large collections present but there is spinal canal stenosis."
分成两个句子:
我也希望使用相同的代码来拆分“and”和其他并列连词(CC)的句子。但我的代码不起作用。请帮忙。在
我想你能做到
在哪里
你可以添加更多的连词,用管道字符
|
隔开。 请注意,这些单词不包含在regex中具有特殊含义的字符。如果有疑问,请先用re.escape(word)
对它们进行转义如果你想避免硬编码连词,比如“但是”和“和”,那么试着在切分的同时切分:
Chinking基本上把我们不需要的东西从一个短语中排除掉,在这个例子中是“但是”。 有关详细信息,请参见:http://www.nltk.org/book/ch07.html
相关问题 更多 >
编程相关推荐