之前安裝了幾次沒有成功,
PengYi <notifications@github.com>,這哥們發email說:
看源代碼里面,ltp是一個link。所以,git clone下來,這個目錄下面是空的。需要進入源代碼目錄。把ltp刪掉,然后在執行 git clone git@github.com:HIT-SCIR/ltp.git,把ltp這個源碼下載下來,再執行 python setup.py install
$git clone https://github.com/HIT-SCIR/pyltp
$cd pyltp/
$ls
$rm -rf ltp/
執行這一步的時候,有可能會出錯
Permission Denied (publickey)問題
看文檔 https://blog.csdn.net/sxg0205/article/details/81412921自行解決
$git clone git@github.com:HIT-SCIR/ltp.git
$cd ltp
這一步修改一下版本號,大概在121行,我的是10.13
$vim setup.py
這一步有可能會出現權限問題,加sudo 執行
$sudo python setup.py install
Installed /Library/Python/2.7/site-packages/pyltp-0.2.1-py2.7-macosx-10.13-intel.egg
Processing dependencies for pyltp==0.2.1
Finished processing dependencies for pyltp==0.2.1
測試一下
>>> from pyltp import SentenceSplitter
>>> sents = SentenceSplitter.split('元芳你怎么看?我就趴窗口上看唄!')
>>> print '\n'.join(sents)
元芳你怎么看?
我就趴窗口上看唄!
分詞
$ python
Python 2.7.10 (default, Oct 6 2017, 22:29:07)
[GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.31)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from pyltp import Segmentor
>>> import os
>>> segmentor = Segmentor()
>>> LTP_DATA_DIR = '/Users/XXXX/pyltp/'
>>> cws_model_path = os.path.join(LTP_DATA_DIR, 'cws.model')
>>> segmentor.load(cws_model_path)
>>> words = segmentor.segment('元芳你怎么看。')
>>> print '\t'.join(words)
元芳 你 怎么 看 。
