新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
創(chuàng)新互聯(lián)Python教程:Python如何使用Spacy進行分詞
說明

創(chuàng)新互聯(lián)2013年至今,是專業(yè)互聯(lián)網(wǎng)技術(shù)服務(wù)公司,擁有項目做網(wǎng)站、網(wǎng)站制作網(wǎng)站策劃,項目實施與項目整合能力。我們以讓每一個夢想脫穎而出為使命,1280元資陽做網(wǎng)站,已為上家服務(wù),為資陽各地企業(yè)和個人服務(wù),聯(lián)系電話:13518219792
1、Spacy語言模型包含一些強大的文本分析功能,如詞性標記和命名實體識別。
2、導(dǎo)入spacy相關(guān)模塊后,需要加載中文處理包。然后讀小說數(shù)據(jù),nlp處理天龍八部小說,包括分詞、定量、詞性標注、語法分析、命名實體識別,用符號/分隔小說。最后,通過is_stop函數(shù)判斷單詞中的單詞是否為無效單詞,刪除無效單詞后,將結(jié)果寫入txt文件。
實例
import spacy
import pandas as pd
import time
from spacy.lang.zh.stop_words import STOP_WORDS
nlp = spacy.load('zh_core_web_sm')
def fenci_stopwords(data,newdata1):
fenci = []
qc_stopwords =[]
article = pd.read_table(data,encoding="utf-8")
start1 = time.time()
with open(newdata1,'w',encoding='utf-8') as f1:
for i in article["天龍八部"]:#分詞
doc = nlp(i)
result1 = '/'.join([t.text for t in doc])
fenci.append(result1)
for j in fenci:#去除停用詞
words = nlp.vocab[j]
if words.is_stop == False:
qc_stopwords.append(j)
result2 = '/'.join(qc_stopwords)
f1.write(result2)
end1 = time.time()
return end1-start1以上就是python使用Spacy進行分詞的方法,希望對大家有所幫助。更多Python學(xué)習(xí)指路:創(chuàng)新互聯(lián)python教程
本文教程操作環(huán)境:windows7系統(tǒng)、Python 3.9.1,DELL G3電腦。
文章題目:創(chuàng)新互聯(lián)Python教程:Python如何使用Spacy進行分詞
標題鏈接:http://www.fisionsoft.com.cn/article/djiieij.html


咨詢
建站咨詢
