Created
January 11, 2017 17:38
-
-
Save ugik/67d1f0582da3d854f9ce1739864b0b8b to your computer and use it in GitHub Desktop.
part 4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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