Skip to content
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
129 changes: 116 additions & 13 deletions your-code/challenge-1.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,58 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 21,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"[nltk_data] Downloading package punkt to\n",
"[nltk_data] C:\\Users\\joani\\AppData\\Roaming\\nltk_data...\n",
"[nltk_data] Package punkt is already up-to-date!\n",
"[nltk_data] Downloading package stopwords to\n",
"[nltk_data] C:\\Users\\joani\\AppData\\Roaming\\nltk_data...\n",
"[nltk_data] Unzipping corpora\\stopwords.zip.\n"
]
},
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 21,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import re \n",
"import nltk\n",
"from nltk.tokenize import word_tokenize\n",
"nltk.download('punkt')\n",
"from nltk.stem import WordNetLemmatizer\n",
"from nltk.corpus import stopwords\n",
"nltk.download('stopwords')"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'ironhack s q website is'"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"def clean_up(s):\n",
" \"\"\"\n",
Expand All @@ -79,7 +128,13 @@
"\n",
" Returns:\n",
" A string that has been cleaned up.\n",
" \"\"\""
" \"\"\"\n",
" string = re.sub(r'http\\S+', '', s)\n",
" return re.sub('[^A-Za-z]+', ' ', string).lower().strip()\n",
"test = \"@Ironhack's-#Q website 776-is http://ironhack.com [(2018)]\"\n",
" \n",
"test_string = clean_up(test)\n",
"test_string"
]
},
{
Expand All @@ -101,9 +156,20 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 15,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"['ironhack', 's', 'q', 'website', 'is']"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"def tokenize(s):\n",
" \"\"\"\n",
Expand All @@ -114,7 +180,11 @@
"\n",
" Returns:\n",
" A list of words as the result of tokenization.\n",
" \"\"\""
" \"\"\"\n",
" return nltk.word_tokenize(s)\n",
"\n",
"test_string = tokenize(test_string)\n",
"test_string"
]
},
{
Expand Down Expand Up @@ -145,9 +215,18 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 2,
"metadata": {},
"outputs": [],
"outputs": [
{
"ename": "SyntaxError",
"evalue": "invalid syntax (<ipython-input-2-90172a743b82>, line 21)",
"output_type": "error",
"traceback": [
"\u001b[1;36m File \u001b[1;32m\"<ipython-input-2-90172a743b82>\"\u001b[1;36m, line \u001b[1;32m21\u001b[0m\n\u001b[1;33m reTurn l\u001b[0m\n\u001b[1;37m ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid syntax\n"
]
}
],
"source": [
"def stem_and_lemmatize(l):\n",
" \"\"\"\n",
Expand All @@ -158,7 +237,18 @@
"\n",
" Returns:\n",
" A list of strings after being stemmed and lemmatized.\n",
" \"\"\""
" \"\"\"\n",
" ps = nltk.PorterStemmer()\n",
" lemmatizer = nltk.WordNetLemmatizer()\n",
" l = []\n",
" \n",
" for w in l:\n",
" s = ps.stem(w)\n",
" s = lemmatizer.lemmatize(s)\n",
" \n",
" l += [s]\n",
" \n",
"reTurn l"
]
},
{
Expand All @@ -176,9 +266,17 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 22,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"ironhack q website\n"
]
}
],
"source": [
"def remove_stopwords(l):\n",
" \"\"\"\n",
Expand All @@ -189,7 +287,12 @@
"\n",
" Returns:\n",
" A list of strings after stop words are removed.\n",
" \"\"\""
" \"\"\"\n",
" stop_words = stopwords.words('english')\n",
" \n",
" return ' '.join([w for w in l if w not in stop_words])\n",
"\n",
"print(remove_stopwords(test_string))"
]
},
{
Expand Down Expand Up @@ -218,7 +321,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.3"
"version": "3.9.6"
}
},
"nbformat": 4,
Expand Down
Loading