栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

在动词/名词/形容词形式之间转换单词

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

在动词/名词/形容词形式之间转换单词

这是一种启发式方法。我刚刚对其进行了编码,以便为样式使用代码。它使用来自wordnet的derivationally_related_forms()。我已经实现名词化。我猜verbify工作类似。根据我的测试,效果很好:

from nltk.corpus import wordnet as wndef nounify(verb_word):    """ Transform a verb to the closest noun: die -> death """    verb_synsets = wn.synsets(verb_word, pos="v")    # Word not found    if not verb_synsets:        return []    # Get all verb lemmas of the word    verb_lemmas = [l for s in verb_synsets         for l in s.lemmas if s.name.split('.')[1] == 'v']    # Get related forms    derivationally_related_forms = [(l, l.derivationally_related_forms())    for l in    verb_lemmas]    # filter only the nouns    related_noun_lemmas = [l for drf in derivationally_related_forms      for l in drf[1] if l.synset.name.split('.')[1] == 'n']    # Extract the words from the lemmas    words = [l.name for l in related_noun_lemmas]    len_words = len(words)    # Build the result in the form of a list containing tuples (word, probability)    result = [(w, float(words.count(w))/len_words) for w in set(words)]    result.sort(key=lambda w: -w[1])    # return all the possibilities sorted by probability    return result


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/646635.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号