相关疑难解决方法(0)

AttributeError:'FreqDist'对象没有属性'inc'

我是Python和NLTK的初学者.我试图从教程中运行以下代码:

from nltk.corpus import gutenberg
from nltk import FreqDist

fd = FreqDist()

for word in gutenberg.words('austen-sense.txt'):
    fd.inc(word)
Run Code Online (Sandbox Code Playgroud)

如果我运行这个我收到以下错误:

AttributeError: 'FreqDist' object has no attribute 'inc'
Run Code Online (Sandbox Code Playgroud)

知道我做错了什么吗?

python attributes nltk python-2.7

13
推荐指数
2
解决办法
8907
查看次数

如何在NLTK中获得synset的wordnet感知频率?

根据文档,我可以在nltk中加载有意义的标记语料库:

>>> from nltk.corpus import wordnet_ic
>>> brown_ic = wordnet_ic.ic('ic-brown.dat')
>>> semcor_ic = wordnet_ic.ic('ic-semcor.dat')
Run Code Online (Sandbox Code Playgroud)

我还可以得到definition,pos,offset,examples因为这样的:

>>> wn.synset('dog.n.01').examples
>>> wn.synset('dog.n.01').definition
Run Code Online (Sandbox Code Playgroud)

但是如何从语料库中获取synset的频率?打破这个问题:

  1. 首先如何计算多次synset发生一个有感觉标记的语料库?
  2. 然后,下一步是将计数除以给定特定引理的所有同义词出现的计数总数.

python nlp nltk wordnet wsd

5
推荐指数
1
解决办法
5210
查看次数

如何从输入查询中找到多义词?

我正在研究多义词消歧项目,为此我试图从输入查询中找到多义词。我这样做的方式是:

#! /usr/bin/python
from nltk.corpus import stopwords
from nltk.corpus import wordnet as wn
stop = stopwords.words('english')
print "enter input query"
string = raw_input()
str1 = [i for i in string.split() if i not in stop]
a = list()
for w in str1:
    if(len(wn.synsets(w)) > 1):
        a.append(w)
Run Code Online (Sandbox Code Playgroud)

这里的列表 a 将包含多义词。但是使用这种方法几乎所有的词都会被认为是多义词。例如,如果我的输入查询是“牛奶是白色的”,那么它将 ('milk','white','colour') 存储为多义词

python nlp nltk wordnet

0
推荐指数
1
解决办法
705
查看次数

标签 统计

nltk ×3

python ×3

nlp ×2

wordnet ×2

attributes ×1

python-2.7 ×1

wsd ×1