#NEWLINE# def lemmatize( ambiguous_word , pos = None , neverstem = False , lemmatizer = wnl , stemmer = porter ) : #NEWLINE# #INDENT# '\n    Tries to convert a surface word into lemma, and if lemmatize word is not in\n    wordnet then try and convert surface word into its stem.\n    \n    This is to handle the case where users input a surface word as an ambiguous \n    word and the surface word is a not a lemma.\n    ' #NEWLINE# if pos : #NEWLINE# #INDENT# lemma = lemmatizer . lemmatize ( ambiguous_word , pos = pos ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# lemma = lemmatizer . lemmatize ( ambiguous_word ) #NEWLINE# #UNINDENT# stem = stemmer . stem ( ambiguous_word ) #NEWLINE# if ( not wn . synsets ( lemma ) ) : #NEWLINE# #INDENT# if neverstem : #NEWLINE# #INDENT# return ambiguous_word #NEWLINE# #UNINDENT# if ( not wn . synsets ( stem ) ) : #NEWLINE# #INDENT# return ambiguous_word #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return stem #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# return lemma