我对python和nltk非常陌生(我2小时前开始学习)。我要做的是:
Write a function GetAmbigousWords(corpus, N) that finds words in the corpus with more than N observed tags. This function should return a ConditionalFreqDist object where the conditions are the words and the frequency distribution indicates the tag frequencies for each word.
以下是我目前所做的:
def GetAmbiguousWords(corpus, number):
conditional_frequency = ConditionalFreqDist()
word_tag_dict = defaultdict(set) # Creates a dictionary of sets
for (word, tag) in corpus:
word_tag_dict[word].add(tag)
for taggedWord in word_tag_dict:
if ( len(word_tag_dict[taggedWord]) >= number ):
condition = taggedWord
conditional_frequency[condition] # do something, I don't know what to do
return conditional_frequency
例如,以下是函数的行为方式:
^{pr2}$我想知道我是在正确的轨道上还是完全偏离轨道?尤其是,我不太明白conditional frequency。在
提前谢谢。在
使用频率分布,可以收集文本中单词出现的频率:
这将导致:
^{pr2}$现在,一个条件频率基本上是相同的,但是你添加了一个条件,在这个条件下你可以对频率进行分组。E、 g.按字长分组:
这将打印:
希望有帮助。在
相关问题 更多 >
编程相关推荐