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
130 changes: 86 additions & 44 deletions your-code/main.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 14,
"metadata": {},
"outputs": [],
"source": [
"# import reduce from functools, numpy and pandas\n"
"import numpy as np\n",
"import regex as re\n",
"import pandas as pd\n",
"from functools import reduce "
]
},
{
Expand All @@ -32,12 +35,10 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"# Run this code:\n",
"\n",
"location = '../58585-0.txt'\n",
"with open(location, 'r', encoding=\"utf8\") as f:\n",
" prophet = f.read().split(' ')"
Expand All @@ -54,11 +55,11 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"# Your code here:\n"
"prophet=prophet[568:]"
]
},
{
Expand All @@ -70,11 +71,22 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 7,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"['the{7}', 'chosen', 'and', 'the\\nbeloved,', 'who', 'was', 'a', 'dawn', 'unto']"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Your code here:\n"
"prophet[1:10]"
]
},
{
Expand All @@ -88,7 +100,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 25,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -101,9 +113,8 @@
" Input: 'the{7}'\n",
" Output: 'the'\n",
" '''\n",
" \n",
" # Your code here:\n",
" "
" rule='{.*'\n",
" return re.sub(rule,'',x)"
]
},
{
Expand All @@ -115,11 +126,11 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 29,
"metadata": {},
"outputs": [],
"source": [
"# Your code here:\n"
"prophet_reference=list(map(reference,prophet))"
]
},
{
Expand All @@ -131,9 +142,20 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 30,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"['the', 'beloved']"
]
},
"execution_count": 30,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"def line_break(x):\n",
" '''\n",
Expand All @@ -144,8 +166,7 @@
" Input: 'the\\nbeloved'\n",
" Output: ['the', 'beloved']\n",
" '''\n",
" \n",
" # Your code here:\n"
" return x.split('\\n')"
]
},
{
Expand All @@ -157,11 +178,11 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 32,
"metadata": {},
"outputs": [],
"source": [
"# Your code here:\n"
"prophet_line=list(map(line_break,prophet_reference))"
]
},
{
Expand All @@ -173,11 +194,11 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 52,
"metadata": {},
"outputs": [],
"source": [
"# Your code here:\n"
"prophet_flat=[x[0] for x in prophet_line]"
]
},
{
Expand All @@ -191,9 +212,20 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 55,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"False"
]
},
"execution_count": 55,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"def word_filter(x):\n",
" '''\n",
Expand All @@ -208,24 +240,29 @@
" Input: 'John'\n",
" Output: True\n",
" '''\n",
" word_list = ['and', 'the']\n",
" \n",
" word_list = []\n",
" \n",
" # Your code here:\n"
" if x not in word_list:\n",
" return True\n",
" else:\n",
" return False\n",
" "
]
},
{
"cell_type": "code",
"execution_count": null,
"cell_type": "markdown",
"metadata": {},
"outputs": [],
"source": []
"source": [
"Use the `filter()` function to filter out the words speficied in the `word_filter()` function. Store the filtered list in the variable `prophet_filter`."
]
},
{
"cell_type": "markdown",
"cell_type": "code",
"execution_count": 46,
"metadata": {},
"outputs": [],
"source": [
"Use the `filter()` function to filter out the words speficied in the `word_filter()` function. Store the filtered list in the variable `prophet_filter`."
"prophet_filter = list(filter(word_filter,prophet_flat))"
]
},
{
Expand All @@ -239,7 +276,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 64,
"metadata": {
"scrolled": true
},
Expand All @@ -248,8 +285,14 @@
"\n",
"def word_filter_case(x):\n",
" \n",
" \n",
" # Your code here:\n"
" word_list = ['And', 'the']\n",
" \n",
" word_list=[x.lower() for x in word_list]\n",
" \n",
" if x.lower() not in word_list:\n",
" return True\n",
" else:\n",
" return False"
]
},
{
Expand All @@ -265,7 +308,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 67,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -278,8 +321,7 @@
" Input: 'John', 'Smith'\n",
" Output: 'John Smith'\n",
" '''\n",
" \n",
" # Your code here:\n"
" return a + ' ' + b"
]
},
{
Expand All @@ -291,11 +333,11 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 68,
"metadata": {},
"outputs": [],
"source": [
"# Your code here:\n"
"prophet_string=reduce(concat_space,prophet_filter)"
]
}
],
Expand All @@ -315,7 +357,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.3"
"version": "3.8.3"
}
},
"nbformat": 4,
Expand Down