哈工大分词器在 mac os 10.13上的源码安装

之前安装了几次没有成功,

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 ' '.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 ' '.join(words)

元芳 怎么

原文地址:https://www.cnblogs.com/herosoft/p/9787164.html