通過(guò)百度云API接口抽取得到產(chǎn)品評(píng)論的觀(guān)點(diǎn),也掠去了很多評(píng)論中無(wú)用的內(nèi)容以及符號(hào),為后續(xù)進(jìn)行文本主題挖掘或者規(guī)則的提取提供基礎(chǔ)。
工具
1、百度云賬號(hào),申請(qǐng)應(yīng)用接口(自然語(yǔ)言處理)
2、python3.5
以下是百度接口提供的說(shuō)明:


我們使用到的可選值是13,kindle屬于3C產(chǎn)品。

下面是代碼示例:
from aip import AipNlpimport csvimport pandas as pdfrom pandas.core.frame import DataFrame""" 你的 APPID AK SK """APP_ID = '********'API_KEY = '********'SECRET_KEY = '********'client = AipNlp(APP_ID, API_KEY, SECRET_KEY)# 導(dǎo)入評(píng)論數(shù)據(jù)文件,并找到第13列(12行)的評(píng)論內(nèi)容提取出來(lái)def output(): urls = [] with open('E://tb_iphone8.csv', "r") as f:  reader = csv.reader(f)  for row in reader:   urls.append(row[12]) return urls# 通過(guò)百度云提供的API對(duì)評(píng)論觀(guān)點(diǎn)進(jìn)行提取def commentTag(): x = output() all={} abst='' for i in range(10560):  text=x[i]  """ 調(diào)用評(píng)論觀(guān)點(diǎn)抽取 """  """ 如果有可選參數(shù) """  # 可選參數(shù)為13表示利用了3C產(chǎn)品的語(yǔ)料庫(kù)  options = {}  options["type"] = 13  """ 帶參數(shù)調(diào)用評(píng)論觀(guān)點(diǎn)抽取 """  result=client.commentTag(text, options)  print(result)  if "error_code" in result.keys():   abst+=''   all['abstract'] = abst  else:   data = result['items']   items = data[0]   abst += items['abstract']   all['abstract'] = abst return abstif __name__ == '__main__': ALL=commentTag() print(ALL)得到的結(jié)果如下:

可以看到,現(xiàn)在抽取出來(lái)的評(píng)論部分內(nèi)容都是具有一定觀(guān)點(diǎn)傾向的,大部分沒(méi)有什么含義的評(píng)論內(nèi)容已經(jīng)被除去,這對(duì)后面的分析有一定的幫助。
以上這篇對(duì)python借助百度云API對(duì)評(píng)論進(jìn)行觀(guān)點(diǎn)抽取的方法詳解就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持武林站長(zhǎng)站。
| 
 
 | 
新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注