Nltk: ساعدني من فضلك! تكامل nltk و standford nlp

تم إنشاؤها على ٦ يوليو ٢٠١٨  ·  3تعليقات  ·  مصدر: nltk/nltk

كانت هناك مشكلة جعلتني مرتبكًا عندما استخدمت تكامل nltk و standford nlp.
بيئات التطوير الخاصة بي مثل هذا:

  1. nltk 3.3
  2. ستاندفورد nlp ستانفورد-مقطع 3.6.0 / 3.9.1
    وأحاول إنشاء كائن StanfordSegmenter مثل هذا:
    standfordNlpPath = self.projectPath + "\ standford-nlp \ stanford-sectioner-2015-12-09"
    stanfordSegmenter = StanfordSegmenter (
    path_to_jar = standfordNlpPath + "\ stanford-sectioner-3.6.0.jar" ،
    path_to_slf4j = standfordNlpPath + "\ slf4j-api.jar" ،
    path_to_sihan_corpora_dict = standfordNlpPath + "\ data-2015" ،
    path_to_model = standfordNlpPath + "\ data-2015 \ pku.gz" ،
    path_to_dict = standfordNlpPath + "\ data-2015 \ict-chris6.ser.gz")
    ثم فشل مثل هذا كنتيجة:
    ==================================================== ==========================
    لم يتمكن NLTK من العثور على stanford-segmenter.jar! اضبط CLASSPATH
    متغيرات البيئة.
    لمزيد من المعلومات حول stanford-sectioner.jar ، انظر:

https://nlp.stanford.edu/software

توجد جميع أنواع الجرار هناك تمامًا ، وأنا متأكد تمامًا ، هل هناك أي خطأ في مساري أو المعلمات التي وضعتها في فصل StanfordSegmenter؟ المثال كان سهلاً للغاية ما وجدته في مستند nltk 3.3 ، لقد وضعوا فقط في معلمة واحدة "path_to_slf4j".
لذا ، شخص ما ، ساعدني :-(!

resolved stanford api

التعليق الأكثر فائدة

الرجاء استخدام الواجهة الجديدة 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))
['انا', 'حامل']

ال 3 كومينتر

@ 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))
['انا', 'حامل']

إغلاق المشكلة كما تم حلها الآن =)
الرجاء فتح إذا كانت هناك مشاكل أخرى.

هل كانت هذه الصفحة مفيدة؟
0 / 5 - 0 التقييمات