*PLEASE ANSWER WITHOUT COPYING OTHER answers ANSWERS AS THEY ARE A
DIFFERENT QUESTION*
The current code i have is this but it is incorrect as the error
says: "
def pos(sentence): #11
"""stemms words apart from exceptions"""
stemmedSentence=''
words=sentence.split(" ")
vowels=['a','e','i','o','u','y']
vowelFound=False
stemmedWord=''
for word in words:
if '\'s' in word:
stemmedWord=word.replace('\'s',"")
elif 's\'' in word:
stemmedWord=word.replace('s\'',"")
else:
stemmedWord=word
if stemmedWord.endswith('s'):
if word[-2] not in
vowels:
for c in
word:
if c in vowels:
vowelFound=True
break
if
vowelFound:
if not word.endswith('us') or word.endswith('ss'):
if word.endswith('sses'):
stemmedWord=word.replace("sses","ss")
elif word.endswith('ies'):
stemmedWord=word.replace('ies','i')
if len(stemmedWord)<=2:
stemmedWord=word
elif word.endswith('ves'):
stemmedWord=word.replace('ves','f')
if len(stemmedWord)<=2:
stemmedWord=word.replace('ves','fe')
else:
stemmedWord=word.replace('s','')
else:
stemmedWord=word
else:
stemmedWord=word
elif word.endswith('ied'):
stemmedWord=word.replace("ied","i")
if
len(stemmedWord)<=2:
stemmedWord=word.replace("d","")
elif word.endswith('ed'):
stemmedWord=word.replace("ed","")
if word.endswith('ing'):
stemmedWord=word.replace("ing","")
if
len(stemmedWord)<3:
stemmedWord=word
if stemmedWord.endswith('ly'):
stemmedWord=stemmedWord.replace("ly","")
if stemmedWord.endswith('er'):
stemmedWord=stemmedWord.replace("er","")
stemmedSentence+=stemmedWord+" "
return stemmedSentence
. Stemming is a process of converting any given words to its root form (whatever that may be). There are many good stemmers out there, but here, we will write our own stemmer. Write a function pos (sentence) (no, it stands for pretty okay stemmer as titled) which takes an input parameter sentence (type string), and returns a string that stemmed all words from the given sentence. Each word should be stemmed as much as possible. The following stemming rules are implemented (list is quite long with exceptions, so take time to digest): Remove all ownerships • Singular ownerships (e.g, it's -> it) o Plural ownerships (e.g, theirs' -> their) • Remove plurals • Any words ending with 's' should remove it (e.g., gaps' -> 'gap', 'runs' -> "run") • Any words ending with a vowel after removing 's' are excepted (e.g., 'gas', 'this', 'has") Any words that has no vowels are excepted (e.g., 'CMPS, 'BTS") Any words ending with 'us' or 'ss' are excepted (e.g., 'census', 'chess") Any words ending with 'sses' should be converted to 'ss' (e.g., presses' -> 'press) • Any words ending with 'ies' should be converted to 'i' unless the length of the stemmed word is less than or equal to 2 (e.g., 'cries' -> 'cri', 'ties' -> 'tie') Any words ending with 'ves' should be removed and converted to 'f unless the length of the stemmed word is less than or equal to 2, in which case instead convert to 'fe' (e.g., "leaves' => 'leaf, 'wives' => 'wife") • Remove past tense Any words ending with 'ed' should remove it (e.g., "burned' -> 'burn', 'owned' -> 'own') Any words ending with 'ied' should be converted to i unless the length of the stemmed word is less than or equal to 2 (e.g., 'cried' -> 'cri', 'tied' => 'tie") Remove adjectives Any words ending with 'er' should remove it (e.g., "fuller' -> 'full', 'hanger' -> 'hang) • Remove verbs Any words ending with 'ing' should remove it (e.g., 'singing' -> 'sing', 'cutting' -> 'cuit') If the stemmed word length is less than 3 after removing 'ing, it should retain it (e.g., "bring') • Remove adverbs Any words ending with 'ly should remove it (e.g., 'greatly' -> 'great", "fully' -> 'ful") Note1: vowels contain lettery.
*PLEASE ANSWER WITHOUT COPYING OTHER answers ANSWERS AS THEY ARE A DIFFERENT QUESTION* The current code i have is this but
-
answerhappygod
- Site Admin
- Posts: 899604
- Joined: Mon Aug 02, 2021 8:13 am
*PLEASE ANSWER WITHOUT COPYING OTHER answers ANSWERS AS THEY ARE A DIFFERENT QUESTION* The current code i have is this but
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!