[英]How to check if a word is more common in its plural form rather than in it's singular form in an array of words (with Python/NLTK)?
我正在嘗試進行NLTK練習,但我無法做到這一點。 “哪些名詞以其復數形式而不是其單數形式更常見?(僅考慮以-s后綴組成的規則復數)。” 我花了一天的時間思考這個問題並嘗試嘗試,但是我還是做不到。 謝謝。
拿一個語料,做一個count_:
>>> from collections import Counter
>>> from nltk.corpus import brown
>>> texts = brown.words()[:10000]
>>> word_counts = Counter(texts)
>>> word_counts['dollar']
5
>>> word_counts['dollars']
15
但請注意,有時您不清楚何時僅使用表面弦進行計數,例如
>>> texts = brown.words()[:10000]
>>> word_counts = Counter(texts)
>>> word_counts['hits']
14
>>> word_counts['hit']
34
>>> word_counts['needs']
14
>>> word_counts['need']
30
POS敏感計數(請參閱類型與令牌):
>>> texts = brown.tagged_words()[:10000]
>>> word_counts = Counter(texts)
>>> word_counts[('need', 'NN')]
6
>>> word_counts[('needs', 'NNS')]
3
>>> word_counts[('hit', 'NN')]
0
>>> word_counts[('hits', 'NNS')]
0
讓我們進行逆向工程, brown
語料庫很好,它已在NLTK中標記和標記,但是如果您要使用自己的語料庫,則必須考慮以下幾點:
最后,考慮一下:
brw是一個單詞數組。
counter = Counter(brw);
plurals = [];
for word in brw:
if(word[-1]!='s'):
plural = counter[word+'s'];
singul = counter[word];
if(plural>singul):
plurals.append(word+'s');
復數是輸出數組,僅包含復數(重復,meh)。 如果我使用set(),它們將不會重復。 這是正確的嗎?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.