【问题标题】:How to extract name from string using nltk如何使用 nltk 从字符串中提取名称
【发布时间】:2017-11-05 15:09:59
【问题描述】:

我正在尝试从非结构化字符串中提取名称(印度)。

我的代码来了:

text = "Balaji Chandrasekaran Bangalore |  Senior Business Analyst/ Lead Business Analyst An accomplished Senior Business Analyst with a track record of handling complex projects in given period of time, exceeding above the expectation. Successful at developing product road maps and leading cross-functional software teams from prototype to release. Professional Competencies Systems Development Life Cycle (SDLC) Agile methodologies Business process improvement Requirements gathering & Analysis Project Management UML Specification UI & UX (Wireframe Designing) Functional Specification Test Scenario Creation SharePoint Admin Work History Senior Business Analyst (Aug 2012 Current) YouBox Technology pvt ltd, Chennai Translating business goals, feature concepts and customer needs into prioritized product requirements and use cases. Expertized in designing innovative wireframes combining user experience analysis and technology models. Extensive Experience in implementing soft wares for Shipping/Logistics firms to handle CRM, Finance, Logistics, Operations, Intermodal, and documentation. Strong interpersonal skills, highly adept at diplomatically facilitating discussions and negotiations with stakeholders. Education Bachelor of Engineering: Electronics & Communication, 2011 CES Tech Hosur Accomplishment Successful onsite implementation at various locations around the globe for Europe Shipping Company. - (Pre Study, General Design, and Functional Specification) Organized Business Analyst Forum and conducted various activities to develop skill sets of Business Analysts."
if text != "":
    grammar = """PERSON: {<NNP>}"""
    chunkParser = nltk.RegexpParser(grammar)
    tagged = nltk.pos_tag(nltk.word_tokenize(text))
    tree = chunkParser.parse(tagged)

    for subtree in tree.subtrees():
        if subtree.label() == "PERSON": 
            pronouns.append(' '.join([c[0] for c in subtree]))

    print(pronouns)

['Balaji', 'Chandrasekaran', 'Bangalore', '|','Senior', 'Business', 'Analys', '/', 'Lead', 'Business', 'Analyst', 'Senior', 'Business', “分析师”、“成功”、“发展”、“生活”、“周期”、“SDLC”、 “敏捷”、“业务”、“需求”、“分​​析”、“项目”、 “管理”、“UML”、“规范”、“UI”、“UX”、“线框”、 “设计”、“功能”、“规范”、“测试”、“场景”、 “创作”、“SharePoint”、“管理员”、“工作”、“历史”、“高级”、 “商业”、“分析师”、“8 月”、“当前”、“技术”、“钦奈”、 “翻译”、“CRM”、“财务”、“物流”、“运营”、 “多式联运”、“教育”、“学士”、“工程”、“电子”、 '沟通','成就','成功','地中海', “船舶”、“公司”、“MSC”、“格鲁吉亚”、“MSC”、“柬埔寨”、“MSC”、“MSC”、 'South', 'Successful', 'Stake', 'MSC', 'Geneva', 'Switzerland', 'Pre', '研究','一般','设计','功能','规范','O', “商业”、“分析师”、“论坛”、“商业”]

但实际上我只需要 Balaji Chandrasekaran ,我什至尝试使用 Standford ner lib.Which 未能选择 Balaji Chandrasekaran

任何人都可以帮助从 un 结构字符串中提取名称,或者建议我任何好的教程来做到这一点。

提前谢谢你。

【问题讨论】:

  • 您可能需要找到一个将非拉丁名称音译成英文的库。我不确定是否存在类似的东西。
  • @emporerblk 你是说 corpus.names 之类的东西吗?但是对于印度名字
  • 没错。 Python 的名字数据库有一段时间没有更新了(proof),斯坦福词典是基于西方名字的。要让 nltk 做你想做的事,你需要提供印度名字的例子。
  • @emporerblk 非常感谢。是否有针对印度人名训练或创建名称库的教程。

标签: python nlp nltk stanford-nlp


【解决方案1】:

就像我在 cmets 中所说的那样,您必须为印度人的名字创建自己的语料库,并对照它测试您的文本。 NLTK 书在Chapter 2 中教你如何做到这一点(确切地说是第 1.9 节)。

from nltk.corpus import PlaintextCorpusReader

# You can use a regular expression to find the files, or pass a list of files
files = ".*\.txt"

new_corpus = PlaintextCorpusReader("/path/", files)
corpus  = nltk.Text(new_corpus.words())

另见:Creating a new corpus with NLTK

【讨论】:

    【解决方案2】:

    命名实体识别不仅仅是查找已知名称;识别器使用线索的组合,包括单词的形式和文本的结构。您无法识别的名称出现在标题中,而不是运行文本中,因此 nltk 的识别器(无论如何也不是那么好)找不到它。看看如果你在文本中使用这个名字会发生什么:

    >>> text = "Balaji Chandrasekaran is a senior business analyst and lives in Bangalore."
    >>> words = nltk.word_tokenize(text)
    >>> print(nltk.ne_chunk(nltk.pos_tag(words)))
    (S
      (PERSON Balaji/NNP)
      Chandrasekaran/NNP
      is/VBZ
      a/DT
      senior/JJ
      business/NN
      analyst/NN
      and/CC
      lives/NNS
      in/IN
      (GPE Bangalore/NNP)
      ./.)
    

    它错过了姓氏(就像我说的识别器不是那么好),但它能够找出这里有一个名字。

    换句话说:您的问题是您不是在挖掘文本,而是在恢复。唯一好的解决方案是使用您想要处理的相同格式的一些带注释的简历来构建和训练识别器。这并不是非常简单:您需要注释您的训练语料库,并找出您的“特征提取功能”将放入字典中的有用特征(来自单词形式和文档结构的线索)。 nltk book 的第 6 章和第 7 章的各个部分都描述了您需要的一切。

    【讨论】:

    • 谢谢,是的,我也正在使用名称语料库。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-10-09
    • 1970-01-01
    • 2019-08-22
    • 1970-01-01
    • 2013-06-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多