python调⽤java的ansj_seg分词⼯具
出现错误:
jpype._jexception.RuntimeExceptionPyRaisable: java.lang.RuntimeException: Class org.ansj.splitWord.analysis.ToAnalysis
not found。
python调⽤ java 的 ansj_seg 分词⼯具的时候
开始时候参考的是
github链接:
代码为(class那⾥将冒号:改为分号;就可以了):
# -*- coding:utf-8 -*-
# -*- created by: mo -*-
import jpype
import os
# jvmPath = '/usr/lib/java/jdk1.8.0_161/jre/lib/amd64/server/libjvm.so'
jvmPath = 'D:/software/Java/Java8/jre/bin/server/jvm.dll'
# jvmPath = 'D:/software/Java/Java8/jre/bin/server/libjvm.so'
print (jvmPath)
jars_dir_ansj_seg = 'D:/software/IDEA/tools/maven_soft/org/ansj/ansj_seg/5.1.6'
jars_dir_nlp_lang = 'D:/software/IDEA/tools/maven_soft/org/nlpcn/nlp-lang/1.7.7'
jars_dir_tree_split = 'D:/software/IDEA/tools/maven_soft/org/ansj/tree_split/1.5'
jars = [os.path.join(jars_dir_ansj_seg, 'ansj_seg-5.1.6.jar'), os.path.join(jars_dir_nlp_lang, 'nlp-lang-1.7.7.jar'), os.path.join(jars_dir_tree_split, 'tree_split-1.5.ja jvm_cp = "-Djava.class.path={}".format(';'.join(jars))
jpype.startJVM(jvmPath, "-ea", jvm_cp)
SegModel = jpype.JClass('org.ansj.splitWord.analysis.ToAnalysis')
jd = SegModel()
print(jd.parseStr("怎么这么⿇烦"))
jpype.shutdownJVM()
结果:
D:/software/Java/Java8/jre/bin/server/jvm.dll
���� 20, 2018 8:59:15 ���� org.ansj.util.MyStaticValue warn
����: not find library.properties in classpath use it by default !
���� 20, 2018 8:59:15 ���� org.ansj.dic.impl.File2Stream info
��Ϣ: path to stream library/ambiguity.dic
���� 20, 2018 8:59:15 ���� org.ansj.library.AmbiguityLibrary error
python转java代码����: Init ambiguity library error :ption.LibraryException:  path :library/ambiguity.dic
file:D:\workspace\python\django_server\nlp_app\segment\library\ambiguity.dic not found or can not to read, path: library/ambiguity.dic
���� 20, 2018 8:59:15 ���� org.ansj.dic.impl.File2Stream info
��Ϣ: path to stream library/default.dic
���� 20, 2018 8:59:15 ���� org.ansj.library.DicLibrary error
����: Init dic library error :ption.LibraryException:  path :library/default.dic
file:D:\workspace\python\django_server\nlp_app\segment\library\default.dic not found or can not to read, path: library/default.dic
���� 20, 2018 8:59:15 ���� org.ansj.library.DATDictionary info
��Ϣ: init core library ok use time : 544
���� 20, 2018 8:59:15 ���� org.ansj.library.NgramLibrary info
��Ϣ: init ngram ok use time :276
怎么/r,这么/r,⿇烦/an
JVM activity report    :
classes loaded      : 26
JVM has been shutdown

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。