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
161 changes: 147 additions & 14 deletions your-code/challenge-1.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,43 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"'ironhack s q website is'\n"
]
},
{
"data": {
"text/plain": [
"'ironhack s q website is'"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# will change the last \" for a ', in order to change it back again later:\n",
"string_ironhack = \"@Ironhack's-#Q website 776-is http://ironhack.com [(2018)]')\"\n",
"\n",
"import re\n",
"\n",
"#Defining the function:\n",
"def clean_up(s):\n",
" s = s.lower()\n",
" result = re.sub(r\"(?<=is)(.*)(?= )\", \"\", s)\n",
" result1 = re.sub(r\"[0-9+]\", \"\", result)\n",
" result2 = re.sub(r\"[^A-Za-z0-9]\", \" \", result1)\n",
" result3 = re.sub(r\"[0-9]\", \" \", result2)\n",
" result4 = result3.lstrip()\n",
" result5 = result4.rstrip()\n",
" return result5\n",
" \"\"\"\n",
" Cleans up numbers, URLs, and special characters from a string.\n",
"\n",
Expand All @@ -79,9 +111,22 @@
"\n",
" Returns:\n",
" A string that has been cleaned up.\n",
" \"\"\""
" \"\"\"\n",
" \n",
"print(\"'ironhack s q website is'\")\n",
"clean_string = clean_up(string_ironhack)\n",
"clean_string\n",
"\n",
"#Done"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
Expand All @@ -101,11 +146,37 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"[nltk_data] Downloading package punkt to\n",
"[nltk_data] /Users/jossuebangos/nltk_data...\n",
"[nltk_data] Unzipping tokenizers/punkt.zip.\n"
]
},
{
"data": {
"text/plain": [
"['ironhack', 's', 'q', 'website', 'is']"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import nltk\n",
"nltk.download('punkt')\n",
"from nltk.tokenize import word_tokenize\n",
"def tokenize(s):\n",
" s = word_tokenize(s)\n",
" return s\n",
" \n",
" \"\"\"\n",
" Tokenize a string.\n",
"\n",
Expand All @@ -114,7 +185,9 @@
"\n",
" Returns:\n",
" A list of words as the result of tokenization.\n",
" \"\"\""
" \"\"\"\n",
"tokenized_str = tokenize(clean_string)\n",
"tokenized_str"
]
},
{
Expand Down Expand Up @@ -145,11 +218,43 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 4,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"[nltk_data] Downloading package wordnet to\n",
"[nltk_data] /Users/jossuebangos/nltk_data...\n",
"[nltk_data] Unzipping corpora/wordnet.zip.\n"
]
},
{
"data": {
"text/plain": [
"['ironhack', 's', 'q', 'websit', 'is']"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from nltk.stem import WordNetLemmatizer\n",
"from nltk.stem import PorterStemmer\n",
"nltk.download('wordnet')\n",
"def stem_and_lemmatize(l):\n",
" \n",
" #Initializing both methods:\n",
" ps = PorterStemmer() \n",
" lemmatizer = WordNetLemmatizer()\n",
" \n",
" stemmed = [ps.stem(word) for word in l]\n",
" stem_and_lemmat = [lemmatizer.lemmatize(word) for word in stemmed]\n",
" return stem_and_lemmat\n",
" #lemmatizer.lemmatize(stemmed)\n",
" \"\"\"\n",
" Perform stemming and lemmatization on a list of words.\n",
"\n",
Expand All @@ -158,7 +263,9 @@
"\n",
" Returns:\n",
" A list of strings after being stemmed and lemmatized.\n",
" \"\"\""
" \"\"\"\n",
"stem_and_lemmat = stem_and_lemmatize(tokenized_str)\n",
"stem_and_lemmat"
]
},
{
Expand All @@ -176,11 +283,36 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 5,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"[nltk_data] Downloading package stopwords to\n",
"[nltk_data] /Users/jossuebangos/nltk_data...\n",
"[nltk_data] Unzipping corpora/stopwords.zip.\n"
]
},
{
"data": {
"text/plain": [
"['ironhack', 'q', 'websit']"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from nltk.corpus import stopwords\n",
"nltk.download('stopwords')\n",
"\n",
"def remove_stopwords(l):\n",
" stop = stopwords.words('english')\n",
" return [word for word in l if word not in stop]\n",
" \"\"\"\n",
" Remove English stopwords from a list of strings.\n",
"\n",
Expand All @@ -189,7 +321,8 @@
"\n",
" Returns:\n",
" A list of strings after stop words are removed.\n",
" \"\"\""
" \"\"\"\n",
"remove_stopwords(stem_and_lemmat)"
]
},
{
Expand Down Expand Up @@ -218,9 +351,9 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.3"
"version": "3.8.3"
}
},
"nbformat": 4,
"nbformat_minor": 2
"nbformat_minor": 4
}
Loading