From Import From Import From Import From Import Import
From Import From Import From Import From Import Import
# str1 = "Ballmer has been vocal in the past warning that Linux
is a threat to Microsoft."
# str2 = "In the memo, Ballmer reiterated the open-source threat
to Microsoft."
# str1 = "The boy is fetching water from the well."
# str2 = "The lion is running in the forest."
# str1 = "A school is a place where kids go to study."
# str2 = "School is an institution for children who want to
study."
# str1 = "The world knows it has lost a heroic champion of
justice and freedom."
# str2 = "The earth recognizes the loss of a valiant champion of
independence and justice."
# str1 = "A cemetery is a place where dead people's bodies or
their ashes are buried."
# str2 = "A graveyard is an area of land ,sometimes near a
church, where dead people are buried."
##---------------Initialising ---------------##
filtered_sentence1 = []
filtered_sentence2 = []
lemm_sentence1 = []
lemm_sentence2 = []
sims = []
temp1 = []
temp2 = []
simi = []
final = []
same_sent1 = []
same_sent2 = []
##---------------WordNet Lematizer---------------##
lemmatizer = WordNetLemmatizer()
##---------------Lemmatizing s1---------------##
for i in filtered_sentence1:
lemm_sentence1.append(lemmatizer.lemmatize(i))
print(lemm_sentence1)
##---------------Lemmatizing s2 ---------------##
for i in filtered_sentence2:
lemm_sentence2.append(lemmatizer.lemmatize(i))
print(lemm_sentence2)
print(sims)
#print(max(sims))
if sims != []:
max_sim = max(sims)
print(max_sim)
simi.append(max_sim)
if simi != []:
max_final = max(simi)
final.append(max_final)
##--------------- classification-Output---------------##
similarity_index = numpy.mean(final)
similarity_index = round(similarity_index , 2)
print("Sentence 1: ",str1)
print("Sentence 2: ",str2)
print("Similarity index value : ", similarity_index)
if similarity_index>0.8:
print("Similar")
elif similarity_index>=0.6:
print("Somewhat Similar")
else:
print("Not Similar")