put back plural exclusions
Browse files846 unmodified lines8478488498508518528532 unmodified lines8568578588598608613 unmodified lines865866867868869870871872873874846 unmodified linesplural_synsets = wordnet.synsets(word.rstrip('s'), pos=wordnet.NOUN)return len(plural_synsets) > len(singular_synsets)def is_plural(word):"""Determine if a word is plural using NLTK's part-of-speech tagging."""# Tokenize the input word (necessary for NLTK tagging)tokens = word_tokenize(word)2 unmodified lines# Check if the word is tagged as plural (NNS or NNPS in Penn Treebank tags)return pos in ["NNS", "NNPS"]def singular_to_plural(word):"""Convert singular words to plural using inflect."""plural = p.plural(word)3 unmodified lines"""Convert plural word to singular using inflect."""if is_plural(word):return p.singular_noun(word) or wordif is_plural_regex(word):return p.singular_noun(word) or wordif is_plural_wordnet(word):return p.singular_noun(word) or wordreturn wordplural_MATH_WORDS = [singular_to_plural(word) for word in MATH_WORDS]846 unmodified lines8478488498508518528532 unmodified lines8568578588598608618628638648658668673 unmodified lines871872873874875876846 unmodified linesplural_synsets = wordnet.synsets(word.rstrip('s'), pos=wordnet.NOUN)return len(plural_synsets) > len(singular_synsets)def is_plural_pos(word):"""Determine if a word is plural using NLTK's part-of-speech tagging."""# Tokenize the input word (necessary for NLTK tagging)tokens = word_tokenize(word)2 unmodified lines# Check if the word is tagged as plural (NNS or NNPS in Penn Treebank tags)return pos in ["NNS", "NNPS"]def is_plural(word):"""Check if a word is plural."""if word in PLURAL_TO_SINGULAR_EXCLUSIONS:return Falsereturn is_plural_regex(word) or is_plural_pos(word) or is_plural_wordnet(word)def singular_to_plural(word):"""Convert singular words to plural using inflect."""plural = p.plural(word)3 unmodified lines"""Convert plural word to singular using inflect."""if is_plural(word):return p.singular_noun(word) or wordreturn wordplural_MATH_WORDS = [singular_to_plural(word) for word in MATH_WORDS]
utils.py+7-5