发现同义词 python_python – 使用WordNet查找同义词,定义和例句

我需要输入一个单词的输入文本文件.然后,我需要使用wordnet来查找词汇的同义词的定义和例子.我经历了这本书:“使用NLTK 2.0 Cookbook的

Python文本处理”以及“使用NLTK的自然语言处理”来帮助我.虽然我已经明白如何使用终端来完成这个工作,但我也不能用文本编辑器来做同样的事情.

例如,如果输入文本的字词“flabbergasted”,输出需要是这样的:

吓坏的

(动词)flabbergast,boggle,碗过度 – 惊奇地克服; “这困扰着头脑!”

(形容词)茫然,沮丧,颤抖,愚蠢,雷霆,浑浊,哑巴 – 仿佛惊讶和惊讶的笨蛋; “一个警察局因为否认这次事故而umb;一声”; “; asted的aldermen是无语的”; “被他的宣传消息吓倒了”

synSets,定义和例句从WordNet直接获得!

我有以下代码:

from __future__ import division

import nltk

from nltk.corpus import wordnet as wn

tokenizer = nltk.data.load('tokenizers/punkt/english.pickle')

fp = open("inpsyn.txt")

data = fp.read()

#to tokenize input text into sentences

print '\n-----\n'.join(tokenizer.tokenize(data))# splits text into sentences

#to tokenize the tokenized sentences into words

tokens = nltk.wordpunct_tokenize(data)

text = nltk.Text(tokens)

words = [w.lower() for w in text]

print words #to print the tokens

for a in words:

print a

syns = wn.synsets(a)

print "synsets:", syns

for s in syns:

for l in s.lemmas:

print l.name

print s.definition

print s.examples

我得到以下输出:

flabbergasted

['flabbergasted']

flabbergasted

synsets: [Synset('flabbergast.v.01'), Synset('dumbfounded.s.01')]

flabbergast

boggle

bowl_over

overcome with amazement

['This boggles the mind!']

dumbfounded

dumfounded

flabbergasted

stupefied

thunderstruck

dumbstruck

dumbstricken

as if struck dumb with astonishment and surprise

['a circle of policement stood dumbfounded by her denial of having seen the accident', 'the flabbergasted aldermen were speechless', 'was thunderstruck by the news of his promotion']

有没有一种方法来与词组名称一起检索词性?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值