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

Upload Main class

parent 2130f133
import spacy
import string
from collections import Counter
from spacy.lang.en.stop_words import STOP_WORDS
from string import punctuation
nlp = spacy.load("en_core_web_sm")
# reading text file
text1 = open("student_answer.txt", encoding="utf-8").read()
text2 = open("teacher_answer.txt", encoding="utf-8").read()
# converting to lowercase
lower_case1 = text1.lower()
lower_case2 = text2.lower()
# Removing punctuations
cleaned_text1 = lower_case1.translate(str.maketrans('', '', string.punctuation))
cleaned_text2 = lower_case2.translate(str.maketrans('', '', string.punctuation))
# assigning a name
doc1 = nlp(cleaned_text1)
doc2 = nlp(cleaned_text2)
for sent in doc1.sents:
word_count = 0
print("Student's Answer: ")
print(sent.text)
for words in sent:
# print(words.text)
word_count = word_count + 1
print(f"\nWord count in the answer: {word_count}")
print("Identified keywords in the given answer:")
similar_word_list = []
for token in doc1:
if token.text == "integration" or token.text == "virtually" or token.text == "internal":
a = token.text
similar_word_list.append(a)
# print(f"\n** {a.upper()}")
print(similar_word_list)
w = Counter(similar_word_list)
print(w)
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