Checking Plagiarism

Now, after performing all the tasks , we start with implementing the plagiarism checking function that will help us calculate the plagiarism.

Python3




# Function to check for plagiarism
def find_plagiarism():
    # Initialize an empty set to store plagiarism results
    plagiarism_results = set()
  
    # Access the global variable doc_filename_pairs
    global doc_filename_pairs
  
    # Iterate through each student's file and vector
    for student_a_file, student_a_vec in doc_filename_pairs:
        # Create a copy of the document-filename pairs for iteration
        remaining_pairs = doc_filename_pairs.copy()
  
        # Find the index of the current document-filename pair
        current_index = remaining_pairs.index((student_a_file, student_a_vec))
  
        # Remove the current pair from the remaining pairs
        del remaining_pairs[current_index]
  
        # Iterate through the remaining pairs to compare with other students
        for student_b_file, student_b_vec in remaining_pairs:
            # Calculate the cosine similarity between student_a_vec and student_b_vec
            similarity_score = calc_cosine_similarity(
                student_a_vec, student_b_vec)[0][1]
  
            # Sort the filenames to maintain consistency in results
            sorted_filenames = sorted((student_a_file, student_b_file))
  
            # Create a plagiarism result tuple with sorted filenames and similarity score
            plagiarism_result = (
                sorted_filenames[0], sorted_filenames[1], similarity_score)
  
            # Add the result to the plagiarism_results set
            plagiarism_results.add(plagiarism_result)
  
    # Return the set of plagiarism results
    return plagiarism_results
  
  
# Print plagiarism results
plagiarism_results = find_plagiarism()
for result in plagiarism_results:
    print(result)


Output:

('fatma.txt', 'juma.txt', 0.22010931810615814)
('john.txt', 'juma.txt', 0.9999999999999998)
('fatma.txt', 'john.txt', 0.22010931810615814)

In the above code, it defines a function ‘find_plagiarism’ to check the plagiarism among the collection of the student documents. It iterates through pairs of student documents, calculating cosine similarity between each pair. It ensures that each document is compared to others only once. The results are stored in a set, ‘plagiarism_results’ , as tuples containing the filenames of similar documents and their cosine similarity scores. Finally, it prints the plagiarism results, identifying the potentially plagiarized documents.

Plagiarism Detection using Python

In this article, we are going to learn how to check plagiarism using Python.

Plagiarism: Plagiarism basically refers to cheating. It means stealing someone’s else work, ideas, or information from the resources without providing the necessary credits to the author. For example, copying text from different resources from word to word without mentioning any quotation marks.

Table of Content

  • What is Plagiarism detection?
  • Importing Libraries
  • Listing and Reading Files
  • TF-IDF Vectorization
  • Calculating Cosine Similarity
  • Creating Document-vector Pairs
  • Checking Plagiarism
  • Word Cloud Visualization
  • Conclusion

Similar Reads

What is Plagiarism detection?

...

Importing Libraries

The crucial procedure of detecting plagiarism aims to identify situations in which someone has directly copied or closely resembled the work the work of others without giving due credit. In order to assess a text’s originality, it must be compared to a variety of previously published works. In order to uphold uniqueness in creative works, maintain academic integrity, and ensure the reliability of research and information, plagiarism must be found. In this article, we’ll look at how to use Python to construct an automated program to find instances of plagiarism so that we can quickly find and deal with them....

Listing and Reading Files

With just one line of code, Python libraries make it exceedingly simple for us to manage the data and finish both straightforward and challenging tasks....

TF-IDF Vectorization

...

Calculating Cosine Similarity

Let’s now prepare the document data and read the context in the data....

Creating Document-vector Pairs

...

Checking Plagiarism

TF-IDF (Term Frequency-Inverse Document Frequency) is a metric that quantifies the value of a term in a document in relation to a group of documents and is used in natural language processing. It is frequently employed in text mining, information retrieval, and text analysis....

Word Cloud Visualization

...

Conclusion

Cosine Similarity is a metric that assesses how similar two non-zero vectors are to one another in an n-dimensional space. It is frequently used in text analysis to compare the vector representations of two documents to ascertain how similar they are....

Contact Us