【问题标题】:Extracting nouns from Noun Phase in NLP从 NLP 中的名词阶段中提取名词
【发布时间】:2011-02-28 15:14:48
【问题描述】:

谁能告诉我如何从以下输出中只提取名词:

我已经使用以下过程根据给定语法对字符串“Give me the review of movie”进行了标记和解析:-

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']
>>> 

现在我只想获取名词。我该怎么做?

【问题讨论】:

    标签: python django nlp


    【解决方案1】:

    您不需要使用完整的解析器来获取名词。您可以简单地使用标记器。您可以使用的一个函数是 nltk.tag.pos_tag()。这将返回包含单词和词性的元组列表。您将能够遍历元组并找到带有“NN”或“NNS”标签的名词或复数名词。

    NLTK 有一个如何使用其标记器的文档。可以在这里找到:https://nltk.googlecode.com/svn/trunk/doc/howto/tag.html,这里是 NLTK 书中关于使用标记器的章节的链接:https://nltk.googlecode.com/svn/trunk/doc/book/ch05.html

    每个地方都有很多代码示例。

    【讨论】:

    • 它通过为名词调用类似的函数并为其添加额外的语法来工作。不确定它是否是最好的方法。谢谢乔,您提供的信息很有帮助
    • 你用了什么函数?你有机会提供实施吗?
    猜你喜欢
    • 1970-01-01
    • 2011-06-03
    • 2013-12-08
    • 1970-01-01
    • 1970-01-01
    • 2019-03-04
    • 2010-12-25
    • 2016-06-29
    • 1970-01-01
    相关资源
    最近更新 更多