Nltk: Tolong bantu aku! nltk dan integrasi nlp standford

Dibuat pada 6 Jul 2018  ·  3Komentar  ·  Sumber: nltk/nltk

Ada masalah yang membuat saya bingung ketika saya menggunakan integrasi nltk dan standford nlp.
Lingkungan pengembangan saya seperti ini:

  1. nltk 3.3
  2. standford nlp stanford-segmenter 3.6.0 / 3.9.1
    Dan saya mencoba membuat Objek StanfordSegmenter seperti ini:
    standfordNlpPath = self.projectPath + "\standford-nlp\stanford-segmenter-2015-12-09"
    stanfordSegmenter= StanfordSegmenter(
    path_to_jar=standfordNlpPath + "\stanford-segmenter-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\dict-chris6.ser.gz")
    maka kegagalan seperti ini sebagai hasil:
    ================================================== ===========================
    NLTK tidak dapat menemukan stanford-segmenter.jar! Setel CLASSPATH
    variabel lingkungan.
    Untuk informasi lebih lanjut, di stanford-segmenter.jar, lihat:

https://nlp.stanford.edu/software

Semua jenis toples persis ada di sana saya cukup yakin, apakah ada yang salah dengan jalur saya atau parameter yang saya masukkan ke dalam kelas StanfordSegmenter? Contohnya cukup mudah yang saya temukan di dokumen nltk 3.3, mereka hanya memasukkan satu parameter yaitu "path_to_slf4j".
Jadi, seseorang, tolong aku :-( !

resolved stanford api

Komentar yang paling membantu

Harap gunakan antarmuka CoreNLPParser .

Pertama perbarui NLTK Anda:

pip3 install -U nltk

Kemudian masih di terminal:

# 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


Untuk bahasa Cina:

# 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 & 

Kemudian di Python3:

>>> from nltk.parse import CoreNLPParser
>>> parser = CoreNLPParser('http://localhost:9001')
>>> list(parser.tokenize(u'我家没有电脑。'))
['我家', '没有', '电脑', '。']

Untuk bahasa Arab:

# 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

Akhirnya, mulai Python:

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

Semua 3 komentar

@libingnan54321 mengapa Anda tidak menggunakan versi 3.9.1 terbaru?

Bisakah Anda mencoba yang ini terlebih dahulu dan memberikan hasilnya?

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,
)

Harap gunakan antarmuka CoreNLPParser .

Pertama perbarui NLTK Anda:

pip3 install -U nltk

Kemudian masih di terminal:

# 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


Untuk bahasa Cina:

# 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 & 

Kemudian di Python3:

>>> from nltk.parse import CoreNLPParser
>>> parser = CoreNLPParser('http://localhost:9001')
>>> list(parser.tokenize(u'我家没有电脑。'))
['我家', '没有', '电脑', '。']

Untuk bahasa Arab:

# 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

Akhirnya, mulai Python:

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

Menutup masalah sebagai diselesaikan untuk saat ini =)
Silakan buka jika ada masalah lebih lanjut.

Apakah halaman ini membantu?
0 / 5 - 0 peringkat