python中pos括号中_如何获得括号格式的解析(不带POS标记)?

我分析了接受的版本,当我需要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方面的专家,所以我希望这不会有什么不同。至少不适合我的申请。在

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值