1. 程式人生 > >自然語言處理之命名實體識別-tanfordcorenlp-NER(一)

自然語言處理之命名實體識別-tanfordcorenlp-NER(一)

轉載請註明出處:https://blog.csdn.net/HHTNAN

簡介

CoreNLP 專案是Stanford開發的一套開源的NLP系統。包括tokenize, pos , parse 等功能,與SpaCy類似。SpaCy號稱是目前最快的NLP系統, 並且提供現成的python介面,但不足之處就是目前還不支援中文處理, CoreNLP則包含了中文模型,可以直接用於處理中文, 但CoreNLP使用Java開發,python呼叫稍微麻煩一點。

Stanford CoreNLP是一個比較厲害的自然語言處理工具,很多模型都是基於深度學習方法訓練得到的。

先附上其官網連結:

https://stanfordnlp.github.io/CoreNLP/index.html
https://nlp.stanford.edu/nlp/javadoc/javanlp/
https://github.com/stanfordnlp/CoreNLP

安裝Installation

windows 10 環境
安裝依賴
1.首先需要配置JDK,安裝JDK 1.8及以上版本。。
2.之後到 https://stanfordnlp.github.io/CoreNLP/history.html 下載對應的jar包。
將壓縮包解壓得到目錄,再將語言的jar包放到這個目錄下即可。
3.下載Stanford CoreNLP檔案:

http://stanfordnlp.github.io/CoreNLP/download.html
在這裡插入圖片描述
4.下載中文模型jar包(注意一定要下載這個檔案,否則它預設是按英文來處理的)。
在這裡插入圖片描述
5.接下來py安裝 stanfordcorenlp
在這裡插入圖片描述
6. 解壓配置
下載完成後兩個檔案加起來1G+下載完成後兩個檔案加起來1G+
在這裡插入圖片描述
把解壓後的Stanford CoreNLP資料夾下載的Stanford-chinese-corenlp-2018—models.jar放在同一目錄下(注意:一定要在同一目錄下,否則執行會報錯)
在這裡插入圖片描述
7. 在Python中引用模型,執行下面語句:

from stanfordcorenlp import StanfordCoreNLP
nlp=StanfordCoreNLP(r’D:\D:\stanford_nlp\stanford-corenlp-full-2018-10-05’,lang=‘zh’)

應用

#encoding="utf-8"
from stanfordcorenlp import StanfordCoreNLP
import os

if os.path.exists('D:\\stanford_nlp\\stanford-corenlp-full-2018-10-05'):
    print("corenlp exists")
else:
    print("corenlp not exists")
nlp=StanfordCoreNLP('D:\\stanford_nlp\\stanford-corenlp-full-2018-10-05',lang='zh')
sentence = '王明是清華大學的一個研究生'
print(nlp.ner(sentence))

輸出:
corenlp exists

[(‘王明’, ‘PERSON’), (‘是’, ‘O’), (‘清華’, ‘ORGANIZATION’), (‘大學’, ‘ORGANIZATION’), (‘的’, ‘O’), (‘一’, ‘NUMBER’), (‘個’, ‘O’), (‘研究生’, ‘O’)]

三、檢視詞性標註
在瀏覽器中訪問:http://localhost:9000/
在這裡插入圖片描述

轉載請註明出處:https://blog.csdn.net/HHTNAN