【问题标题】:Creating own named entity using NLTK on Python在 Python 上使用 NLTK 创建自己的命名实体
【发布时间】:2020-11-28 08:49:24
【问题描述】:

我正在使用一本名为 Natural Language Processing with Python Cookbook 的书学习 NLTK。

这是代码,但根本没有解释。

grammar = r"NAMED-ENTITY: {<NNP>+}"
cp = nltk.RegexpParser(grammar)

samplestrings = [
    "Microsoft Azure is a cloud service",
    "Bill Gates announces Satya Nadella as new CEO of Microsoft"
]

def demo(samplestrings):
    for s in samplestrings:
        words = nltk.word_tokenize(s)
        tagged = nltk.pos_tag(words)
        # chunks = nltk.ne_chunk(tagged)
        chunks = cp.parse(tagged)
        print(nltk.tree2conllstr(chunks))
        print(chunks)

demo(samplestrings)

所以我被第一行卡住了。

grammar = r"NAMED-ENTITY: {&lt;NNP&gt;+}" 这段代码有什么作用?

这是否意味着如果存在多个 NNP(至少一个 NNP),那么该标记词就是命名实体?

谢谢你的回答

【问题讨论】:

    标签: python nltk named-entity-recognition chunking


    【解决方案1】:

    在此示例中,它们是使用名为 NAMED-ENTITY 的正则表达式解析器对专有名词进行分块序列。

    cp = nltk.RegexpParser(r"NAMED-ENTITY: {<NNP>+}")
    

    NNP 是专有名词的词性标签。

    【讨论】:

      猜你喜欢
      • 2015-10-28
      • 1970-01-01
      • 2013-10-19
      • 2016-09-08
      • 2020-02-01
      • 2011-08-08
      • 1970-01-01
      • 2017-09-26
      • 1970-01-01
      相关资源
      最近更新 更多