簡體   English   中英

如何在NLTK中為復制器添加復合詞?

[英]How to add compound words to the tagger in NLTK?

所以,我想知道是否有人知道如何組合多個術語來在NLTK中的標記器中創建單個術語

例如,當我這樣做時:

nltk.pos_tag(nltk.word_tokenize('Apple Incorporated is the largest company'))

它給了我:

[('Apple', 'NNP'), ('Incorporated', 'NNP'), ('is', 'VBZ'), ('the', 'DT'), ('largest', 'JJS'), ('company', 'NN')]

如何將'Apple'和'Incorporated'放在一起('Apple Incorporated','NNP')

你可以試試看看nltk.RegexParser 它允許您根據正則表達式對部分語音標記內容進行分塊。 在你的例子中,你可以做類似的事情

pattern = "NP:{<NN|NNP|NNS|NNPS>+}"
c = nltk.RegexpParser(p)
t = c.parse(nltk.pos_tag(nltk.word_tokenize("Apple Incorporated is the largest company")))
print t

這會給你:

Tree('S', [Tree('NP', [('Apple', 'NNP'), ('Incorporated', 'NNP')]), ('is', 'VBZ'), ('the', 'DT'), ('largest', 'JJS'), Tree('NP', [('company', 'NN')])])

代碼正在完成它應該做的事情。 它正在為令牌添加詞性標簽。 'Apple Incorporated'不是一個單一的標記。 它是兩個單獨的令牌,因此不能應用單個POS標簽。 這是正確的行為。

我想知道你是否正在嘗試使用錯誤的工具來完成工作。 你想做什么/你為什么要這樣做? 也許您有興趣識別搭配而不是POS標記? 你可以看看這里: 搭配模塊

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM