thesis-prediction-ml/fetchDatafromDb/NLTKdependency.ipynb
2023-06-22 00:12:27 +00:00

118 lines
7.6 KiB
Text

{
"cells": [
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Collecting nltk\n",
" Downloading nltk-3.8.1-py3-none-any.whl (1.5 MB)\n",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1.5/1.5 MB\u001b[0m \u001b[31m1.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m00:01\u001b[0m00:01\u001b[0m0m\n",
"\u001b[?25hCollecting click\n",
" Downloading click-8.1.3-py3-none-any.whl (96 kB)\n",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m96.6/96.6 kB\u001b[0m \u001b[31m787.1 kB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m \u001b[36m0:00:01\u001b[0m\n",
"\u001b[?25hRequirement already satisfied: joblib in /home/shoney/dev/.venv/lib/python3.10/site-packages (from nltk) (1.2.0)\n",
"Collecting regex>=2021.8.3\n",
" Downloading regex-2023.6.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (770 kB)\n",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m770.4/770.4 kB\u001b[0m \u001b[31m1.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m00:01\u001b[0m00:01\u001b[0m\n",
"\u001b[?25hCollecting tqdm\n",
" Downloading tqdm-4.65.0-py3-none-any.whl (77 kB)\n",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m77.1/77.1 kB\u001b[0m \u001b[31m779.0 kB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m \u001b[36m0:00:01\u001b[0m\n",
"\u001b[?25hInstalling collected packages: tqdm, regex, click, nltk\n",
"Successfully installed click-8.1.3 nltk-3.8.1 regex-2023.6.3 tqdm-4.65.0\n",
"\n",
"\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m A new release of pip is available: \u001b[0m\u001b[31;49m23.0.1\u001b[0m\u001b[39;49m -> \u001b[0m\u001b[32;49m23.1.2\u001b[0m\n",
"\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m To update, run: \u001b[0m\u001b[32;49mpip install --upgrade pip\u001b[0m\n"
]
}
],
"source": [
"!python -m pip install nltk"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"from nltk.grammar import DependencyGrammar"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"from nltk.parse import (\n",
"DependencyGraph,\n",
"ProjectiveDependencyParser,\n",
"NonprojectiveDependencyParser,\n",
" )"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"ename": "ValueError",
"evalue": "Number of tab-delimited fields (5) not supported by CoNLL(10) or Malt-Tab(4) format",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mKeyError\u001b[0m Traceback (most recent call last)",
"File \u001b[0;32m~/dev/.venv/lib/python3.10/site-packages/nltk/parse/dependencygraph.py:329\u001b[0m, in \u001b[0;36mDependencyGraph._parse\u001b[0;34m(self, input_, cell_extractor, zero_based, cell_separator, top_relation_label)\u001b[0m\n\u001b[1;32m 328\u001b[0m \u001b[39mtry\u001b[39;00m:\n\u001b[0;32m--> 329\u001b[0m cell_extractor \u001b[39m=\u001b[39m extractors[cell_number]\n\u001b[1;32m 330\u001b[0m \u001b[39mexcept\u001b[39;00m \u001b[39mKeyError\u001b[39;00m \u001b[39mas\u001b[39;00m e:\n",
"\u001b[0;31mKeyError\u001b[0m: 5",
"\nThe above exception was the direct cause of the following exception:\n",
"\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[0;32mIn[6], line 2\u001b[0m\n\u001b[1;32m 1\u001b[0m treebank_data \u001b[39m=\u001b[39m\u001b[39m\"\"\"\u001b[39m\u001b[39mvaico v10 4245 shock absorber\u001b[39m\u001b[39m\"\"\"\u001b[39m\n\u001b[0;32m----> 2\u001b[0m dg \u001b[39m=\u001b[39m DependencyGraph(treebank_data)\n\u001b[1;32m 3\u001b[0m dg\u001b[39m.\u001b[39mtree()\u001b[39m.\u001b[39mpprint()\n",
"File \u001b[0;32m~/dev/.venv/lib/python3.10/site-packages/nltk/parse/dependencygraph.py:79\u001b[0m, in \u001b[0;36mDependencyGraph.__init__\u001b[0;34m(self, tree_str, cell_extractor, zero_based, cell_separator, top_relation_label)\u001b[0m\n\u001b[1;32m 76\u001b[0m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mroot \u001b[39m=\u001b[39m \u001b[39mNone\u001b[39;00m\n\u001b[1;32m 78\u001b[0m \u001b[39mif\u001b[39;00m tree_str:\n\u001b[0;32m---> 79\u001b[0m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49m_parse(\n\u001b[1;32m 80\u001b[0m tree_str,\n\u001b[1;32m 81\u001b[0m cell_extractor\u001b[39m=\u001b[39;49mcell_extractor,\n\u001b[1;32m 82\u001b[0m zero_based\u001b[39m=\u001b[39;49mzero_based,\n\u001b[1;32m 83\u001b[0m cell_separator\u001b[39m=\u001b[39;49mcell_separator,\n\u001b[1;32m 84\u001b[0m top_relation_label\u001b[39m=\u001b[39;49mtop_relation_label,\n\u001b[1;32m 85\u001b[0m )\n",
"File \u001b[0;32m~/dev/.venv/lib/python3.10/site-packages/nltk/parse/dependencygraph.py:331\u001b[0m, in \u001b[0;36mDependencyGraph._parse\u001b[0;34m(self, input_, cell_extractor, zero_based, cell_separator, top_relation_label)\u001b[0m\n\u001b[1;32m 329\u001b[0m cell_extractor \u001b[39m=\u001b[39m extractors[cell_number]\n\u001b[1;32m 330\u001b[0m \u001b[39mexcept\u001b[39;00m \u001b[39mKeyError\u001b[39;00m \u001b[39mas\u001b[39;00m e:\n\u001b[0;32m--> 331\u001b[0m \u001b[39mraise\u001b[39;00m \u001b[39mValueError\u001b[39;00m(\n\u001b[1;32m 332\u001b[0m \u001b[39m\"\u001b[39m\u001b[39mNumber of tab-delimited fields (\u001b[39m\u001b[39m{}\u001b[39;00m\u001b[39m) not supported by \u001b[39m\u001b[39m\"\u001b[39m\n\u001b[1;32m 333\u001b[0m \u001b[39m\"\u001b[39m\u001b[39mCoNLL(10) or Malt-Tab(4) format\u001b[39m\u001b[39m\"\u001b[39m\u001b[39m.\u001b[39mformat(cell_number)\n\u001b[1;32m 334\u001b[0m ) \u001b[39mfrom\u001b[39;00m \u001b[39me\u001b[39;00m\n\u001b[1;32m 336\u001b[0m \u001b[39mtry\u001b[39;00m:\n\u001b[1;32m 337\u001b[0m index, word, lemma, ctag, tag, feats, head, rel \u001b[39m=\u001b[39m cell_extractor(\n\u001b[1;32m 338\u001b[0m cells, index\n\u001b[1;32m 339\u001b[0m )\n",
"\u001b[0;31mValueError\u001b[0m: Number of tab-delimited fields (5) not supported by CoNLL(10) or Malt-Tab(4) format"
]
}
],
"source": [
"treebank_data =\"\"\"vaico v10 4245 shock absorber\"\"\"\n",
"dg = DependencyGraph(treebank_data)\n",
"dg.tree().pprint()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": ".venv",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.12"
},
"orig_nbformat": 4
},
"nbformat": 4,
"nbformat_minor": 2
}