我分析了接受的版本,当我需要python语言时,我创建了一个简单的函数,它可以创建相同的结果。为了分析句子,我改编了the referenced link上的版本。在import re
import string
from stanfordcorenlp import StanfordCoreNLP
from nltk import Tree
from functools import reduce
regex = re.compile('[%s]' % re.escape(string.punctuation))
def parse_sentence(sentence):
nlp = StanfordCoreNLP(r'./stanford-corenlp-full-2018-02-27')
sentence = regex.sub('', sentence)
result = nlp.parse(sentence)
result = result.replace('\n', '')
result = re.sub(' +',' ', result)
nlp.close() # Do not forget to close! The backend server will consume a lot memery.
return result.encode("utf-8")
def binarize(parsed_sentence):
sentence = sentence.replace("\n", "")
for pattern in ["ROOT", "SINV", "NP", "S", "PP", "ADJP", "SBAR",
"DT", "JJ", "NNS", "VP", "VBP", "RB"]:
sentence = sentence.replace("({}".format(pattern), "(")
sentence = re.sub(' +',' ', sentence)
return sentence
无论是我的版本还是接受的版本,都不能提供与SNLI或{a3}语料库中显示的结果相同的结果,因为它们将树的两个单叶集为一个。一个来自MultiNLI语料库的例子显示
"( ( The ( new rights ) ) ( are ( nice enough ) ) )"
当布思回答这里返回哪里
'( ( ( ( The) ( new) ( rights)) ( ( are) ( ( nice) ( enough)))))'。在
我不是NLP方面的专家,所以我希望这不会有什么不同。至少不适合我的申请。在