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
๋ง์ง๋ง์ผ๋ก 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))
['ุงูุง', 'ุญุงู
ู']
ํ์ฌ ํด๊ฒฐ๋ ๋๋ก ๋ฌธ์ ์ข
๋ฃ =)
์ถ๊ฐ ๋ฌธ์ ๊ฐ ์์ผ๋ฉด ์ด์ด์ฃผ์ธ์.
๊ฐ์ฅ ์ ์ฉํ ๋๊ธ
์๋ก์ด
CoreNLPParser
์ธํฐํ์ด์ค๋ฅผ ์ฌ์ฉํ์ญ์์ค.๋จผ์ NLTK๋ฅผ ์ ๋ฐ์ดํธํ์ญ์์ค.
๊ทธ๋ฐ ๋ค์ ์ฌ์ ํ ํฐ๋ฏธ๋์ ์์ต๋๋ค.
์ค๊ตญ์ด:
๊ทธ๋ฐ ๋ค์ Python3์์:
์๋์ด:
๋ง์ง๋ง์ผ๋ก Python์ ์์ํฉ๋๋ค.