如何获得斯坦福解析器的正确输出格式?不是树格式

时间:2019-04-09 03:18:57

标签: stanford-nlp

我目前在斯坦福解析器中使用Python接口,但是我不想获取树输出格式。

import sys

import os

from nltk.parse import stanford


os.environ['STANFORD_PARSER'] = 'E:/jars/stanford-parser.jar'

os.environ['STANFORD_MODELS'] = 'E:/jars/stanford-parser-3.9.2-models.jar'

parser1 = stanford.StanfordParser(model_path="/stanford-parser-full-2018-10-17/edu/stanford/nlp/models/lexparser/englishPCFG.ser.gz")

output=list(parser.raw_parse("The young man who boarded his usual train that Sunday afternoon was twenty-four years old and fat. "))

print(output)

代码输出如下:

[Tree('ROOT', [Tree('S', [Tree('NP', [Tree('NP', [Tree('DT', ['The']), Tree('JJ', ['young']), Tree('NN', ['man'])]), Tree('SBAR', [Tree('WHNP', [Tree('WP'....Tree('.', ['.'])])])]

但是,我不需要标签,因此我希望输出的格式如下:

( ( A person ) ( ( ( ( is ( at ( a diner ) ) ) , ) ( ordering ( an omelette ) ) ) . ) ) 

我们将非常感谢您的帮助。谢谢!

0 个答案:

没有答案