栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

stanfordnlp python 踩坑记录

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

stanfordnlp python 踩坑记录

1 mac上踩坑 1.1 mac上启动java服务–没问题

安装java
下载最新jar包,模型包,解压
进入文件下启动Java服务
java -Xmx4g -cp “*” edu.stanford.nlp.pipeline.StanfordCoreNLPServer -serverProperties StanfordCoreNLP-chinese.properties -port 9000 -timeout 15000

curl没问题:
curl --data ‘打开微信’ ‘http://localhost:9000/?properties={%22annotators%22%3A%22tokenize%2Cssplit%2Cpos%22%2C%22outputFormat%22%3A%22json%22}’ -o -

python request调用没问题:
import requests
print(requests.post(‘http://[::]:9000/?properties={“annotators”:“tokenize,ssplit,pos”,“outputFormat”:“json”}’, data = {‘data’:‘The quick brown fox jumped over the lazy dog.’}).text)

1.2 mac上使用stanfordcorenlp python–有问题

process.py文件调用
from stanfordcorenlp import StanfordCoreNLP
nlp = StanfordCoreNLP(‘C:/myLearning/stanford-corenlp-full-2016-10-31’, lang=‘zh’)#处理中文需指定lang=‘zh’,英文不用,其它语言也有
sentence = ‘我是tab,我现在正在学习python’
#分词
print(nlp.word_tokenize(sentence))
#词性标注
print(nlp.pos_tag(sentence))
#命名实体识别
print(nlp.ner(sentence))

问题1:运行process.py
psutil.AccessDenied: (pid=41793)
有人建议加上权限 sudo

问题2:sudo运行process.py
RuntimeError: proc_pidinfo(PROC_PIDLISTFDS) 2/2 syscall failed
有人建议加上port,详见:https://blog.csdn.net/weixin_43823924/article/details/125545016
self.model = StanfordCoreNLP(model_path, lang=‘zh’, logging_level=logging.DEBUG, port=9001)
依然报错。即使这个接口没有被占用过

2 centos上踩坑

java启动服务,可以curl访问,可以requests请求
但是使用Processor.py返回response 500

解决方式:
stanfordcorenlp源码里面:

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/1018652.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号