簡體   English   中英

如何檢查單詞在單詞數組中是否以復數形式而不是單數形式更常見(使用Python / NLTK)?

[英]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中標記和標記,但是如果您要使用自己的語料庫,則必須考慮以下幾點:

  • 使用哪個語料庫? 如何標記? 如何進行POS標記?
  • 你在數什么 類型或令牌?
  • 如何處理POS歧義? 如何區分名詞和非名詞?

最后,考慮一下:

  • 是否真的有辦法找出語言中的單詞是復數還是單數更常見? 還是會一直與您選擇分析的語料庫有關?
  • 在某些名詞中是否存在不存在復數或單數的情況? (很可能答案是肯定的)。

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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM