zoukankan      html  css  js  c++  java
  • 学习笔记CB003:分块、标记、关系抽取、文法特征结构

    分块,根据句子的词和词性,按照规则组织合分块,分块代表实体。常见实体,组织、人员、地点、日期、时间。名词短语分块(NP-chunking),通过词性标记、规则识别,通过机器学习方法识别。介词短语(PP)、动词短语(VP)、句子(S)。

    分块标记,IOB标记,I(inside,内部)、O(outside,外部)、B(begin,开始)。树结构存储分块。多级分块,多重分块方法。级联分块。

    关系抽取,找出实体间关系。实体识别认知事物,关系识别掌握真相。三元组(X,a,Y),X、Y实体,a表达关系字符串。通过正则识别。from nltk.corpus import conll2000,print(conll2000.chunked_sents('train.txt')[99]) 。

    文法,潜在无限句子集合紧凑特性。形式化模型,覆盖所有结构句子。符合多种文法句子有歧义。只能用特征方法处理。

    文法特征结构,单词最后字母、词性标签、文法类别、正字拼写、指示物、关系、施事角色、受事角色。文法特征是键值对,特征结构存储形式是字典。句法协议、属性、约束、术语。import nltk,fs1 = nltk.FeatStruct(TENSE='past', NUM='sg') ,fs2 = nltk.FeatStruct(POS='N', AGR=fs1) 。nltk产生式文法描述 /nltk_data/grammars/book_grammars 。sql0.fcfg,查找国家城市sql语句文法:

    % start S

    S[SEM=(?np + WHERE + ?vp)] -> NP[SEM=?np] VP[SEM=?vp]

    VP[SEM=(?v + ?pp)] -> IV[SEM=?v] PP[SEM=?pp]
    VP[SEM=(?v + ?ap)] -> IV[SEM=?v] AP[SEM=?ap]
    NP[SEM=(?det + ?n)] -> Det[SEM=?det] N[SEM=?n]
    PP[SEM=(?p + ?np)] -> P[SEM=?p] NP[SEM=?np]
    AP[SEM=?pp] -> A[SEM=?a] PP[SEM=?pp]

    NP[SEM='Country="greece"'] -> 'Greece'
    NP[SEM='Country="china"'] -> 'China'

    Det[SEM='SELECT'] -> 'Which' | 'What'

    N[SEM='City FROM city_table'] -> 'cities'

    IV[SEM=''] -> 'are'
    A[SEM=''] -> 'located'
    P[SEM=''] -> 'in'

    加载文法描述

    import nltk
    from nltk import load_parser
    cp = load_parser('grammars/book_grammars/sql0.fcfg')
    query = 'What cities are located in China'
    tokens = query.split()
    for tree in cp.parse(tokens):
    print(tree)

    参考资料:

    《Python 自然语言处理》

    http://www.shareditor.com/blogshow?blogId=70

    http://www.shareditor.com/blogshow?blogId=71

    欢迎推荐上海机器学习工作机会,我的微信:qingxingfengzi

  • 相关阅读:
    韩式英语
    Daily dictation 听课笔记
    words with same pronunciation
    you will need to restart eclipse for the changes to take effect. would you like to restart now?
    glottal stop(britain fountain mountain)
    education 的发音
    第一次用Matlab 的lamada语句
    SVN的switch命令
    String的split
    SVN模型仓库中的资源从一个地方移动到另一个地方的办法(很久才解决)
  • 原文地址:https://www.cnblogs.com/libinggen/p/8448278.html
Copyright © 2011-2022 走看看