问题解决:Stanford CoreNLP 文本包含百分号%时报错JSONDecodeError: Expecting value: line 1 column 1 (char 0)

在使用Stanford CoreNLP时遇到一个问题,当文本中包含百分号%时,会抛出JSONDecodeError。通过查阅官方文档,了解到需要对百分号进行URL编码,将其替换为%。修改代码后,成功解决了这个问题,实现了正常运行。
摘要由CSDN通过智能技术生成

原代码

sentence = "Ten of them are yellow, and there are 80% more of those in purple."
output = nlp.parse(sentence)
print(output)

报错

​​​​​​​JSONDecodeError: Expecting value: line 1 column 1 (char 0)

参考官方文档(CoreNLP Server - CoreNLP (stanfordnlp.github.io)

CoreNLP command line, except formatted as a JSON object. The POST data should be percent-encoded (otherwise known as URL encoded). In particular, you shoud esapce a % sign as %25. (Interfaces calling CoreNLP via the web service should do this escaping for their users.)

代码改为

sentence = "Ten of them are yellow, and there are 80%2
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值