{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Collecting spacy\n", " Downloading spacy-3.5.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (6.6 MB)\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m6.6/6.6 MB\u001b[0m \u001b[31m1.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m00:01\u001b[0m00:01\u001b[0m\n", "\u001b[?25hRequirement already satisfied: numpy>=1.15.0 in /home/shoney/dev/.venv/lib/python3.10/site-packages (from spacy) (1.25.0)\n", "Collecting murmurhash<1.1.0,>=0.28.0\n", " Downloading murmurhash-1.0.9-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (21 kB)\n", "Collecting pathy>=0.10.0\n", " Downloading pathy-0.10.2-py3-none-any.whl (48 kB)\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m48.9/48.9 kB\u001b[0m \u001b[31m633.4 kB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m \u001b[36m0:00:01\u001b[0m\n", "\u001b[?25hCollecting spacy-loggers<2.0.0,>=1.0.0\n", " Downloading spacy_loggers-1.0.4-py3-none-any.whl (11 kB)\n", "Collecting cymem<2.1.0,>=2.0.2\n", " Downloading cymem-2.0.7-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (34 kB)\n", "Collecting wasabi<1.2.0,>=0.9.1\n", " Downloading wasabi-1.1.2-py3-none-any.whl (27 kB)\n", "Collecting preshed<3.1.0,>=3.0.2\n", " Downloading preshed-3.0.8-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (124 kB)\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m124.7/124.7 kB\u001b[0m \u001b[31m808.8 kB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m00:01\u001b[0m00:01\u001b[0m\n", "\u001b[?25hCollecting langcodes<4.0.0,>=3.2.0\n", " Downloading langcodes-3.3.0-py3-none-any.whl (181 kB)\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m181.6/181.6 kB\u001b[0m \u001b[31m1.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0ma \u001b[36m0:00:01\u001b[0m\n", "\u001b[?25hCollecting pydantic!=1.8,!=1.8.1,<1.11.0,>=1.7.4\n", " Downloading pydantic-1.10.9-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.1 MB)\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m3.1/3.1 MB\u001b[0m \u001b[31m1.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m00:01\u001b[0m00:01\u001b[0m\n", "\u001b[?25hRequirement already satisfied: packaging>=20.0 in /home/shoney/dev/.venv/lib/python3.10/site-packages (from spacy) (23.1)\n", "Collecting smart-open<7.0.0,>=5.2.1\n", " Downloading smart_open-6.3.0-py3-none-any.whl (56 kB)\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m56.8/56.8 kB\u001b[0m \u001b[31m586.3 kB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0ma \u001b[36m0:00:01\u001b[0m\n", "\u001b[?25hRequirement already satisfied: tqdm<5.0.0,>=4.38.0 in /home/shoney/dev/.venv/lib/python3.10/site-packages (from spacy) (4.65.0)\n", "Collecting typer<0.8.0,>=0.3.0\n", " Downloading typer-0.7.0-py3-none-any.whl (38 kB)\n", "Collecting srsly<3.0.0,>=2.4.3\n", " Downloading srsly-2.4.6-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (492 kB)\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m492.2/492.2 kB\u001b[0m \u001b[31m976.1 kB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m00:01\u001b[0m00:01\u001b[0m\n", "\u001b[?25hRequirement already satisfied: jinja2 in /home/shoney/dev/.venv/lib/python3.10/site-packages (from spacy) (3.1.2)\n", "Collecting spacy-legacy<3.1.0,>=3.0.11\n", " Downloading spacy_legacy-3.0.12-py2.py3-none-any.whl (29 kB)\n", "Collecting catalogue<2.1.0,>=2.0.6\n", " Downloading catalogue-2.0.8-py3-none-any.whl (17 kB)\n", "Requirement already satisfied: setuptools in /home/shoney/dev/.venv/lib/python3.10/site-packages (from spacy) (65.5.0)\n", "Collecting requests<3.0.0,>=2.13.0\n", " Downloading requests-2.31.0-py3-none-any.whl (62 kB)\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m62.6/62.6 kB\u001b[0m \u001b[31m829.1 kB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m0:01\u001b[0m00:01\u001b[0m\n", "\u001b[?25hCollecting thinc<8.2.0,>=8.1.8\n", " Downloading thinc-8.1.10-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (913 kB)\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m913.3/913.3 kB\u001b[0m \u001b[31m910.2 kB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m00:01\u001b[0m00:01\u001b[0m\n", "\u001b[?25hRequirement already satisfied: typing-extensions>=4.2.0 in /home/shoney/dev/.venv/lib/python3.10/site-packages (from pydantic!=1.8,!=1.8.1,<1.11.0,>=1.7.4->spacy) (4.6.3)\n", "Requirement already satisfied: urllib3<3,>=1.21.1 in /home/shoney/dev/.venv/lib/python3.10/site-packages (from requests<3.0.0,>=2.13.0->spacy) (2.0.3)\n", "Requirement already satisfied: idna<4,>=2.5 in /home/shoney/dev/.venv/lib/python3.10/site-packages (from requests<3.0.0,>=2.13.0->spacy) (3.4)\n", "Collecting charset-normalizer<4,>=2\n", " Downloading charset_normalizer-3.1.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (199 kB)\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m199.3/199.3 kB\u001b[0m \u001b[31m851.0 kB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m00:01\u001b[0m00:01\u001b[0m\n", "\u001b[?25hCollecting certifi>=2017.4.17\n", " Downloading certifi-2023.5.7-py3-none-any.whl (156 kB)\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m157.0/157.0 kB\u001b[0m \u001b[31m841.0 kB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m00:01\u001b[0m00:01\u001b[0m\n", "\u001b[?25hCollecting blis<0.8.0,>=0.7.8\n", " Downloading blis-0.7.9-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (10.2 MB)\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m10.2/10.2 MB\u001b[0m \u001b[31m1.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m00:01\u001b[0m0:01\u001b[0m\n", "\u001b[?25hCollecting confection<1.0.0,>=0.0.1\n", " Downloading confection-0.0.4-py3-none-any.whl (32 kB)\n", "Requirement already satisfied: click<9.0.0,>=7.1.1 in /home/shoney/dev/.venv/lib/python3.10/site-packages (from typer<0.8.0,>=0.3.0->spacy) (8.1.3)\n", "Requirement already satisfied: MarkupSafe>=2.0 in /home/shoney/dev/.venv/lib/python3.10/site-packages (from jinja2->spacy) (2.1.3)\n", "Installing collected packages: cymem, wasabi, typer, spacy-loggers, spacy-legacy, smart-open, pydantic, murmurhash, langcodes, charset-normalizer, certifi, catalogue, blis, srsly, requests, preshed, pathy, confection, thinc, spacy\n", "Successfully installed blis-0.7.9 catalogue-2.0.8 certifi-2023.5.7 charset-normalizer-3.1.0 confection-0.0.4 cymem-2.0.7 langcodes-3.3.0 murmurhash-1.0.9 pathy-0.10.2 preshed-3.0.8 pydantic-1.10.9 requests-2.31.0 smart-open-6.3.0 spacy-3.5.3 spacy-legacy-3.0.12 spacy-loggers-1.0.4 srsly-2.4.6 thinc-8.1.10 typer-0.7.0 wasabi-1.1.2\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 spacy\n" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Collecting en-core-web-sm==3.5.0\n", " Downloading https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-3.5.0/en_core_web_sm-3.5.0-py3-none-any.whl (12.8 MB)\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m12.8/12.8 MB\u001b[0m \u001b[31m1.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m00:01\u001b[0m00:01\u001b[0m\n", "\u001b[?25hRequirement already satisfied: spacy<3.6.0,>=3.5.0 in /home/shoney/dev/.venv/lib/python3.10/site-packages (from en-core-web-sm==3.5.0) (3.5.3)\n", "Requirement already satisfied: jinja2 in /home/shoney/dev/.venv/lib/python3.10/site-packages (from spacy<3.6.0,>=3.5.0->en-core-web-sm==3.5.0) (3.1.2)\n", "Requirement already satisfied: pathy>=0.10.0 in /home/shoney/dev/.venv/lib/python3.10/site-packages (from spacy<3.6.0,>=3.5.0->en-core-web-sm==3.5.0) (0.10.2)\n", "Requirement already satisfied: srsly<3.0.0,>=2.4.3 in /home/shoney/dev/.venv/lib/python3.10/site-packages (from spacy<3.6.0,>=3.5.0->en-core-web-sm==3.5.0) (2.4.6)\n", "Requirement already satisfied: cymem<2.1.0,>=2.0.2 in /home/shoney/dev/.venv/lib/python3.10/site-packages (from spacy<3.6.0,>=3.5.0->en-core-web-sm==3.5.0) (2.0.7)\n", "Requirement already satisfied: langcodes<4.0.0,>=3.2.0 in /home/shoney/dev/.venv/lib/python3.10/site-packages (from spacy<3.6.0,>=3.5.0->en-core-web-sm==3.5.0) (3.3.0)\n", "Requirement already satisfied: setuptools in /home/shoney/dev/.venv/lib/python3.10/site-packages (from spacy<3.6.0,>=3.5.0->en-core-web-sm==3.5.0) (65.5.0)\n", "Requirement already satisfied: spacy-loggers<2.0.0,>=1.0.0 in /home/shoney/dev/.venv/lib/python3.10/site-packages (from spacy<3.6.0,>=3.5.0->en-core-web-sm==3.5.0) (1.0.4)\n", "Requirement already satisfied: wasabi<1.2.0,>=0.9.1 in /home/shoney/dev/.venv/lib/python3.10/site-packages (from spacy<3.6.0,>=3.5.0->en-core-web-sm==3.5.0) (1.1.2)\n", "Requirement already satisfied: smart-open<7.0.0,>=5.2.1 in /home/shoney/dev/.venv/lib/python3.10/site-packages (from spacy<3.6.0,>=3.5.0->en-core-web-sm==3.5.0) (6.3.0)\n", "Requirement already satisfied: catalogue<2.1.0,>=2.0.6 in /home/shoney/dev/.venv/lib/python3.10/site-packages (from spacy<3.6.0,>=3.5.0->en-core-web-sm==3.5.0) (2.0.8)\n", "Requirement already satisfied: requests<3.0.0,>=2.13.0 in /home/shoney/dev/.venv/lib/python3.10/site-packages (from spacy<3.6.0,>=3.5.0->en-core-web-sm==3.5.0) (2.31.0)\n", "Requirement already satisfied: pydantic!=1.8,!=1.8.1,<1.11.0,>=1.7.4 in /home/shoney/dev/.venv/lib/python3.10/site-packages (from spacy<3.6.0,>=3.5.0->en-core-web-sm==3.5.0) (1.10.9)\n", "Requirement already satisfied: numpy>=1.15.0 in /home/shoney/dev/.venv/lib/python3.10/site-packages (from spacy<3.6.0,>=3.5.0->en-core-web-sm==3.5.0) (1.25.0)\n", "Requirement already satisfied: spacy-legacy<3.1.0,>=3.0.11 in /home/shoney/dev/.venv/lib/python3.10/site-packages (from spacy<3.6.0,>=3.5.0->en-core-web-sm==3.5.0) (3.0.12)\n", "Requirement already satisfied: thinc<8.2.0,>=8.1.8 in /home/shoney/dev/.venv/lib/python3.10/site-packages (from spacy<3.6.0,>=3.5.0->en-core-web-sm==3.5.0) (8.1.10)\n", "Requirement already satisfied: tqdm<5.0.0,>=4.38.0 in /home/shoney/dev/.venv/lib/python3.10/site-packages (from spacy<3.6.0,>=3.5.0->en-core-web-sm==3.5.0) (4.65.0)\n", "Requirement already satisfied: murmurhash<1.1.0,>=0.28.0 in /home/shoney/dev/.venv/lib/python3.10/site-packages (from spacy<3.6.0,>=3.5.0->en-core-web-sm==3.5.0) (1.0.9)\n", "Requirement already satisfied: typer<0.8.0,>=0.3.0 in /home/shoney/dev/.venv/lib/python3.10/site-packages (from spacy<3.6.0,>=3.5.0->en-core-web-sm==3.5.0) (0.7.0)\n", "Requirement already satisfied: preshed<3.1.0,>=3.0.2 in /home/shoney/dev/.venv/lib/python3.10/site-packages (from spacy<3.6.0,>=3.5.0->en-core-web-sm==3.5.0) (3.0.8)\n", "Requirement already satisfied: packaging>=20.0 in /home/shoney/dev/.venv/lib/python3.10/site-packages (from spacy<3.6.0,>=3.5.0->en-core-web-sm==3.5.0) (23.1)\n", "Requirement already satisfied: typing-extensions>=4.2.0 in /home/shoney/dev/.venv/lib/python3.10/site-packages (from pydantic!=1.8,!=1.8.1,<1.11.0,>=1.7.4->spacy<3.6.0,>=3.5.0->en-core-web-sm==3.5.0) (4.6.3)\n", "Requirement already satisfied: urllib3<3,>=1.21.1 in /home/shoney/dev/.venv/lib/python3.10/site-packages (from requests<3.0.0,>=2.13.0->spacy<3.6.0,>=3.5.0->en-core-web-sm==3.5.0) (2.0.3)\n", "Requirement already satisfied: certifi>=2017.4.17 in /home/shoney/dev/.venv/lib/python3.10/site-packages (from requests<3.0.0,>=2.13.0->spacy<3.6.0,>=3.5.0->en-core-web-sm==3.5.0) (2023.5.7)\n", "Requirement already satisfied: idna<4,>=2.5 in /home/shoney/dev/.venv/lib/python3.10/site-packages (from requests<3.0.0,>=2.13.0->spacy<3.6.0,>=3.5.0->en-core-web-sm==3.5.0) (3.4)\n", "Requirement already satisfied: charset-normalizer<4,>=2 in /home/shoney/dev/.venv/lib/python3.10/site-packages (from requests<3.0.0,>=2.13.0->spacy<3.6.0,>=3.5.0->en-core-web-sm==3.5.0) (3.1.0)\n", "Requirement already satisfied: confection<1.0.0,>=0.0.1 in /home/shoney/dev/.venv/lib/python3.10/site-packages (from thinc<8.2.0,>=8.1.8->spacy<3.6.0,>=3.5.0->en-core-web-sm==3.5.0) (0.0.4)\n", "Requirement already satisfied: blis<0.8.0,>=0.7.8 in /home/shoney/dev/.venv/lib/python3.10/site-packages (from thinc<8.2.0,>=8.1.8->spacy<3.6.0,>=3.5.0->en-core-web-sm==3.5.0) (0.7.9)\n", "Requirement already satisfied: click<9.0.0,>=7.1.1 in /home/shoney/dev/.venv/lib/python3.10/site-packages (from typer<0.8.0,>=0.3.0->spacy<3.6.0,>=3.5.0->en-core-web-sm==3.5.0) (8.1.3)\n", "Requirement already satisfied: MarkupSafe>=2.0 in /home/shoney/dev/.venv/lib/python3.10/site-packages (from jinja2->spacy<3.6.0,>=3.5.0->en-core-web-sm==3.5.0) (2.1.3)\n", "Installing collected packages: en-core-web-sm\n", "Successfully installed en-core-web-sm-3.5.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", "\u001b[38;5;2m✔ Download and installation successful\u001b[0m\n", "You can now load the package via spacy.load('en_core_web_sm')\n" ] } ], "source": [ "!python3 -m spacy download en_core_web_sm" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "import spacy\n", "from spacy import displacy\n", "from pathlib import Path\n", "nlp = spacy.load(\"en_core_web_sm\")\n", "\n", "options = {\"compact\": True, \"bg\": \"white\",\n", " \"color\": \"black\", \"font\": \"Source Sans Pro\"}" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "17268" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "text = (\"Motor oil, engine oil, or engine lubricant is any one of various substances used for the lubrication of internal combustion engines\")\n", "doc = nlp(text)\n", "svg = displacy.render(doc, style=\"dep\",jupyter=False)\n", "\n", "output_path = Path(\"../doc/images/dependency-parser.svg\") # you can keep there only \"dependency_plot.svg\" if you want to save it in the same folder where you run the script \n", "output_path.open(\"w\", encoding=\"utf-8\").write(svg)" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "doc = nlp(text)" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Noun phrases: ['Motor oil', 'engine oil', 'engine lubricant', 'various substances', 'the lubrication', 'internal combustion engines']\n", "Verbs: ['use']\n" ] } ], "source": [ "# Analyze syntax\n", "print(\"Noun phrases:\", [chunk.text for chunk in doc.noun_chunks])\n", "print(\"Verbs:\", [token.lemma_ for token in doc if token.pos_ == \"VERB\"])" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", " Motor\n", " NOUN\n", "\n", "\n", "\n", " oil,\n", " NOUN\n", "\n", "\n", "\n", " engine\n", " NOUN\n", "\n", "\n", "\n", " oil,\n", " NOUN\n", "\n", "\n", "\n", " or\n", " CCONJ\n", "\n", "\n", "\n", " engine\n", " NOUN\n", "\n", "\n", "\n", " lubricant\n", " NOUN\n", "\n", "\n", "\n", " is\n", " AUX\n", "\n", "\n", "\n", " any\n", " DET\n", "\n", "\n", "\n", " one\n", " NUM\n", "\n", "\n", "\n", " of\n", " ADP\n", "\n", "\n", "\n", " various\n", " ADJ\n", "\n", "\n", "\n", " substances\n", " NOUN\n", "\n", "\n", "\n", " used\n", " VERB\n", "\n", "\n", "\n", " for\n", " ADP\n", "\n", "\n", "\n", " the\n", " DET\n", "\n", "\n", "\n", " lubrication\n", " NOUN\n", "\n", "\n", "\n", " of\n", " ADP\n", "\n", "\n", "\n", " internal\n", " ADJ\n", "\n", "\n", "\n", " combustion\n", " NOUN\n", "\n", "\n", "\n", " engines\n", " NOUN\n", "\n", "\n", "\n", " \n", " \n", " compound\n", " \n", " \n", "\n", "\n", "\n", " \n", " \n", " nsubj\n", " \n", " \n", "\n", "\n", "\n", " \n", " \n", " compound\n", " \n", " \n", "\n", "\n", "\n", " \n", " \n", " conj\n", " \n", " \n", "\n", "\n", "\n", " \n", " \n", " cc\n", " \n", " \n", "\n", "\n", "\n", " \n", " \n", " compound\n", " \n", " \n", "\n", "\n", "\n", " \n", " \n", " conj\n", " \n", " \n", "\n", "\n", "\n", " \n", " \n", " det\n", " \n", " \n", "\n", "\n", "\n", " \n", " \n", " attr\n", " \n", " \n", "\n", "\n", "\n", " \n", " \n", " prep\n", " \n", " \n", "\n", "\n", "\n", " \n", " \n", " amod\n", " \n", " \n", "\n", "\n", "\n", " \n", " \n", " pobj\n", " \n", " \n", "\n", "\n", "\n", " \n", " \n", " acl\n", " \n", " \n", "\n", "\n", "\n", " \n", " \n", " prep\n", " \n", " \n", "\n", "\n", "\n", " \n", " \n", " det\n", " \n", " \n", "\n", "\n", "\n", " \n", " \n", " pobj\n", " \n", " \n", "\n", "\n", "\n", " \n", " \n", " prep\n", " \n", " \n", "\n", "\n", "\n", " \n", " \n", " amod\n", " \n", " \n", "\n", "\n", "\n", " \n", " \n", " compound\n", " \n", " \n", "\n", "\n", "\n", " \n", " \n", " pobj\n", " \n", " \n", "\n", "" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "displacy.render(doc, style=\"dep\")" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "3855" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "text = (\"Ford does not recomend Fx01\")\n", "doc = nlp(text)\n", "svg = displacy.render(doc, style=\"dep\",jupyter=False)\n", "\n", "output_path = Path(\"../doc/images/verbpart.svg\") # you can keep there only \"dependency_plot.svg\" if you want to save it in the same folder where you run the script \n", "output_path.open(\"w\", encoding=\"utf-8\").write(svg)" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", " Ford\n", " PROPN\n", "\n", "\n", "\n", " does\n", " AUX\n", "\n", "\n", "\n", " not\n", " PART\n", "\n", "\n", "\n", " recomend\n", " VERB\n", "\n", "\n", "\n", " Fx01\n", " PROPN\n", "\n", "\n", "\n", " \n", " \n", " nsubj\n", " \n", " \n", "\n", "\n", "\n", " \n", " \n", " aux\n", " \n", " \n", "\n", "\n", "\n", " \n", " \n", " neg\n", " \n", " \n", "\n", "\n", "\n", " \n", " \n", " dobj\n", " \n", " \n", "\n", "" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "5776" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "text = (\"Ford does not recomend Fx01. It recommends Fx05\")\n", "doc = nlp(text)\n", "svg = displacy.render(doc, style=\"dep\",options=options,jupyter=False)\n", "\n", "output_path = Path(\"../doc/images/pronoun.svg\") # you can keep there only \"dependency_plot.svg\" if you want to save it in the same folder where you run the script \n", "output_path.open(\"w\", encoding=\"utf-8\").write(svg)" ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", " What\n", " PRON\n", "\n", "\n", "\n", " is\n", " AUX\n", "\n", "\n", "\n", " used\n", " VERB\n", "\n", "\n", "\n", " for\n", " ADP\n", "\n", "\n", "\n", " the\n", " DET\n", "\n", "\n", "\n", " lubrication\n", " NOUN\n", "\n", "\n", "\n", " of\n", " ADP\n", "\n", "\n", "\n", " internal\n", " ADJ\n", "\n", "\n", "\n", " combustion\n", " NOUN\n", "\n", "\n", "\n", " engines\n", " NOUN\n", "\n", "\n", "\n", " \n", " \n", " nsubjpass\n", " \n", " \n", "\n", "\n", "\n", " \n", " \n", " auxpass\n", " \n", " \n", "\n", "\n", "\n", " \n", " \n", " prep\n", " \n", " \n", "\n", "\n", "\n", " \n", " \n", " det\n", " \n", " \n", "\n", "\n", "\n", " \n", " \n", " pobj\n", " \n", " \n", "\n", "\n", "\n", " \n", " \n", " prep\n", " \n", " \n", "\n", "\n", "\n", " \n", " \n", " amod\n", " \n", " \n", "\n", "\n", "\n", " \n", " \n", " compound\n", " \n", " \n", "\n", "\n", "\n", " \n", " \n", " pobj\n", " \n", " \n", "\n", "" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "text = (\"What is used for the lubrication of internal combustion engines\")\n", "doc = nlp(text)\n", "displacy.render(doc, style=\"dep\")" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", " vaico\n", " PROPN\n", "\n", "\n", "\n", " v26\n", " NOUN\n", "\n", "\n", "\n", " 0302\n", " NUM\n", "\n", "\n", "\n", " track\n", " NOUN\n", "\n", "\n", "\n", " control\n", " NOUN\n", "\n", "\n", "\n", " arm\n", " NOUN\n", "\n", "\n", "\n", " \n", " \n", " nsubj\n", " \n", " \n", "\n", "\n", "\n", " \n", " \n", " nmod\n", " \n", " \n", "\n", "\n", "\n", " \n", " \n", " nummod\n", " \n", " \n", "\n", "\n", "\n", " \n", " \n", " compound\n", " \n", " \n", "\n", "\n", "\n", " \n", " \n", " compound\n", " \n", " \n", "\n", "" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "text = (\"vaico v26 0302 track control arm\")\n", "doc = nlp(text)\n", "displacy.render(doc, style=\"dep\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "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" } }, "nbformat": 4, "nbformat_minor": 2 }