Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 109 additions & 0 deletions Untitled.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [],
"source": [
"def corrector(a,b):\n",
" c=0\n",
" a=a.lower()\n",
" b=b.lower()\n",
" if a==b:\n",
" return 0\n",
" if(len(a)==len(b)):\n",
" for i in range(len(a)):\n",
" if(a[i]!=b[i]):\n",
" c+=1\n",
" if(c==1):\n",
" return 1\n",
" else:\n",
" return 2\n",
" \n",
" if(len(a)==len(b)+1):\n",
" if(b in a):\n",
" \n",
" return 1\n",
" else:\n",
" for i in range(len(a)):\n",
" if (b == a[:i]+a[i+1:]):\n",
" return 1\n",
" if(len(b)==len(a)+1):\n",
" if(a in b):\n",
" return 1\n",
" else:\n",
" for i in range(len(b)):\n",
" if (a == b[:i]+b[i+1:]):\n",
" return 1\n",
" \n",
" return 2"
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"this in the first car.programming in fun and easy.this in very easy.we love python."
]
}
],
"source": [
"\n",
"\n",
"\n",
"correct=[]\n",
"x=open(\"Original.txt\",\"r\")\n",
"xo=((x.readline()).lower()).split(\".\")\n",
"x1=[]\n",
"for i in range(len(xo)):\n",
" x1.append(xo[i].split())\n",
" \n",
"y=open(\"Correct_spelled.txt\",\"r\")\n",
"yo=((y.readline()).lower()).split(\",\")\n",
"y1=[]\n",
"for i in range(len(yo)):\n",
" y1.append(yo[i].strip())\n",
"\n",
"for k in range(len(x1)):\n",
" for i in range(len(x1[k])):\n",
" a=x1[k][i]\n",
" for j in range(len(y1)):\n",
" b=y1[j]\n",
" q=corrector(a,b) \n",
" if(q==1):\n",
" x1[k][i]=y1[j]\n",
" \n",
"for m in range(len(x1)):\n",
" print(' '.join(x1[m]),end=\".\")\n",
"\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"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.6.5"
}
},
"nbformat": 4,
"nbformat_minor": 2
}