pip install stanfordcorenlp 进行安装。pip install stanfordcorenlp -i https://pypi.tuna.tsinghua.edu.cn/simple 进行安装。首先需要下载相关模型,下载地址为:https://nlp.stanford.edu/software/corenlp-backup-download.html
```python from stanfordcorenlp import StanfordCoreNLP
zhmodel = StanfordCoreNLP(r'stanford-corenlp-full-2018-02-27', lang='zh') szh = '我爱自然语言处理技术!' nerzh = zhmodel.ner(s_zh)
szh1 = '我爱北京天安门!' nerzh1 = zhmodel.ner(szh1)
print(nerzh)
print(nerzh1)
输出结果:
[('我爱', 'O'), ('自然', 'O'), ('语言', 'O'), ('处理', 'O'), ('技术', 'O'), ('!', 'O')]
[('我爱', 'O'), ('北京', 'STATEORPROVINCE'), ('天安门', 'FACILITY'), ('!', 'O')]
```
```python engmodel = StanfordCoreNLP(r'stanford-corenlp-full-2018-02-27') seng = 'I love natural language processing technology!' nereng = engmodel.ner(s_eng)
seng1 = 'I love Beijing Tiananmen!' nereng1 = engmodel.ner(seng1)
print(nereng)
print(nereng1)
输出结果:
[('I', 'O'), ('love', 'O'), ('natural', 'O'), ('language', 'O'), ('processing', 'O'), ('technology', 'O'), ('!', 'O')]
[('I', 'O'), ('love', 'O'), ('Beijing', 'CITY'), ('Tiananmen', 'LOCATION'), ('!', 'O')]
```
pip install pyhanlp 进行安装。pip install pyhanlp -i https://pypi.tuna.tsinghua.edu.cn/simple 进行安装。```python from pyhanlp import *
CRFnewSegment = HanLP.newSegment("crf")
termlist = CRFnewSegment.seg("我爱北京天安门!")
print(termlist)
输出结果:
[我/r, 爱/v, 北京/ns, 天安门/ns, !/w]
```
pip install nltk 进行安装。pip install nltk -i https://pypi.tuna.tsinghua.edu.cn/simple 进行安装。```python import nltk
s = 'I love natural language processing technology!' stoken = nltk.wordtokenize(s) stagged = nltk.postag(stoken) sner = nltk.chunk.nechunk(stagged) print(s_ner) ```
pip install spacy 进行安装。pip install spacy -i https://pypi.tuna.tsinghua.edu.cn/simple 进行安装。```python import spacy
eng_model = spacy.load('en') s = 'I want to Beijing learning natural language processing technology!'
sent = engmodel(s)
for ent in sent.ents:
print(ent, ent.label, ent.label)
输出结果:
Beijing GPE 382
```
希望以上内容对你有所帮助。