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
159 changes: 147 additions & 12 deletions module-3/natural-language-processing/your-code/challenge-1.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,16 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import re "
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -79,7 +88,42 @@
"\n",
" Returns:\n",
" A string that has been cleaned up.\n",
" \"\"\""
" \"\"\"\n",
" \n",
" s_clean = re.sub(r'https?:\\/\\/.*[\\r\\n]*', '', s) # deleting the url\n",
" s_clean = re.sub(r'\\#|\\@|\\d|\\-|\\'|\\,|\\[|\\]', ' ', s_clean) # deleting special characters\n",
" \n",
" return s_clean.lower() #lowercase to ML"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [],
"source": [
"sentence = '''@Ironhack's-#Q website 776-is http://ironhack.com [(2018)]\")'''"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"' ironhack s q website is '"
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sentence_clean = clean_up(sentence)\n",
"sentence_clean"
]
},
{
Expand All @@ -101,7 +145,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -114,7 +158,32 @@
"\n",
" Returns:\n",
" A list of words as the result of tokenization.\n",
" \"\"\""
" \"\"\"\n",
" \n",
" s_list = re.split(r' ', s)\n",
" s_list_withiout_empty_strings = [s for s in s_list if s != '']\n",
" \n",
" return s_list_withiout_empty_strings"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"['ironhack', 's', 'q', 'website', 'is']"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"tokenize(sentence_clean)"
]
},
{
Expand Down Expand Up @@ -145,7 +214,27 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
"import nltk"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
"import nltk\n",
"from nltk.stem import WordNetLemmatizer\n",
"lemmatizer = WordNetLemmatizer()"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -158,7 +247,11 @@
"\n",
" Returns:\n",
" A list of strings after being stemmed and lemmatized.\n",
" \"\"\""
" \"\"\"\n",
" \n",
" lemmatize = [lemmatizer.lemmatize(t) for t in l]\n",
" \n",
" return lemmatize"
]
},
{
Expand All @@ -176,7 +269,16 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 10,
"metadata": {},
"outputs": [],
"source": [
"from nltk.corpus import stopwords"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -189,7 +291,40 @@
"\n",
" Returns:\n",
" A list of strings after stop words are removed.\n",
" \"\"\""
" \"\"\"\n",
" lemmatize = stem_and_lemmatize(l)\n",
" stop_words= [t for t in lemmatize if t not in stopwords.words('english')]\n",
" \n",
" return stop_words"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [],
"source": [
"list_words = ['I', 'saw', 'the', 'life', 'inside', 'your', 'eyes']"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"['I', 'saw', 'life', 'inside', 'eye']"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"remove_stopwords(list_words)"
]
},
{
Expand All @@ -204,9 +339,9 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python [conda env:ironhack_env]",
"language": "python",
"name": "python3"
"name": "conda-env-ironhack_env-py"
},
"language_info": {
"codemirror_mode": {
Expand All @@ -218,9 +353,9 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.3"
"version": "3.8.5"
}
},
"nbformat": 4,
"nbformat_minor": 2
"nbformat_minor": 4
}
Loading