μλ νμΈμ,
μ€ν ν¬λ νμ μμ λ₯Ό μ€ννλ €κ³ ν©λλ€. μ
from nltk.parse.stanford import *
dep_parser=StanfordDependencyParser(model_path="edu/stanford/nlp/models/lexparser/englishPCFG.ser.gz")
[parse.tree() for parse in dep_parser.raw_parse("The quick brown fox jumps over the lazy dog.")]
λ§μ§λ§ λͺ λ Ήμ μ€ννλ©΄ μ€λ₯κ° λ°μν©λλ€.
OSError: Java command failed : [u'/usr/bin/java', u'-mx1000m', '-cp', ....
λͺ
λ Ήμ€μμ λμΌν λͺ
λ Ήμ μ¬νν λ Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
μ€λ₯κ° λ°μν©λλ€.
λ°λΌμ slf4j-api.jar
λ₯Ό _λͺ
λ Ήμ€μμ_ ν΄λμ€ κ²½λ‘μ μΆκ°νλ©΄ ꡬ문 λΆμμ΄ μ±κ³΅ν©λλ€.
μ΄λ»κ² slf4j-api.jar
λ₯Ό nltk ν΄λμ€ κ²½λ‘μ μΆκ°ν μ μμΌλ―λ‘ κ΅¬λ¬Έ λΆμμ΄ μ±κ³΅ν μ μμ΅λκΉ?
κ°μ¬ν©λλ€!
μ¦κ±°μ΄ ν΄μΌ 보λ΄μΈμ
@yuvval Stanford Parser λ²μ 2015-12-09λ₯Ό μ¬μ©νκ³ μλμ§ νμΈνμμμ€. κ·Έλ λ€λ©΄ μ΄ μ€λ₯λ μ΄μ λ³΄λ€ λ λ§μ μ’ μμ±μ μ¬μ©νλ μλ‘μ΄ StanfordNLPλ‘ μΈν΄ λ°μν©λλ€. μ΄κ²μ #1237κ³Ό μ μ¬ν©λλ€.
#1237μ΄ μμ λκ³ NLTKκ° Standford λꡬλ₯Ό λ°λΌμ‘κΈ° μ μ μ μ κΈ°λ€λ €μΌ ν©λλ€.
λΉ λ₯Έ μμ μ루μ μ λ€μ μ€ νλμ λλ€.
from nltk.internals import find_jars_within_path
from nltk.parse.stanford import StanfordDependencyParser
dep_parser=StanfordDependencyParser(model_path="edu/stanford/nlp/models/lexparser/englishPCFG.ser.gz")
stanford_dir = st._stanford_jar.rpartition('/')[0]
# or in windows comment the line above and uncomment the one below:
#stanford_dir = st._stanford_jar.rpartition("\\")[0]
stanford_jars = find_jars_within_path(stanford_dir)
st.stanford_jar = ':'.join(stanford_jars)
[parse.tree() for parse in dep_parser.raw_parse("The quick brown fox jumps over the lazy dog.")]
κ°μ¬ν©λλ€! 2015-04-20 λ²μ μμ μλν©λλ€.
classpath ν΄νΉλ μλνμ΅λκΉ?
μλνμ§ μμμ΅λλ€. λ°©κΈ μ΅μ λ²μ μ μμ νκ³ 2015-04-20 λ²μ μ λ€μ΄λ‘λνμ΅λλ€.
μλ νμΈμ! λλ λΉμ μ ν΄νΉμ λ°λ₯΄λ €κ³ νμ§λ§ λμκ²λ `StanfordDependencyParser``κ° μμ΅λλ€.
print(nltk.__version__)
from nltk.tag import StanfordDependencyParser
3.1
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-7-67bb74c3494a> in <module>()
----> 1 from nltk.tag import StanfordDependencyParser
ImportError: cannot import name 'StanfordDependencyParser'
μ΄ λ¬Έμ λ₯Ό ν΄κ²°νλ λ°©λ²μ λν μμ΄λμ΄κ° μμ΅λκΉ? μ΅μ μ€ν ν¬λ λ²μ μ μ¬μ©νκ³ μΆμ΅λλ€.
@methodds μ€νλ₯Ό μ©μνμμμ€. from nltk.parse.stanford import StanfordDependencyParser
μ
λλ€. μμΈν μ€λͺ
μ https://gist.github.com/alvations/e1df0ba227e542955a8a λ₯Ό μ°Έμ‘°νμΈμ.
λ§ν¬ μ£Όμ μ κ°μ¬ν©λλ€. λΆννλ λ΄ λ¦¬λ μ€ λ―ΌνΈ OSμμ μλνλ νκ²½ λ³μλ₯Ό μ»μ μ μμ΅λλ€.
λ΄ bashrc
λ λ€μκ³Ό κ°μ΅λλ€.
export JAVA_HOME="/usr/lib/jvm/java-8-oracle/"
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH="/home/cs/stanford_nlp/stanford-postagger-full-2015-04-20/stanford-postagger.jar:$CLASSPATH"
export CLASSPATH="/home/cs/stanford_nlp/stanford-ner-2015-04-20/stanford-ner.jar:$CLASSPATH"
export STANFORD_MODELS="/home/cs/stanford_nlp/stanford-ner-2015-04-20/classifiers:$STANFORD_MODELS"
export STANFORD_MODELS="/home/cs/stanford_nlp/stanford-postagger-full-2015-04-20/models:$STANFORD_MODELS"
λ³μλ₯Ό λ°μνλ©΄ λ€μκ³Ό κ°μ΄ μ¬λ°λ₯΄κ² 보μ λλ€.
echo $CLASSPATH
/home/cs/stanford_nlp/stanford-ner-2015-04-20/stanford-ner.jar:/home/cs/stanford_nlp/stanford-postagger-full-2015-04-20/stanford-postagger.jar
echo $STANFORD_MODELS
/home/cs/stanford_nlp/stanford-postagger-full-2015-04-20/models:/home/cs/stanford_nlp/stanford-ner-2015-04-20/classifiers
κ·Έλ¬λ (μ¬λΆν νμλ) NLTKλ μ¬μ ν νκ±°λ₯Ό μ°Ύμ§ λͺ»ν©λλ€.
from nltk.tag.stanford import StanfordPOSTagger
st = StanfordPOSTagger('english-bidirectional-distsim.tagger')
st.tag('What is the airspeed of an unladen swallow ?'.split())
NLTK was unable to find stanford-postagger.jar! Set the CLASSPATH
environment variable.
source .bashrc
λ₯Ό μννλ©΄ μλνλ λμ http://apple.stackexchange.com/questions/12993/why-doesnt-bashrc-run-automatically μμ bashrcκ° μλνλ λ°©μμ μμ보μμμ€.
νμ μ£Όμ μ κ°μ¬ν©λλ€. νμ§λ§ μ¬μ μ .bashrc μμ€λ₯Ό μ λ ₯νλλ° μλνμ§ μμμ΅λλ€. λ€μ μλνμ§λ§ λΆννλ μ¬μ ν μλνμ§ μμ΅λλ€.
Linux λ°°ν¬ν λ° λ²μ μ 무μμ
λκΉ? lsb_release -a
μμ΅λκΉ? μλλ©΄ MacμΌλ‘ μμ
νκ³ μμ΅λκΉ?
μ‘°μ¬ν΄μ£Όμ
μ κ°μ¬ν©λλ€. ` lsb_release -a
λ°ν
No LSB modules are available.
Distributor ID: LinuxMint
Description: Linux Mint 17.3 Rosa
Release: 17.3
Codename: rosa
export
λͺ
λ Ήμ μ΄λμμ μννμ΅λκΉ? μ΄λ€ λλ ν 리?Python μ€ν¬λ¦½νΈλ₯Ό μ€ννλ €λ μμΉλ‘ μ΄λνμ¬ λ€μμ μνν©λλ€. import os; print os.environ
.
κ·Έλ° λ€μ ν λλ ν λ¦¬λ‘ μ΄λνμ¬ pythonμ μμνκ³ λμΌν μμ
μ μνν©λλ€. import os; print os.environ
λ μΈνΈμ νκ²½ λ³μκ° λ€λ₯Έ κ²μ΄ 보μ΄μλμ?
.bashrc
μμ λ΄λ³΄λΈ νκ²½ λ³μλ₯Ό λνλ΄μ§ μμ import os; print(os.environ)
μ μ¬μ©νκΈ°λ₯Ό μνλ κ² κ°μ΅λλ€. κ·Έ ν λ΄μ©μ 볡μ¬νμ¬ .profile
(λ΄ ν ν΄λμ μμ)μ λΆμ¬λ£κ³ μ΄μ μλ²½νκ² μλν©λλ€. μ =DμΈμ§ λͺ¨λ₯΄κ² μ΅λλ€.
.profile
μλν΄μ λ€νμ
λλ€. OS λ°°ν¬ν λ¬Έμ μΈ κ² κ°μ΅λλ€. νκ²½ λ³μλ₯Ό μ μ μΌλ‘ μ μ₯νμ§ μλ κ²μ΄ μ’μ΅λλ€. κ°μΈμ μΌλ‘ Python μ€ν¬λ¦½νΈλ₯Ό μμν λλ§λ€ λ€μ μ€ννμ¬ μΆ©λμ΄ μλμ§ νμΈν μ μμ΅λλ€. NLTK APIμ Stanford λκ΅¬λ‘ μ¦κ±°μ΄ μκ°μ 보λ΄μΈμ!
κ³ λ§μ΅λλ€ :)
'stanford_dir = st._stanford_jar.rpartition('/')[0]' λͺ λ Ήμμ 'st'λ 무μμ λκΉ?
hansen7λκ³Ό κ°μ μ§λ¬Έμ΄ μμ΅λλ€.
stκ° λ¬΄μμΈμ§ μ°Ύκ³ μλ μμμ μ¬λλ€μ μν΄,
st = StanfordNERTagger(os.environ.get('STANFORD_MODELS'))
μ°Έμ‘°: https://gist.github.com/manashmndl/810db10809cbc1209b34c7d25efe95d5#file -stanfordnertagger-py
κ°μ₯ μ μ©ν λκΈ
'stanford_dir = st._stanford_jar.rpartition('/')[0]' λͺ λ Ήμμ 'st'λ 무μμ λκΉ?