Sample Program Using Python 3
Sample Program Using Python 3
Sample Program Using Python 3
# This script gives you an idea how stemming has been placed by using NLTK library.
# It is part of morphological analysis
word = "unexpected"
text = "disagreement"
text1 = "disagree"
text2 = "agreement"
text3 = "quirkiness"
text4 = "historical"
text5 = "canonical"
text6 = "happiness"
text7 = "unkind"
text8 = "dogs"
text9 = "expected"
def stemmer_porter():
port = PorterStemmer()
print("\nDerivational Morphemes")
print (" ".join([port.stem(i) for i in text6.split()]))
print (" ".join([port.stem(i) for i in text7.split()]))
print ("\nInflectional Morphemes")
print (" ".join([port.stem(i) for i in text8.split()]))
print (" ".join([port.stem(i) for i in text9.split()]))
print ("\nSome examples")
print (" ".join([port.stem(i) for i in word.split()]))
print (" ".join([port.stem(i) for i in text.split()]))
print (" ".join([port.stem(i) for i in text1.split()]))
print (" ".join([port.stem(i) for i in text2.split()]))
print (" ".join([port.stem(i) for i in text3.split()]))
print (" ".join([port.stem(i) for i in text4.split()]))
print (" ".join([port.stem(i) for i in text5.split()]))
if __name__ == "__main__":
stemmer_porter()
# This script gives you an idea how tokenization and lemmatization has been placed by using NLTK.
# It is part of lexical analysis
from nltk.tokenize import word_tokenize
from nltk.stem.wordnet import WordNetLemmatizer
def wordtokenization():
content = """Stemming is funnier than a bummer says the sushi loving computer scientist.
She really wants to buy cars. She told me angrily. It is better for you.
Man is walking. We are meeting tomorrow. You really don't know..!"""
print (word_tokenize(content))
def wordlemmatization():
wordlemma = WordNetLemmatizer()
print (wordlemma.lemmatize('cars'))
print (wordlemma.lemmatize('walking',pos='v'))
print (wordlemma.lemmatize('meeting',pos='n'))
print (wordlemma.lemmatize('meeting',pos='v'))
print (wordlemma.lemmatize('better',pos='a'))
print (wordlemma.lemmatize('is',pos='v'))
print (wordlemma.lemmatize('funnier',pos='a'))
print (wordlemma.lemmatize('expected',pos='v'))
print (wordlemma.lemmatize('fantasized',pos='v'))
if __name__ =="__main__":
wordtokenization()
print ("\n")
print ("----------Word Lemmatization----------")
wordlemmatization()
if __name__ == "__main__":
print("\n--------Parsing result as per defined grammar-------")
definegrammar_pasrereult()
print("\n--------Drawing Parse Tree-------")
draw_parser_tree()