gpt4 book ai didi

r - 如何使用sentimentr或qdap检测否定句

转载 作者:行者123 更新时间:2023-12-02 09:15:34 24 4
gpt4 key购买 nike

我正在尝试从包含否定的医疗报告中提取(并最终分类)句子。一个例子是这样的:

samples<-c('There is no evidence of a lump','Neither a contusion nor a scar was seen','No inflammation was evident','We found generalised badness here')

我正在尝试使用 sentimentr 包,因为它似乎能够检测否定者。有没有一种方法可以仅使用否定器的检测来提取否定句(最好将其提取到新的数据框中以进行进一步的工作)?

使用qdap中的极性只是给出一个汇总统计数据,并且基于包括我不想包括的放大器和去放大器。

polarity(samples,negators = qdapDictionaries::negation.words)

all total.sentences total.words ave.polarity sd.polarity stan.mean.polarity
1 all 4 24 0.213 0.254 0.842

我尝试了情感包如下:

extract_sentiment_terms(MyColonData$Endo_ResultText,polity_dt = lexicon::hash_sentiment_jockers, 连字符 = "")

这给了我中性、消极和积极的词:

   element_id sentence_id     negative positive
1: 1 1
2: 2 1 scar
3: 3 1 inflammation evident
4: 4 1 badness found

但我确实在寻找包含否定词的句子而不解释情绪,因此输出是:

element_id sentence_id                          negative                    positive
1: 1 1 There is no evidence of a lump
2: 2 1 Neither a contusion nor a scar was seen
3: 3 1 No inflammation was evident
4: 4 1 We found generalised badness here

最佳答案

我认为您只想根据否定符的存在对文本进行正面和负面分类,因此从词典中提取否定符应该会有所帮助。

samples<-c('There is no evidence of a lump','Neither a contusion nor a scar was seen','No inflammation was evident','We found generalised badness here')


polarity <- data.frame(text = samples, pol = NA)

polarity$pol <- ifelse(grepl(paste(lexicon::hash_valence_shifters[y==1]$x,collapse = '|'), tolower(samples)),'Negative','Positive')

polarity

text pol
1 There is no evidence of a lump Negative
2 Neither a contusion nor a scar was seen Negative
3 No inflammation was evident Negative
4 We found generalised badness here Positive

格式化OP:

reshape2::dcast(polarity,text~pol) 



text Negative Positive
1 Neither a contusion nor a scar was seen Negative <NA>
2 No inflammation was evident Negative <NA>
3 There is no evidence of a lump Negative <NA>
4 We found generalised badness here <NA> Positive

关于r - 如何使用sentimentr或qdap检测否定句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47531852/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com