Дерево разбора в StanfordCoreNLP и Stanza дает разные результаты (структура представления) - PullRequest
0 голосов
/ 02 мая 2020

Я выполнил разбор зависимостей, используя StanfordCoreNLP, используя код ниже

from stanfordcorenlp import StanfordCoreNLP
nlp = StanfordCoreNLP('stanford-corenlp-full-2018-10-05', lang='en')

sentence = 'The clothes in the dressing room are gorgeous. Can I have one?'
tree_str = nlp.parse(sentence)
print(tree_str)

И я получил вывод:

  (S
    (NP
      (NP (DT The) (NNS clothes))
      (PP (IN in)
        (NP (DT the) (VBG dressing) (NN room))))
    (VP (VBP are)
      (ADJP (JJ gorgeous)))
    (. .)))

Как я могу получить этот же вывод в Stanza ??

import stanza
from stanza.server import CoreNLPClient
classpath='/stanford-corenlp-full-2020-04-20/*'
client = CoreNLPClient(be_quite=False, classpath=classpath, annotators=['parse'], memory='4G', endpoint='http://localhost:8900')
client.start()
text = 'The clothes in the dressing room are gorgeous. Can I have one?'
ann = client.annotate(text)
sentence = ann.sentence[0]
dependency_parse = sentence.basicDependencies
print(dependency_parse)

В строфе Похоже, мне нужно разделить предложения, из которых состоит предложение. Есть ли что-то, что я делаю неправильно?

Обратите внимание, что моя цель состоит в том, чтобы извлечь словосочетания.

1 Ответ

2 голосов
/ 03 мая 2020

Здесь есть некоторая документация по использованию: https://stanfordnlp.github.io/stanza/corenlp_client.html#usage

Здесь показано, как получить анализ группы участников (это форма вашего выходного примера). Анализ зависимости представляет собой список граней между словами.

# set up the client
with CoreNLPClient(annotators=['tokenize','ssplit','pos','lemma','ner', 'parse'], timeout=30000, memory='16G') as client:
    # submit the request to the server
    ann = client.annotate(text)

    # get the first sentence
    sentence = ann.sentence[0]

    # get the constituency parse of the first sentence
    print('---')
    print('constituency parse of first sentence')
    constituency_parse = sentence.parseTree
    print(constituency_parse)

    # get the first subtree of the constituency parse
    print('---')
    print('first subtree of constituency parse')
    print(constituency_parse.child[0])

...