Houve um problema que me deixou confuso quando usei a integração nltk e nlp standford.
Meus ambientes de desenvolvimento como este:
Todos os tipos de jarros existem exatamente lá, tenho certeza, há algo de errado com o meu caminho ou com os parâmetros que coloquei na classe do StanfordSegmenter? O exemplo foi bastante fácil o que eu encontrei no documento nltk 3.3, eles apenas colocaram em um parâmetro que "path_to_slf4j".
Então, alguém, me ajude :-(!
@ libingnan54321 por que você não está usando a versão 3.9.1 mais recente?
Você pode tentar este primeiro e fornecer o resultado?
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,
)
Use a nova interface CoreNLPParser
.
Primeiro atualize seu NLTK:
pip3 install -U nltk
Ainda no 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
Para chinês:
# 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 &
Então, em Python3:
>>> from nltk.parse import CoreNLPParser
>>> parser = CoreNLPParser('http://localhost:9001')
>>> list(parser.tokenize(u'我家没有电脑。'))
['我家', '没有', '电脑', '。']
Para árabe:
# 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
Finalmente, inicie o 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))
['انا', 'حامل']
Fechando o problema como resolvido por enquanto =)
Abra se houver mais problemas.
Comentários muito úteis
Use a nova interface
CoreNLPParser
.Primeiro atualize seu NLTK:
Ainda no terminal:
Para chinês:
Então, em Python3:
Para árabe:
Finalmente, inicie o Python: