簡體   English   中英

從NLP中的名詞階段中提取名詞

[英]Extracting nouns from Noun Phase in NLP

誰能告訴我如何從以下輸出中只提取名詞:

我已經使用以下程序基於給定的語法對字符串“給我電影評論”進行了標記化和解析: -

sent=nltk.word_tokenize(msg)
parser=nltk.ChartParser(grammar)
trees=parser.nbest_parse(sent)
for tree in trees:
    print tree
tokens=find_all_NP(tree)
tokens1=nltk.word_tokenize(tokens[0])
print tokens1

並獲得以下輸出:

>>> 
(S
  (VP (V Give) (Det me))
  (NP (Det the) (N review) (PP (P of) (N movie))))
(S
  (VP (V Give) (Det me))
  (NP (Det the) (N review) (NP (PP (P of) (N movie)))))
['the', 'review', 'of', 'movie']
>>> 

現在我只想獲得名詞。 我怎么做?

您不需要使用完整的解析器來獲取名詞。 您只需使用標記器即可。 您可以使用的一個功能是nltk.tag.pos_tag()。 這將返回帶有單詞和詞性的元組列表。 您將能夠遍歷元組並找到標有“NN”或“NNS”的單詞,用於名詞或復數名詞。

NLTK有如何記錄如何使用他們的標記。 它可以在這里找到: https://nltk.googlecode.com/svn/trunk/doc/howto/tag.html這里是如何使用標注器在NLTK本書的章節的鏈接: HTTPS://nltk.googlecode .COM / SVN /主干/ DOC /電子書/ ch05.html

每個地方都有許多代碼示例。

暫無
暫無

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

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