SmoothNLP
- python
- Java
Python
python interfaces for SmoothNLP 的 Python 接口, 支持自動下載底層jar包 ,目前支持Python3
Pypi 官方安裝
pip3 install smoothnlp
復制代碼
請注意使用python3
安裝smoothnlp項目,當前版本 version=0.2.4
如果您使用的Mac,且用anaconda管理python, 可能會碰到報錯, 請嘗試:
export MACOSX_DEPLOYMENT_TARGET=10.10 CFLAGS='-stdlib=libc++'
pip3 install jpype1
pip3 install smoothnlp
復制代碼
API
通過smoothnlp 調用python 接口
1.Tokenize分詞
import smoothnlp
smoothnlp.segment('歡迎使用smoothnlp的Python接口')
['歡迎', '使用', 'smoothnlp', '的', 'Python', '接口']
復制代碼
2.Postag詞性標注
import smoothnlp
smoothnlp.postag('歡迎使用smoothnlp的Python接口')
[{'postag': 'VV', 'token': '歡迎'}, {'postag': 'VV', 'token': '使用'}, {'postag': 'NN', 'token': 'smoothnlp'}, {'postag': 'DEC', 'token': '的'}, {'postag': 'NN', 'token': 'Python'}, {'postag': 'NN', 'token': '接口'}]
復制代碼
3.NER 實體識別
import smoothnlp
smoothnlp.ner("中國平安2019年度長期服務計劃于2019年5月7日至5月14日通過二級市場完成購股," \"共購得本公司A股股票5429.47萬股,占總股本的比例為0.297%," \"成交金額合計42.96億元(含費用),成交均價約為79.10元/股")
[{'charEnd': 4, 'charStart': 0, 'nerTag': 'financial_agency', 'normalizedEntityValue': '中國平安', 'sTokenList': None, 'text': '中國平安'},{'charEnd': 9, 'charStart': 4, 'nerTag': 'datetime', 'normalizedEntityValue': '2019年', 'sTokenList': None, 'text': '2019年'}, {'charEnd': 26, 'charStart': 17, 'nerTag': 'datetime', 'normalizedEntityValue': '2019年5月7日', 'sTokenList': None, 'text': '2019年5月7日'},{'charEnd': 29, 'charStart': 27, 'nerTag': 'datetime', 'normalizedEntityValue': '5月', 'sTokenList': None, 'text': '5月'}, {'charEnd': 51, 'charStart': 49, 'nerTag': 'financial_metric', 'normalizedEntityValue': 'A股', 'sTokenList': None, 'text': 'A股'}, {'charEnd': 53, 'charStart': 51, 'nerTag': 'financial_metric', 'normalizedEntityValue': '股票', 'sTokenList': None, 'text': '股票'}, {'charEnd': 61, 'charStart': 53, 'nerTag': 'NUMBER', 'normalizedEntityValue': '54294700', 'sTokenList': {'25': {'postag': 'NN', 'token': '5429.47萬'}}, 'text': '5429.47萬'}, {'charEnd': 67, 'charStart': 64, 'nerTag': 'organization_metric', 'normalizedEntityValue': '總股本', 'sTokenList': None, 'text': '總股本'}, {'charEnd': 77, 'charStart': 71, 'nerTag': 'PERCENT', 'normalizedEntityValue': '0.297%', 'sTokenList': {'33': {'postag': 'NN', 'token': '0.297%'}}, 'text': '0.297%'}, {'charEnd': 91, 'charStart': 84, 'nerTag': 'MONEY', 'normalizedEntityValue': '¥4296000000', 'sTokenList': {'38': {'postag': 'CD', 'token': '42.96億'}, '39': {'postag': 'M', 'token': '元'}}, 'text': '42.96億元'}, {'charEnd': 109, 'charStart': 103, 'nerTag': 'MONEY', 'normalizedEntityValue': '¥79.1', 'sTokenList': {'49': {'postag': 'CD', 'token': '79.10'}, '50': {'postag': 'M', 'token': '元'}}, 'text': '79.10元'}]
復制代碼
4. 金融實體識別
import smoothnlp
smoothnlp.financial_agency_recognize("中國平安2019年度長期服務計劃于2019年5月7日至5月14日通過二級市場完成購股")
[{'charEnd': 4, 'charStart': 0, 'nerTag': 'financial_agency', 'normalizedEntityValue': '中國平安', 'sTokenList': None, 'text': '中國平安'}]
復制代碼
5.數字實體識別
import smoothnlp
smoothnlp.number_recognize("百度移動應用的月活躍設備達11億臺")
#-- output
[{'charEnd': 16, 'charStart': 13, 'nerTag': 'NUMBER', 'normalizedEntityValue': '1100000000', 'sTokenList': {'9': {'postag': 'CD', 'token': '11億'}}, 'text': '11億'}]
復制代碼
更多功能請閱讀pySmoothnlp項目文檔
Java
SmoothNLP項目的主要功能都在Java中有實現, 打包好的Jar文件會在[Release頁面]定期更新, 或者在提供的maven項目代碼中, 直接編譯即可
git clone https://github.com/smoothnlp/SmoothNLP.git
cd smoothnlp_maven
mvn clean package
復制代碼
編譯好的Jar文件會在 smoothnlp_maven/target/smoothnlp-*.jar