Thursday, 22 August 2013

Capitalized First Letter Not Getting the Correct Answer

Capitalized First Letter Not Getting the Correct Answer

Stemming If you search for something in Google and use a word like
"running", Google is smart enough to match "run" or "runs" as well. That's
because search engines do what's called stemming before matching words.
In English, stemming involves removing common endings from words to
produce a base word. It's hard to come up with a complete set of rules
that work for all words, but this simplified set does a pretty good job:
If the word starts with a capital letter, output it without changes. If
the word ends in 's', 'ed', or 'ing' remove those letters, but if the
resulting stemmed word is only 1 or 2 letters long (e.g. chopping the ing
from sing), use the original word. Your program should read one word of
input and print out the corresponding stemmed word.
So i have made a program but when running it doesn't work if i capitalize
the first letter of the word so if you could rewrite this program so it
can work that would be very nice of you
word = input (" Enter the Word: ")
if word[0].isupper():
word2 = word
elif word.endswith("s"):
word2 = word[:-1]
elif word.endswith("ed"):
word2 = word[:-2]
elif word.endswith("ing"):
word2 = word[:-3]
if len(word2) <=2:
print (word)
else:
print(word2)

No comments:

Post a Comment