Python
(파이썬) 표절 검사 프로그램 Plagiarism check program
enjoy-country-life
2024. 1. 22. 14:14
반응형
하단에 표절검사를 하는 C언어 코드가 있으니 참고하십시오.
여기서 만들 표절 검사 프로그램은 텍스트 문서를 비교하여 유사점을 식별 합니다. 다음은 Levenshtein 거리 알고리즘을 사용하여 두 텍스트 사이의 유사성을 측정하는 Python의 간단한 예입니다.
def levenshtein_distance(s1, s2):
if len(s1) < len(s2):
return levenshtein_distance(s2, s1)
if len(s2) == 0:
return len(s1)
previous_row = range(len(s2) + 1)
for i, c1 in enumerate(s1):
current_row = [i + 1]
for j, c2 in enumerate(s2):
insertions = previous_row[j + 1] + 1
deletions = current_row[j] + 1
substitutions = previous_row[j] + (c1 != c2)
current_row.append(min(insertions, deletions, substitutions))
previous_row = current_row
return previous_row[-1]
def similarity_percentage(s1, s2):
distance = levenshtein_distance(s1, s2)
max_length = max(len(s1), len(s2))
return 100 * (1 - distance / max_length)
def check_plagiarism(text1, text2, threshold=70):
similarity = similarity_percentage(text1, text2)
if similarity >= threshold:
return True, similarity
else:
return False, similarity
# Example usage
document1 = "This is a sample text for testing plagiarism."
document2 = "This is a sample text for testing."
is_plagiarized, similarity_percent = check_plagiarism(document1, document2)
if is_plagiarized:
print(f"Plagiarism detected! Similarity: {similarity_percent:.2f}%")
else:
print("No plagiarism detected.")
(Output)
Plagiarism detected! Similarity: 75.56%
C언어 코드:
https://gonyzany.tistory.com/676
반응형