def convert_postag(complex_word, candidates): specific_tag = NLP.pos_tag(complex_word)[0][1] generic_tag = get_type(specific_tag) # print(generic_tag) final_candidates = set() if generic_tag == "NN": ### Nouns # print(generic_tag) for candidate in candidates: candidate_tag = NLP.pos_tag(candidate)[0][1] if specific_tag == "NNS" and candidate_tag != "NNS": candidate = pluralize(candidate) # print("pluraaal ", candidate) elif specific_tag == "NN" and candidate_tag == "NNS": candidate = singularize(candidate) # print("singulaaar" , candidate) # print("wwilll add") final_candidates.add(candidate) elif generic_tag == "ADJ": ## Adjectives for candidate in candidates: candidate_tag = NLP.pos_tag(candidate)[0][1] if specific_tag == "JJR" and candidate_tag != "JJR": candidate = comparative(candidate) # print(candidate , "jjr") elif specific_tag == "JJS" and candidate_tag != "JJS": # print(candidate , "jjs") candidate = superlative(candidate) # print(candidate , "added") final_candidates.add(candidate) elif generic_tag == "VB": ## Verbs complex_tense = tenses(complex_word) if (len(complex_tense)) < 1: return candidates for candidate in candidates: # print("my tense" , complex_tense.upper() ," candidate " , candidate , " ", tenses(candidate)[0][0] ) if len(tenses(candidate)) > 0 and tenses( candidate)[0][0] != complex_tense: if complex_tense == "past": candidate = conjugate(candidate, tense=PAST) elif complex_tense == "present": candidate = conjugate(candidate, tense=PRESENT) elif complex_tense == "future": candidate = conjugate(candidate, tense=FUTURE) elif complex_tense == "infinitive": candidate = conjugate(candidate, tense=INFINITIVE) final_candidates.add(candidate) else: final_candidates = candidates return final_candidates
def write_hypo(parent, count, list_of_neighbors): return_dict = {} for index in range(0, len(list_of_neighbors)): s = wordnet.synsets(list_of_neighbors[index]) if len(s) > 0: s = s[0] synomyms = s.synonyms hypernyms = s.hypernyms() hyponyms = s.hyponyms() holonyms = s.holonyms() meronyms = s.meronyms() singulars = [singularize(list_of_neighbors[index])] plurals = [pluralize(list_of_neighbors[index])] comparatives = [comparative(list_of_neighbors[index])] superlatives = [superlative(list_of_neighbors[index])] lemmas = [lemma(list_of_neighbors[index])] lexemes = [lexeme(list_of_neighbors[index])] tensess = [tenses(list_of_neighbors[index])] suggests = [suggest(list_of_neighbors[index])] neighbors_with_link_string = None if parent in synomyms: neighbors_with_link_string = str( list_of_neighbors[index]) + "[SYNO]" elif parent in hypernyms: neighbors_with_link_string = str( list_of_neighbors[index]) + "[HYPER]" elif parent in hyponyms: neighbors_with_link_string = str( list_of_neighbors[index]) + "[HYPO]" elif parent in holonyms: neighbors_with_link_string = str( list_of_neighbors[index]) + "[HOLO]" elif parent in meronyms: neighbors_with_link_string = str( list_of_neighbors[index]) + "[MERO]" elif parent in singulars: neighbors_with_link_string = str( list_of_neighbors[index]) + "[PLURAL]" elif parent in plurals: neighbors_with_link_string = str( list_of_neighbors[index]) + "[SINGULAR]" elif parent in comparatives: neighbors_with_link_string = str( list_of_neighbors[index]) + "[COMPA]" elif parent in superlatives: neighbors_with_link_string = str( list_of_neighbors[index]) + "[SUPERLA]" elif parent in lemmas: neighbors_with_link_string = str( list_of_neighbors[index]) + "[LEMMA]" elif parent in lexemes: neighbors_with_link_string = str( list_of_neighbors[index]) + "[LEXEME]" elif parent in tensess: neighbors_with_link_string = str( list_of_neighbors[index]) + "[TENSE]" elif parent in suggests: neighbors_with_link_string = str( list_of_neighbors[index]) + "[MISPELL]" if neighbors_with_link_string: try: return_dict[word][1].append( neighbors_with_link_string) except: return_dict[word] = (count, [neighbors_with_link_string]) return return_dict
from pattern.text.en import conjugate, lemma, lexeme print(lemma('gave')) print(lexeme('gave')) from pattern.text.en import pluralize, singularize print(pluralize('leaf')) print(singularize('theives')) print(singularize('words')) from pattern.text.en import comparative, superlative print(comparative('good')) print(superlative('good')) from pattern.text.en import suggest print(suggest("Whitle")) print(suggest("white")) print(suggest("assid"))