在python [更新]中找到与目标短语相关的形容词/动词的任何有效方法?

数据挖掘 Python nlp 情绪分析
2021-09-19 21:10:39

我正在对给定的文档进行情绪分析。我的目标是找出与我的句子中的目标短语最接近或周围的形容词我确实知道如何提取与目标短语相关的周围单词。但是我如何找到相对于目标短语相对接近或最接近的形容词或NNPVBN或其他词性标签?

这是关于我如何获得与目标短语相关的周围单词的草图想法。

sentence_List = {
    "Obviously one of the most important features of any computer is the human interface.", 
    "Good for everyday computing and web browsing.",
    "My problem was with DELL Customer Service", 
    "I play a lot of casual games online[comma] and the touchpad is very responsive"
}

target_phraseList = {
    "human interface",
    "everyday computing",
    "DELL Customer Service",
    "touchpad"
}

请注意,我的原始数据集是作为 DataFrame 给出的,其中给出了句子列表和相应的目标短语。这里我只是模拟数据如下:

import pandas as pd
df=pd.Series(sentence_List, target_phraseList)
df=pd.DataFrame(df)

在这里,我将句子标记如下:

from nltk.tokenize import word_tokenize
tokenized_sents = [word_tokenize(i) for i in sentence_List]
tokenized=[i for i in tokenized_sents]

然后我尝试通过使用这里的战利品来找出与我的目标短语相关的周围单词但是,我想找出相对更接近或最接近adjective的,或verbsVBN对于我的目标短语。

我怎样才能做到这一点?有什么想法可以完成吗?谢谢

1个回答

词性标注由附加词性的限定词组成。Part-Of-Speech 是一个标签,表示一个词在句子中的作用(例如,名词、及物动词、比较形容词等)。你需要这个来知道一个词是否是形容词,这很容易用你正在使用的nltk[source]完成:

>> nltk.pos_tag("The grand jury")
>> ('The', 'AT'), ('grand', 'JJ'), ('jury', 'NN')

在这里,JJ 表示“形容词”,“NN”表示“普通名词”。

就您而言,您对邻居形容词感兴趣。这是否意味着句子中的“最接近的形容词”?或者目标半径范围内的形容词,如果有的话?根据定义,执行此操作的方式有所不同。

对于半径范围内的形容词,由于您已经使用您提到的片段选择了半径范围内的单词,因此您可以对它们进行 POS 标记,然后仅选择带有表示形容词标记的标记的那些。

>> adjective_tags = ["JJ", "JJR", "JJS"]
>> close_adjectives_list = [a[0] for a in nltk.pos_tag(" ".join(close_words_list)) if a[1] in adjective_tags ]

您可以查看列出大多数现有 POS 标签的这个答案