安装:pip install stanfordcorenlp
国内源安装:pip install stanfordcorenlp -i
https://pypi.tuna.tsinghua.edu.cn/simple
使用stanfordcorenlp进行命名实体类识别
from stanfordcorenlp import StanfordCoreNLP
zh_model = StanfordCoreNLP(r’D:\Anaconda\Scripts\NLP\stanford-corenlp-full-2018-10-05’, lang=‘zh’)
s_zh = ‘我爱自然语言处理技术!’
ner_zh = zh_model.ner(s_zh)
s_zh1 = ‘我喜欢中国!’
ner_zh1 = zh_model.ner(s_zh1)
print(ner_zh)
print(ner_zh1)
1
2
3
4
5
6
7
8
9
[(‘我爱’, ‘O’), (‘自然’, ‘O’), (‘语言’, ‘O’), (‘处理’, ‘O’), (‘技术’, ‘O’), (’!’, ‘O’)]
[(‘我’, ‘O’), (‘喜欢’, ‘O’), (‘中国’, ‘COUNTRY’), (’!’, ‘O’)]
from stanfordcorenlp import StanfordCoreNLP
eng_model = StanfordCoreNLP(r’D:\Anaconda\Scripts\NLP\stanford-corenlp-full-2018-10-05’,lang=‘en’)
s_eng = ‘I love natural language processing technology!’
ner_eng = eng_model.ner(s_eng)
s_eng1 = ‘I love Beijing Tiananmen!’
ner_eng1 = eng_model.ner(s_eng1)
print(ner_eng)
print(ner_eng1)
1
2
3
4
5
6
7
8
9
[(‘I’, ‘O’), (‘love’, ‘O’), (‘natural’, ‘O’), (‘language’, ‘O’), (‘processing’, ‘O’), (‘technology’, ‘O’), (’!’, ‘O’)]
[(‘I’, ‘O’), (‘love’, ‘O’), (‘Beijing’, ‘CITY’), (‘Tiananmen’, ‘LOCATION’), (’!’, ‘O’)]
————————————————
版权声明:本文为CSDN博主「Mr.Jk.Zhang」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/mrjkzhangma/article/details/92765048