Skip to content

Phoenix 13 - Final Submission #27

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
Binary file added AIML Models/Anti-Plag/Assignment/Lorem.docx
Binary file not shown.
Binary file added AIML Models/Anti-Plag/Assignment/Sujal.docx
Binary file not shown.
Binary file added AIML Models/Anti-Plag/Assignment/temp/Sujal.docx
Binary file not shown.
155 changes: 155 additions & 0 deletions AIML Models/Anti-Plag/Plag_Check.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Intel(R) Extension for Scikit-learn* enabled (https://github.com/intel/scikit-learn-intelex)\n",
"[nltk_data] Downloading package stopwords to\n",
"[nltk_data] C:\\Users\\kulsh\\AppData\\Roaming\\nltk_data...\n",
"[nltk_data] Package stopwords is already up-to-date!\n"
]
},
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import string\n",
"import nltk\n",
"from nltk.corpus import stopwords\n",
"import sklearnex\n",
"from sklearnex import patch_sklearn\n",
"patch_sklearn() \n",
"from sklearn.feature_extraction.text import TfidfVectorizer\n",
"from sklearn.metrics.pairwise import cosine_similarity\n",
"from docx import Document\n",
"nltk.download('stopwords')"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"def preprocess_text(text):\n",
" # Remove punctuation and convert to lowercase\n",
" text = text.translate(str.maketrans(\"\", \"\", string.punctuation)).lower()\n",
" \n",
" # Remove stopwords\n",
" stop_words = set(stopwords.words('english'))\n",
" text = \" \".join(word for word in text.split() if word not in stop_words)\n",
" \n",
" return text"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"def extract_text_from_docx(file_path):\n",
" doc = Document(file_path)\n",
" paragraphs = [p.text for p in doc.paragraphs]\n",
" return '\\n'.join(paragraphs)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"def check_plagiarism(student_assignment_file, reference_assignment_files):\n",
" # Load student assignment\n",
" student_assignment = extract_text_from_docx(student_assignment_file)\n",
" processed_student = preprocess_text(student_assignment)\n",
" \n",
" similarities = []\n",
" \n",
" for ref_file in reference_assignment_files:\n",
" # Load reference assignment\n",
" reference_assignment = extract_text_from_docx('./Assignment/'+ref_file)\n",
" processed_ref = preprocess_text(reference_assignment)\n",
" \n",
" # Create TF-IDF vectors\n",
" vectorizer = TfidfVectorizer()\n",
" vectors = vectorizer.fit_transform([processed_student, processed_ref])\n",
" \n",
" # Calculate cosine similarity\n",
" similarity = cosine_similarity(vectors[0], vectors[1])[0][0]\n",
" similarities.append(similarity)\n",
" \n",
" return similarities"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"student_assignment_file = \"./Assignment/temp/Sujal.docx\"\n",
"reference_assignment_files = [doc for doc in os.listdir('./Assignment/') if doc.endswith('.doc') or doc.endswith('.docx')]"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Similarity with reference assignment 1: 0.1433594398627273\n",
"Similarity with reference assignment 2: 0.6140647534863115\n"
]
}
],
"source": [
"similarities = check_plagiarism(student_assignment_file, reference_assignment_files)\n",
"for i, similarity in enumerate(similarities):\n",
" print(f\"Similarity with reference assignment {i+1}: {similarity}\")"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "tf",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.16"
},
"orig_nbformat": 4
},
"nbformat": 4,
"nbformat_minor": 2
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading