StanfordCoreNLP英语upos注释

时间:2019-05-21 11:50:38

标签: python stanford-nlp

我想使用CoreNLPClient提取带有uPOS注释的依赖项解析器。

现在,我的代码是:

def query_NLP_server(my_text, to_print=False):
    '''
    Query the NLP server to tokenize and tag my_text, and do some process to return nice my_tokens
    :param my_text (string): The sentence we want to extract the token and the tags
    :param to_print (boolean): Option to print the resulted tokens extracted from NLP server
    :return: my_tokens (list of list of tuples): The tokens with tags extracted from my_text
    '''

    # 1- Ask the query to the NLP Server
    with CoreNLPClient(annotators=['tokenize', 'ssplit', 'pos', 'parse'],
                       timeout=30000,
                       output_format="json",
                       properties={'tokenize.language': 'en'}
                       ) as client:
        ann = client.annotate(my_text)

    # 2- Process the output of the NLP Server to have a nice token list
    output = ann['sentences'][0]['parse']
    tree = ParentedTree.fromstring(output)
    my_tokens = []
    try:
        for subtree in tree.subtrees(filter=lambda t: t[0].parent().label() == 'ROOT'):
            for subtree2 in subtree:
                my_tokens.append(subtree2.pos())
    except:  # when it is finish (the exception happen when it is ok for us)
        if to_print:
            print('The tokens extracted from NLP Server are :\n', my_tokens, '\n')
    return my_tokens

我得到的结果是:

  

[[(('I','PRP'),('am','VBP'),('looking','VBG'),('for','IN'),   ('children','NNS'),('with','IN'),('gingivitus,'NN'),('。',   '。')]]

但是我想拥有upos而不是xpos :似乎可以使用管道,如下所述:StanfordNLP Website

我已经使用此代码成功使用了法国模型:

    with CoreNLPClient(annotators=['tokenize', 'ssplit', 'pos', 'parse'],
                   timeout=30000,
                   output_format="json",
                   properties={'tokenize.language': 'en',
                               'pos.model': 'edu/stanford/nlp/models/pos-tagger/french/french-ud.tagger',
                               'parse.model': 'edu/stanford/nlp/models/lexparser/frenchFactored.ser.gz'}
                   ) as client:
    ann = client.annotate(my_text)

但是我不明白为什么英语的“基本”模型不能返回upos ...
是否可以使用StanfordCoreNLP Client以英语为语言获得upos?

1 个答案:

答案 0 :(得分:1)

目前还没有,我们还没有使用该标签集为Java Stanford Corenlp培训过针对英语的词性标签器。我将其添加到待办事项列表中。