Skip to content

Instantly share code, notes, and snippets.

@ugik
Created January 11, 2017 17:38
Show Gist options
  • Save ugik/67d1f0582da3d854f9ce1739864b0b8b to your computer and use it in GitHub Desktop.
Save ugik/67d1f0582da3d854f9ce1739864b0b8b to your computer and use it in GitHub Desktop.
part 4
# calculate a score for a given class
def calculate_class_score(sentence, class_name, show_details=True):
score = 0
# tokenize each word in our new sentence
for word in nltk.word_tokenize(sentence):
# check to see if the stem of the word is in any of our classes
if stemmer.stem(word.lower()) in class_words[class_name]:
# treat each word with same weight
score += 1
if show_details:
print (" match: %s" % stemmer.stem(word.lower() ))
return score
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment