用nlpnet(http://nilc.icmc.usp.br/nlpnet/index.html)做了一个词分类器。其目标是仅提取具有给定标记符的单个单词。你知道吗
响应代码
import nlpnet
import codecs
import itertools
TAGGER = nlpnet.POSTagger('pos-pt', language='pt')
def TAGGER_txt(text):
return (list(TAGGER.tag(text)))
with codecs.open('document.txt', encoding='utf8') as original_file:
with codecs.open('document_teste.txt', 'w') as output_file:
for line in original_file.readlines():
print (line)
words = TAGGER_txt(line)
all_words = list(itertools.chain(*words))
nouns = [word[0] for word in all_words if word[1]=='V']
print (nouns)
结果
O gato esta querendo comer o ratão
['gato', 'ratão']
我认为这可能是你所需要的东西的本质。请查看已编辑的版本。
正如您在问题中所说,标记
Sentence
的结果类似于tagged
。如果只需要Sentence
中的名词,可以使用nouns =
之后的表达式来恢复它们。你知道吗输出:
编辑:我不清楚你想要什么。还有一种可能性。你知道吗
codecs.open
中。你知道吗是的。你知道吗
输出:
用Python测试:3.4.2和2.7.9
相关问题 更多 >
编程相关推荐