كانت هناك مشكلة جعلتني مرتبكًا عندما استخدمت تكامل nltk و standford nlp.
بيئات التطوير الخاصة بي مثل هذا:
توجد جميع أنواع الجرار هناك تمامًا ، وأنا متأكد تمامًا ، هل هناك أي خطأ في مساري أو المعلمات التي وضعتها في فصل StanfordSegmenter؟ المثال كان سهلاً للغاية ما وجدته في مستند nltk 3.3 ، لقد وضعوا فقط في معلمة واحدة "path_to_slf4j".
لذا ، شخص ما ، ساعدني :-(!
@ libingnan54321 لماذا لا تستخدم أحدث إصدار 3.9.1؟
هل يمكنك تجربة هذا أولاً وتقديم الإخراج؟
segmenter_jar_file = os.path.join(standfordNlpPath,'stanford-segmenter-2018-02-27/stanford-segmenter-3.9.1.jar')
assert(os.path.isfile(segmenter_jar_file))
stanfordSegmenter = StanfordSegmenter(
path_to_jar=segmenter_jar_file,
)
الرجاء استخدام الواجهة الجديدة CoreNLPParser
.
قم أولاً بتحديث NLTK الخاص بك:
pip3 install -U nltk
ثم لا يزال في المحطة:
# Get the CoreNLP package
wget http://nlp.stanford.edu/software/stanford-corenlp-full-2018-02-27.zip
unzip stanford-corenlp-full-2018-02-27.zip
cd stanford-corenlp-full-2018-02-27/
# Download the properties for chinese language
wget http://nlp.stanford.edu/software/stanford-chinese-corenlp-2018-02-27-models.jar
wget https://raw.githubusercontent.com/stanfordnlp/CoreNLP/master/src/edu/stanford/nlp/pipeline/StanfordCoreNLP-chinese.properties
# Download the properties for arabic
wget http://nlp.stanford.edu/software/stanford-arabic-corenlp-2018-02-27-models.jar
wget https://raw.githubusercontent.com/stanfordnlp/CoreNLP/master/src/edu/stanford/nlp/pipeline/StanfordCoreNLP-arabic.properties
للصينية:
# Start the server.
java -Xmx4g -cp "*" edu.stanford.nlp.pipeline.StanfordCoreNLPServer \
-serverProperties StanfordCoreNLP-chinese.properties \
-preload tokenize,ssplit,pos,lemma,ner,parse \
-status_port 9001 -port 9001 -timeout 15000 &
ثم في Python3:
>>> from nltk.parse import CoreNLPParser
>>> parser = CoreNLPParser('http://localhost:9001')
>>> list(parser.tokenize(u'我家没有电脑。'))
['我家', '没有', '电脑', '。']
للغة العربية:
# Start the server.
java -Xmx4g -cp "*" edu.stanford.nlp.pipeline.StanfordCoreNLPServer \
-serverProperties StanfordCoreNLP-arabic.properties \
-preload tokenize,ssplit,pos,parse \
-status_port 9005 -port 9005 -timeout 15000
أخيرًا ، ابدأ بايثون:
>>> from nltk.parse import CoreNLPParser
>>> parser = CoreNLPParser(url='http://localhost:9005')
>>> text = u'انا حامل'
>>> parser.tokenize(text)
<generator object GenericCoreNLPParser.tokenize at 0x7f4a26181bf8>
>>> list(parser.tokenize(text))
['انا', 'حامل']
إغلاق المشكلة كما تم حلها الآن =)
الرجاء فتح إذا كانت هناك مشاكل أخرى.
التعليق الأكثر فائدة
الرجاء استخدام الواجهة الجديدة
CoreNLPParser
.قم أولاً بتحديث NLTK الخاص بك:
ثم لا يزال في المحطة:
للصينية:
ثم في Python3:
للغة العربية:
أخيرًا ، ابدأ بايثون: