【发布时间】:2017-08-29 00:07:41
【问题描述】:
用 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']
【问题讨论】:
-
Edit 你的问题并展示一个超过 5 个动词的例句以及该句子的
print(TAGGER.tag(Sentence)[0].arg_structures)的输出。 -
输入文件的单行是否包含某个整数倍数的葡萄牙语句子?我的意思是,没有多余的词,例如从上一句的结尾或从下一句的开头?
-
@stovfl 我编辑了问题,看看是否更清楚。
-
@BillBell 一个包含多行文本、不同大小和不同单词的文本文档。
-
(1) 让我换一种方式提出我的问题:如果我读取输入文本文件的一行,那将只包含一个句子吗? (2) 请您不要给我们图片,而是在您的问题中插入文字,以便我们可以方便地复制它?
标签: python python-2.7 text url-rewriting pos-tagger