第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

在 Python 中進(jìn)行基于方面的情感分析時(shí)需要有關(guān)否定處理的建議

在 Python 中進(jìn)行基于方面的情感分析時(shí)需要有關(guān)否定處理的建議

精慕HU 2024-01-24 20:47:33
我正在嘗試編寫一個(gè) Python 代碼,使用依賴解析器對(duì)產(chǎn)品評(píng)論進(jìn)行基于方面的情感分析。我創(chuàng)建了一個(gè)示例評(píng)論:“音質(zhì)很好,但電池壽命很差?!陛敵鰹椋篬['soundquality', ['great']], ['batterylife', ['bad']]]我可以正確地得到這句話的方面和形容詞,但是當(dāng)我將文本更改為:“音質(zhì)不是很好,但電池壽命還不錯(cuò)?!陛敵鋈匀槐3植蛔?。如何向我的代碼添加否定處理?有什么方法可以改善我目前所擁有的嗎?
查看完整描述

1 回答

?
翻閱古今

TA貢獻(xiàn)1780條經(jīng)驗(yàn) 獲得超5個(gè)贊

您不妨嘗試一下spacy。以下模式將捕獲:

  • 名詞短語

  • 后跟isare

  • 可選地跟隨not

  • 后面跟著一個(gè)形容詞

import spacy

from spacy.matcher import Matcher

nlp = spacy.load('en_core_web_sm')


output = []

doc = nlp('The product is very good')

matcher = Matcher(nlp.vocab)

matcher.add("mood",None,[{"LOWER":{"IN":["is","are"]}},{"LOWER":{"IN":["no","not"]},"OP":"?"},{"LOWER":"very","OP":"?"},{"POS":"ADJ"}])

for nc in doc.noun_chunks:

    d = doc[nc.root.right_edge.i+1:nc.root.right_edge.i+1+3]

    matches = matcher(d)

    if matches:

        _, start, end = matches[0]

        output.append((nc.text, d[start+1:end].text))

    

print(output)

[('The product', 'very good')]

或者,您可以使用依賴解析器中的信息來擴(kuò)展匹配模式,這將添加形容詞短語的定義:


output = []

matcher = Matcher(nlp.vocab, validate=True)

matcher.add("mood",None,[{"LOWER":{"IN":["is","are"]}},{"LOWER":{"IN":["no","not"]},"OP":"?"},{"DEP":"advmod","OP":"?"},{"DEP":"acomp"}])

for nc in doc.noun_chunks:

    d = doc[nc.root.right_edge.i+1:nc.root.right_edge.i+1+3]

    matches = matcher(d)

    if matches:

        _, start, end = matches[0]

        output.append((nc.text, d[start+1:end].text))

    

print(output)

[('The product', 'very good')]


查看完整回答
反對(duì) 回復(fù) 2024-01-24
  • 1 回答
  • 0 關(guān)注
  • 181 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)