[
  {
    "path": "README.md",
    "content": "# Plagiarism-checker-Python\n\nThis repo consists of a source code of a Python script which detects plagiarism in a textual document using **cosine similarity**.\n\n[![Become a patron](pictures/become_a_patron_button.png)](https://www.patreon.com/kalebujordan)\n\n## How is it Done?\n\nYou might be wondering how plagiarism detection on textual data is done, well it ain't as complicated as you may think.\n\nWe all know that computers are good with numbers; so in order to compute the similarity between two text documents, the textual raw data is transformed into vectors => arrays of numbers and from that, we make use of basic knowledge of vectors to compute the similarity between them.\n\nThis repo contains a basic example on how to do that.\n\n\n## Getting Started\n\nTo get started with the code on this repo, you need to either *clone* or *download* this repo into your machine as shown below;\n\n```bash\ngit clone https://github.com/Kalebu/Plagiarism-checker-Python\n```\n\n## Dependencies\n\nBefore you begin playing with the source code, you might need to install dependencies just as shown below;\n\n```bash\npip3 install -r requirements.txt\n```\n\n## Running the App\n\nTo run this code you need to have your textual documents in your project directory with the **.txt** extension. When you run the script, it will automatically load all the documents with that extension and then compute the similarities between them as shown below;\n\n```bash\n$-> cd Plagiarism-checker-Python\n$ Plagiarism-checker-Python-> python3 app.py\n('john.txt', 'juma.txt', 0.5465972177348937)\n('fatma.txt', 'john.txt', 0.14806887549598566)\n('fatma.txt', 'juma.txt', 0.18643448370323362)\n\n```\n\n## A Python Library?\n\nWould you like to use a Python library instead to help you compare strings and documents without spending time writing the vectorizers by yourself, then take a look at [Pysimilar](https://github.com/Kalebu/pysimilar).\n\n## Explore it \n\nExplore it and twist it to your own use case. In case of any questions feel free to reach me directly at *isaackeinstein@gmail.com*.\n\n## Issues\n\nIn case you have any difficulties or issues while trying to run the script\nyou can raise an issue. \n\n## Pull Requests\n\nIf you have something to add, I welcome pull requests on improvement; your helpful contribution will be merged as soon as possible.\n\n## Give it a Star\n\nIf you find this repo useful, give it a star so that many people can get to know it.\n\n## Credits\n\nAll the credit goes to [kalebu](https://github.com/kalebu).\n"
  },
  {
    "path": "app.py",
    "content": "import os\nfrom sklearn.feature_extraction.text import TfidfVectorizer\nfrom sklearn.metrics.pairwise import cosine_similarity\n\nstudent_files = [doc for doc in os.listdir() if doc.endswith('.txt')]\nstudent_notes = [open(_file, encoding='utf-8').read()\n                 for _file in student_files]\n\n\ndef vectorize(Text): return TfidfVectorizer().fit_transform(Text).toarray()\ndef similarity(doc1, doc2): return cosine_similarity([doc1, doc2])\n\n\nvectors = vectorize(student_notes)\ns_vectors = list(zip(student_files, vectors))\nplagiarism_results = set()\n\n\ndef check_plagiarism():\n    global s_vectors\n    for student_a, text_vector_a in s_vectors:\n        new_vectors = s_vectors.copy()\n        current_index = new_vectors.index((student_a, text_vector_a))\n        del new_vectors[current_index]\n        for student_b, text_vector_b in new_vectors:\n            sim_score = similarity(text_vector_a, text_vector_b)[0][1]\n            student_pair = sorted((student_a, student_b))\n            score = (student_pair[0], student_pair[1], sim_score)\n            plagiarism_results.add(score)\n    return plagiarism_results\n\n\nfor data in check_plagiarism():\n    print(data)\n"
  },
  {
    "path": "fatma.txt",
    "content": "Life is all about doing your best in trying to\nfind what works out for you and taking most time in\ntrying to pursue those skills "
  },
  {
    "path": "john.txt",
    "content": "Life is all about finding money and spending on luxury stuffs\nCoz this life is kinda short , trust "
  },
  {
    "path": "juma.txt",
    "content": "Life to me is about finding money and use it on things that makes you happy\ncoz this life is kinda short "
  },
  {
    "path": "requirements.txt",
    "content": "scikit_learn==0.24.2\n"
  }
]