Commit 385e99a4 authored by Rathnayake R.M.Y.A.B's avatar Rathnayake R.M.Y.A.B

Upload Keyword comparing algorithm class

parent 621187b3
import spacy
import string
from spacy.lang.en.stop_words import STOP_WORDS
from string import punctuation
nlp = spacy.load("en_core_web_sm")
stopwords = list(STOP_WORDS)
punctuation = punctuation + '\n'
Topic = nlp("black")
text2 = open("student_answer.txt", encoding="utf-8").read()
lower_case2 = text2.lower()
cleaned_text2 = lower_case2.translate(str.maketrans('', '', string.punctuation))
Content = nlp(cleaned_text2)
Total_similarity = 0
for token1 in Content:
if token1.text.lower() not in stopwords:
if token1.text.lower() not in punctuation:
for token2 in Topic:
print((token1.text, token2.text), "similarity", token1.similarity(token2))
Total_similarity = Total_similarity + token1.similarity(token2)
if token1.similarity(token2) > 0.8:
print("Similar")
print(len(Content))
print(Total_similarity)
average_similarity = Total_similarity / len(Content)
print(average_similarity)
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment