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
97 changes: 79 additions & 18 deletions lab-functional-programming/your-code/Q3.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 1,
"metadata": {},
"outputs": [
{
Expand All @@ -22,7 +22,7 @@
"[2, 12, 30]"
]
},
"execution_count": 11,
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -44,7 +44,7 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 2,
"metadata": {},
"outputs": [
{
Expand All @@ -53,7 +53,7 @@
"[2, 12, 30]"
]
},
"execution_count": 10,
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
Expand Down Expand Up @@ -85,13 +85,24 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[1, 4, 5]\n"
]
}
],
"source": [
"numbers = [1, 4, -1, -100, 0, 5, -99]\n",
"\n",
"# Enter your code below"
"# Enter your code below\n",
"\n",
"positive_numbers=list(filter(lambda x: x>0, numbers))\n",
"print(positive_numbers)"
]
},
{
Expand All @@ -113,15 +124,53 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 4,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Requirement already satisfied: langdetect in c:\\users\\monla\\anaconda3\\lib\\site-packages (1.0.9)\n",
"Requirement already satisfied: six in c:\\users\\monla\\anaconda3\\lib\\site-packages (from langdetect) (1.16.0)\n",
"Note: you may need to restart the kernel to use updated packages.\n"
]
}
],
"source": [
"import langdetect\n",
"pip install langdetect\n"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"['good morning', 'everyone']\n"
]
},
{
"data": {
"text/plain": [
"'good morning everyone'"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from langdetect import detect\n",
"from functools import reduce\n",
"words = ['good morning', '早上好', 'доброго', 'おはようございます', 'everyone', '大家', 'каждый', 'みんな']\n",
"\n",
"# Enter your code below"
"english_words=list(filter(lambda x: detect(x)=='en',words))\n",
"print(english_words)\n",
"' '.join(english_words)"
]
},
{
Expand All @@ -142,7 +191,7 @@
},
{
"cell_type": "code",
"execution_count": 80,
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -160,9 +209,21 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 7,
"metadata": {},
"outputs": [],
"outputs": [
{
"ename": "ImportError",
"evalue": "cannot import name 'stop_words' from 'sklearn.feature_extraction' (C:\\Users\\monla\\anaconda3\\lib\\site-packages\\sklearn\\feature_extraction\\__init__.py)",
"output_type": "error",
"traceback": [
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[1;31mImportError\u001b[0m Traceback (most recent call last)",
"Input \u001b[1;32mIn [7]\u001b[0m, in \u001b[0;36m<cell line: 1>\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01msklearn\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mfeature_extraction\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m stop_words\n\u001b[0;32m 2\u001b[0m bow \u001b[38;5;241m=\u001b[39m get_bow_from_docs([\n\u001b[0;32m 3\u001b[0m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124m../../lab-bag-of-words/your-code/doc1.txt\u001b[39m\u001b[38;5;124m'\u001b[39m, \n\u001b[0;32m 4\u001b[0m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124m../../lab-bag-of-words/your-code/doc2.txt\u001b[39m\u001b[38;5;124m'\u001b[39m, \n\u001b[0;32m 5\u001b[0m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124m../../lab-bag-of-words/your-code/doc3.txt\u001b[39m\u001b[38;5;124m'\u001b[39m],\n\u001b[0;32m 6\u001b[0m stop_words\u001b[38;5;241m.\u001b[39mENGLISH_STOP_WORDS\n\u001b[0;32m 7\u001b[0m )\n\u001b[0;32m 9\u001b[0m \u001b[38;5;28mprint\u001b[39m(bow)\n",
"\u001b[1;31mImportError\u001b[0m: cannot import name 'stop_words' from 'sklearn.feature_extraction' (C:\\Users\\monla\\anaconda3\\lib\\site-packages\\sklearn\\feature_extraction\\__init__.py)"
]
}
],
"source": [
"from sklearn.feature_extraction import stop_words\n",
"bow = get_bow_from_docs([\n",
Expand All @@ -185,7 +246,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -199,9 +260,9 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.6"
"version": "3.9.12"
}
},
"nbformat": 4,
"nbformat_minor": 2
"nbformat_minor": 4
}
Loading