0

我正在研究基于 stanford Coe NLP 的 NLP 项目。我得到了与每个文本/句子相对应的情绪——感谢这里的文档 现在我需要获取数据框列中每个文本的名词和相关形容词列表,那里我可以根据形容词的情绪对它们进行存储。我尝试了斯坦福网站,但没有找到任何示例函数/代码来实现这一点。我能得到帮助吗?TIA

对于我的 text_df 数据框,

with CoreNLPClient(annotators=['sentiment','tokenize','ssplit','pos','lemma','ner', 'depparse'], timeout=60000, memory='16G') as client:
    # submit the request to the server
    for ind in text_df.index:                                                                                    
        ann = client.annotate(text_df["text1"][ind])
        dp = sentence.basicDependencies
        token_dict = {sentence.token[i].tokenEndIndex- 
        offset:sentence.token[i].word for i in range(0, 
        len(sentence.token))}offset += len(sentence.token)

        out_parse = [(dp.edge[i].source, dp.edge[i].target,dp.edge[i].dep,) 
        for i in range(0, len(dp.edge))]
            for source, target,dep in out_parse:
                print(dep, token_dict[source], token_dict[target])
                text_df1['dep'][j]=dep
                text_df1['source'][j]=token_dict[source]
                text_df1['target'][j]=token_dict[target]
                text_df1['Sent_id'][j]=text_sentences
                j=j+1
            for token in sentence.token:
                text_df2['target'][h]=token.word
                text_df2['pos'][h]=token.pos
                text_df2['Sent_id'][h]=text_sentences
                h=h+1 

此代码基本上在一个数据帧(text_df1)中创建具有依赖解析器(dep)、源和目标令牌的数据帧,并在另一个数据帧中创建具有 POS 值(text_df2)的每个令牌。我的要求是用名词和相关形容词在句子中获取每个标记/单词。最后,我将这两个表结合起来,得到了所需的数据框。但我现在的问题是,我有句子“raj 去办公室,他的办公室很远”我看到下面给出的 text_df1:nsubj 去了 raj nmod 去办公室 dep 去是案例办公室到 cc 办公室和 conj 办公室办公室 nmod :poss office 他的 advmod 远 advmod 远非常

理想情况下,我应该看到一个带有 nsubj(far,office) 的依赖解析器,但我错过了这个特定的值,有什么时候可以帮我找出我错过的地方..?

当我检查http://nlp.stanford.edu:8080/parser/index.jsp时,我也看到了同样的句子 nsubj(far,office) ..

我想我需要编写 python 代码来在他们的网站上生成“通用依赖,增强”。任何人都可以帮忙吗

4

0 回答 0