从nltk或其他NLP库中的副词获取形容词 [英] Getting adjective from an adverb in nltk or other NLP library

查看:242
本文介绍了从nltk或其他NLP库中的副词获取形容词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法可以获取与NLTK或其他python库中给定副词相对应的形容词. 例如,对于副词"非常",我需要得到"非常". 谢谢.

Is there a way to get an adjective corresponding to a given adverb in NLTK or other python library. For example, for the adverb "terribly", I need to get "terrible". Thanks.

推荐答案

wordnet中存在一个关系,该关系将adjectivesadverbs连接,反之亦然.

There is a relation in wordnet that connects the adjectives to adverbs and vice versa.

>>> from itertools import chain
>>> from nltk.corpus import wordnet as wn
>>> from difflib import get_close_matches as gcm
>>> possible_adjectives = [k.name for k in chain(*[j.pertainyms() for j in chain(*[i.lemmas for i in wn.synsets('terribly')])])]
['terrible', 'atrocious', 'awful', 'rotten']
>>> gcm('terribly',possible_adjectives)
['terrible']

一种更易于理解的计算方式possible_adjective如下:

A more human readable way to computepossible_adjective is as followed:

possible_adj = []
for ss in wn.synsets('terribly'):
  for lemmas in ss.lemmas: # all possible lemmas.
    for lemma in lemmas: 
      for ps in lemma.pertainyms(): # all possible pertainyms.
        for p in ps:
          for ln in p.name: # all possible lemma names.
            possible_adj.append(ln)

在NLTK的较新版本中:

In the newer version of NLTK:

possible_adj = []
for ss in wn.synsets('terribly'):
  for lemmas in ss.lemmas(): # all possible lemmas
      for ps in lemmas.pertainyms(): # all possible pertainyms
          possible_adj.append(ps.name())

这篇关于从nltk或其他NLP库中的副词获取形容词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆