{ "cells": [ { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "from spacy import displacy" ] }, { "cell_type": "code", "execution_count": 33, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Prepared 22 documents.\n", "They can be accessed using or_texts[n], being n an integer from 0 to 21.\n", "Distribution of documents by language after translation: {'en': 22}\n", "Unique terms found: 3538\n", "Named entities found: 176\n", "Vectors created.\n", "Test: [4 5 0 0 0 2 0 0 0 1 4 4 2 2 1 0 2 4 1 1 1 3]\n", "Reference: [0, 5, 2, 2, 2, 3, 2, 2, 2, 4, 0, 0, 3, 3, 4, 2, 3, 0, 4, 4, 4, 1]\n", "Adjusted Rand Index: 1.0\n" ] } ], "source": [ "%run ./Practica1ObligatoriaRIMT_1819.py" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Rendering named entities visualization of original texts" ] }, { "cell_type": "code", "execution_count": 30, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
The \n", "\n", " British\n", " NORP\n", "\n", " photographer \n", "\n", " John Cantlie\n", " PERSON\n", "\n", ", hostage of the \n", "\n", " Islamic\n", " NORP\n", "\n", " \n", "\n", " State\n", " ORG\n", "\n", " since \n", "\n", " November 2012\n", " DATE\n", "\n", " could be alive and be in \n", "\n", " Syria\n", " GPE\n", "\n", ", specifically the last stronghold of the jihadist organization that is being attacked by \n", "\n", " the Syrian Democratic Forces (SDF\n", " ORG\n", "\n", "), formed mostly by militias \n", "\n", " Kurdish\n", " NORP\n", "\n", " \n", "\n", " YPG\n", " ORG\n", "\n", ".
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "displacy.render(nlp(or_texts[3])[0:50], style = 'ent', jupyter = True)" ] }, { "cell_type": "code", "execution_count": 32, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
The \n", "\n", " British\n", " NORP\n", "\n", " journalist \n", "\n", " John Cantlie\n", " PERSON\n", "\n", ", kidnapped \n", "\n", " seven years ago\n", " DATE\n", "\n", " in \n", "\n", " Syria\n", " GPE\n", "\n", " by \n", "\n", " the Islamic State\n", " ORG\n", "\n", " (IS), could remain alive, according to the Secretary of \n", "\n", " State for Security of the United Kingdom\n", " ORG\n", "\n", ", \n", "\n", " Ben Wallace\n", " PERSON\n", "\n", ". Speaking to the media at \n", "\n", " the Interior Ministry\n", " ORG\n", "\n", ", \n", "\n", " Wallace\n", " PERSON\n", "\n", "
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "displacy.render(nlp(or_texts[4])[0:50], style = 'ent', jupyter = True)" ] }, { "cell_type": "code", "execution_count": 43, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
Based on facts observed and verified firsthand by the journalist, or reported by reliable and well-informed sources. The \n", "\n", " American\n", " NORP\n", "\n", " retires at \n", "\n", " 34 years\n", " DATE\n", "\n", " after the conquest of an unexpected bronze medal in the descent of \n", "\n", " the World Cup\n", " EVENT\n", "\n", " AreThe ski said goodbye to \n", "\n", " Lindsey Vonn\n", " PERSON\n", "\n", " with
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "displacy.render(nlp(or_texts[0])[0:50], style = 'ent', jupyter = True)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "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.7.0" } }, "nbformat": 4, "nbformat_minor": 2 }