Playground checker
import re
def plagiarism_checker(text1, text2):
# Convert text to lowercase and remove punctuation
text1 = re.sub(r'[^\w\s]', '', text1.lower())
text2 = re.sub(r'[^\w\s]', '', text2.lower())
# Split text into words
words1 = text1.split()
words2 = text2.split()
# Calculate word frequency for each text
frequency1 = {}
for word in words1:
frequency1[word] = frequency1.get(word, 0) + 1
frequency2 = {}
for word in words2:
frequency2[word] = frequency2.get(word, 0) + 1
# Calculate similarity score
similarity_score = 0
for word in frequency1:
if word in frequency2:
similarity_score += frequency1[word] * frequency2[word]
return similarity_score
text1 = "This is some sample text."
text2 = "This is another sample text."
score = plagiarism_checker(text1, text2)
if score > 0:
print("Similarity score:", score)
else:
print("Texts are not similar.")
टिप्पणियाँ
एक टिप्पणी भेजें