{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import nltk\n", "from nltk.tokenize import word_tokenize\n", "from nltk.tag import pos_tag\n", "from nltk.chunk import ne_chunk" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "sentence = 'European authorities fined Google a record $5.1 billion on Wednesday for abusing its power in the mobile phone market and ordered the company to alter its practices'" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "ne_tree = ne_chunk(pos_tag(word_tokenize(sentence)))" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "(S\n", " (GPE European/JJ)\n", " authorities/NNS\n", " fined/VBD\n", " (PERSON Google/NNP)\n", " a/DT\n", " record/NN\n", " $/$\n", " 5.1/CD\n", " billion/CD\n", " on/IN\n", " Wednesday/NNP\n", " for/IN\n", " abusing/VBG\n", " its/PRP$\n", " power/NN\n", " in/IN\n", " the/DT\n", " mobile/JJ\n", " phone/NN\n", " market/NN\n", " and/CC\n", " ordered/VBD\n", " the/DT\n", " company/NN\n", " to/TO\n", " alter/VB\n", " its/PRP$\n", " practices/NNS)\n" ] } ], "source": [ "print(ne_tree)" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "ex = 'European authorities fined Google a record $5.1 billion on Wednesday for abusing its power in the mobile phone market and ordered the company to alter its practices'" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "def preprocess(sent):\n", " sent = nltk.word_tokenize(sent)\n", " sent = nltk.pos_tag(sent)\n", " return sent" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[('European', 'JJ'),\n", " ('authorities', 'NNS'),\n", " ('fined', 'VBD'),\n", " ('Google', 'NNP'),\n", " ('a', 'DT'),\n", " ('record', 'NN'),\n", " ('$', '$'),\n", " ('5.1', 'CD'),\n", " ('billion', 'CD'),\n", " ('on', 'IN'),\n", " ('Wednesday', 'NNP'),\n", " ('for', 'IN'),\n", " ('abusing', 'VBG'),\n", " ('its', 'PRP$'),\n", " ('power', 'NN'),\n", " ('in', 'IN'),\n", " ('the', 'DT'),\n", " ('mobile', 'JJ'),\n", " ('phone', 'NN'),\n", " ('market', 'NN'),\n", " ('and', 'CC'),\n", " ('ordered', 'VBD'),\n", " ('the', 'DT'),\n", " ('company', 'NN'),\n", " ('to', 'TO'),\n", " ('alter', 'VB'),\n", " ('its', 'PRP$'),\n", " ('practices', 'NNS')]" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "sent = preprocess(ex)\n", "sent" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "pattern = 'NP: {
?*}'" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "(S\n", " European/JJ\n", " authorities/NNS\n", " fined/VBD\n", " Google/NNP\n", " (NP a/DT record/NN)\n", " $/$\n", " 5.1/CD\n", " billion/CD\n", " on/IN\n", " Wednesday/NNP\n", " for/IN\n", " abusing/VBG\n", " its/PRP$\n", " (NP power/NN)\n", " in/IN\n", " (NP the/DT mobile/JJ phone/NN)\n", " (NP market/NN)\n", " and/CC\n", " ordered/VBD\n", " (NP the/DT company/NN)\n", " to/TO\n", " alter/VB\n", " its/PRP$\n", " practices/NNS)\n" ] } ], "source": [ "cp = nltk.RegexpParser(pattern)\n", "cs = cp.parse(sent)\n", "print(cs)" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [], "source": [ "NPChunker = nltk.RegexpParser(pattern) \n", "result = NPChunker.parse(sent)\n", "result.draw()" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[('European', 'JJ', 'O'),\n", " ('authorities', 'NNS', 'O'),\n", " ('fined', 'VBD', 'O'),\n", " ('Google', 'NNP', 'O'),\n", " ('a', 'DT', 'B-NP'),\n", " ('record', 'NN', 'I-NP'),\n", " ('$', '$', 'O'),\n", " ('5.1', 'CD', 'O'),\n", " ('billion', 'CD', 'O'),\n", " ('on', 'IN', 'O'),\n", " ('Wednesday', 'NNP', 'O'),\n", " ('for', 'IN', 'O'),\n", " ('abusing', 'VBG', 'O'),\n", " ('its', 'PRP$', 'O'),\n", " ('power', 'NN', 'B-NP'),\n", " ('in', 'IN', 'O'),\n", " ('the', 'DT', 'B-NP'),\n", " ('mobile', 'JJ', 'I-NP'),\n", " ('phone', 'NN', 'I-NP'),\n", " ('market', 'NN', 'B-NP'),\n", " ('and', 'CC', 'O'),\n", " ('ordered', 'VBD', 'O'),\n", " ('the', 'DT', 'B-NP'),\n", " ('company', 'NN', 'I-NP'),\n", " ('to', 'TO', 'O'),\n", " ('alter', 'VB', 'O'),\n", " ('its', 'PRP$', 'O'),\n", " ('practices', 'NNS', 'O')]\n" ] } ], "source": [ "from nltk.chunk import conlltags2tree, tree2conlltags\n", "from pprint import pprint\n", "\n", "iob_tagged = tree2conlltags(cs)\n", "pprint(iob_tagged)" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [], "source": [ "import spacy\n", "from spacy import displacy\n", "from collections import Counter\n", "import en_core_web_sm\n", "nlp = en_core_web_sm.load()" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[('European', 'NORP'),\n", " ('Google', 'ORG'),\n", " ('$5.1 billion', 'MONEY'),\n", " ('Wednesday', 'DATE')]\n" ] } ], "source": [ "doc = nlp('European authorities fined Google a record $5.1 billion on Wednesday for abusing its power in the mobile phone market and ordered the company to alter its practices')\n", "pprint([(X.text, X.label_) for X in doc.ents])" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[(European, 'B', 'NORP'),\n", " (authorities, 'O', ''),\n", " (fined, 'O', ''),\n", " (Google, 'B', 'ORG'),\n", " (a, 'O', ''),\n", " (record, 'O', ''),\n", " ($, 'B', 'MONEY'),\n", " (5.1, 'I', 'MONEY'),\n", " (billion, 'I', 'MONEY'),\n", " (on, 'O', ''),\n", " (Wednesday, 'B', 'DATE'),\n", " (for, 'O', ''),\n", " (abusing, 'O', ''),\n", " (its, 'O', ''),\n", " (power, 'O', ''),\n", " (in, 'O', ''),\n", " (the, 'O', ''),\n", " (mobile, 'O', ''),\n", " (phone, 'O', ''),\n", " (market, 'O', ''),\n", " (and, 'O', ''),\n", " (ordered, 'O', ''),\n", " (the, 'O', ''),\n", " (company, 'O', ''),\n", " (to, 'O', ''),\n", " (alter, 'O', ''),\n", " (its, 'O', ''),\n", " (practices, 'O', '')]\n" ] } ], "source": [ "pprint([(X, X.ent_iob_, X.ent_type_) for X in doc])" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [], "source": [ "from bs4 import BeautifulSoup\n", "import requests\n", "import re" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [], "source": [ "def url_to_string(url):\n", " res = requests.get(url)\n", " html = res.text\n", " soup = BeautifulSoup(html, 'html5lib')\n", " for script in soup([\"script\", \"style\", 'aside']):\n", " script.extract()\n", " return \" \".join(re.split(r'[\\n\\t]+', soup.get_text()))" ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "188" ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ny_bb = url_to_string('https://www.nytimes.com/2018/08/13/us/politics/peter-strzok-fired-fbi.html?hp&action=click&pgtype=Homepage&clickSource=story-heading&module=first-column-region®ion=top-news&WT.nav=top-news')\n", "article = nlp(ny_bb)\n", "len(article.ents)" ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Counter({'CARDINAL': 5,\n", " 'DATE': 29,\n", " 'EVENT': 1,\n", " 'GPE': 35,\n", " 'LOC': 1,\n", " 'NORP': 5,\n", " 'ORDINAL': 1,\n", " 'ORG': 26,\n", " 'PERSON': 84,\n", " 'WORK_OF_ART': 1})" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "labels = [x.label_ for x in article.ents]\n", "Counter(labels)" ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[('Strzok', 32), ('F.B.I.', 17), ('Trump', 10)]" ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "items = [x.text for x in article.ents]\n", "Counter(items).most_common(3)" ] }, { "cell_type": "code", "execution_count": 18, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Firing Mr. Strzok, however, removes a favorite target of Mr. Trump from the ranks of the F.B.I. and gives Mr. Bowdich and the F.B.I. director, Christopher A. Wray, a chance to move beyond the president’s ire.\n" ] } ], "source": [ "sentences = [x for x in article.sents]\n", "print(sentences[20])" ] }, { "cell_type": "code", "execution_count": 19, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
Firing Mr. \n", "\n", " Strzok\n", " PERSON\n", "\n", ", however, removes a favorite target of Mr. \n", "\n", " Trump\n", " PERSON\n", "\n", " from the ranks of the \n", "\n", " F.B.I.\n", " GPE\n", "\n", " and gives Mr. \n", "\n", " Bowdich\n", " PERSON\n", "\n", " and the \n", "\n", " F.B.I.\n", " GPE\n", "\n", " director, \n", "\n", " Christopher A. Wray\n", " PERSON\n", "\n", ", a chance to move beyond the president’s ire.
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "displacy.render(nlp(str(sentences[20])), jupyter=True, style='ent')" ] }, { "cell_type": "code", "execution_count": 33, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", " Firing\n", " VERB\n", "\n", "\n", "\n", " Mr.\n", " PROPN\n", "\n", "\n", "\n", " Strzok,\n", " PROPN\n", "\n", "\n", "\n", " however,\n", " ADV\n", "\n", "\n", "\n", " removes\n", " VERB\n", "\n", "\n", "\n", " a\n", " DET\n", "\n", "\n", "\n", " favorite\n", " ADJ\n", "\n", "\n", "\n", " target\n", " NOUN\n", "\n", "\n", "\n", " of\n", " ADP\n", "\n", "\n", "\n", " Mr.\n", " PROPN\n", "\n", "\n", "\n", " Trump\n", " PROPN\n", "\n", "\n", "\n", " from\n", " ADP\n", "\n", "\n", "\n", " the\n", " DET\n", "\n", "\n", "\n", " ranks\n", " NOUN\n", "\n", "\n", "\n", " of\n", " ADP\n", "\n", "\n", "\n", " the\n", " DET\n", "\n", "\n", "\n", " F.B.I.\n", " PROPN\n", "\n", "\n", "\n", " and\n", " CCONJ\n", "\n", "\n", "\n", " gives\n", " VERB\n", "\n", "\n", "\n", " Mr.\n", " PROPN\n", "\n", "\n", "\n", " Bowdich\n", " PROPN\n", "\n", "\n", "\n", " and\n", " CCONJ\n", "\n", "\n", "\n", " the\n", " DET\n", "\n", "\n", "\n", " F.B.I.\n", " PROPN\n", "\n", "\n", "\n", " director,\n", " NOUN\n", "\n", "\n", "\n", " Christopher\n", " PROPN\n", "\n", "\n", "\n", " A.\n", " PROPN\n", "\n", "\n", "\n", " Wray,\n", " PROPN\n", "\n", "\n", "\n", " a\n", " DET\n", "\n", "\n", "\n", " chance\n", " NOUN\n", "\n", "\n", "\n", " to\n", " PART\n", "\n", "\n", "\n", " move\n", " VERB\n", "\n", "\n", "\n", " beyond\n", " ADP\n", "\n", "\n", "\n", " the\n", " DET\n", "\n", "\n", "\n", " president\n", " NOUN\n", "\n", "\n", "\n", " ’s\n", " PART\n", "\n", "\n", "\n", " ire.\n", " NOUN\n", "\n", "\n", "\n", " \n", " \n", " compound\n", " \n", " \n", "\n", "\n", "\n", " \n", " \n", " dobj\n", " \n", " \n", "\n", "\n", "\n", " \n", " \n", " advmod\n", " \n", " \n", "\n", "\n", "\n", " \n", " \n", " dep\n", " \n", " \n", "\n", "\n", "\n", " \n", " \n", " det\n", " \n", " \n", "\n", "\n", "\n", " \n", " \n", " amod\n", " \n", " \n", "\n", "\n", "\n", " \n", " \n", " dobj\n", " \n", " \n", "\n", "\n", "\n", " \n", " \n", " prep\n", " \n", " \n", "\n", "\n", "\n", " \n", " \n", " compound\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", " 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", " det\n", " \n", " \n", "\n", "\n", "\n", " \n", " \n", " pobj\n", " \n", " \n", "\n", "\n", "\n", " \n", " \n", " cc\n", " \n", " \n", "\n", "\n", "\n", " \n", " \n", " conj\n", " \n", " \n", "\n", "\n", "\n", " \n", " \n", " compound\n", " \n", " \n", "\n", "\n", "\n", " \n", " \n", " dative\n", " \n", " \n", "\n", "\n", "\n", " \n", " \n", " cc\n", " \n", " \n", "\n", "\n", "\n", " \n", " \n", " det\n", " \n", " \n", "\n", "\n", "\n", " \n", " \n", " amod\n", " \n", " \n", "\n", "\n", "\n", " \n", " \n", " conj\n", " \n", " \n", "\n", "\n", "\n", " \n", " \n", " compound\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", " dobj\n", " \n", " \n", "\n", "\n", "\n", " \n", " \n", " aux\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", " poss\n", " \n", " \n", "\n", "\n", "\n", " \n", " \n", " case\n", " \n", " \n", "\n", "\n", "\n", " \n", " \n", " pobj\n", " \n", " \n", "\n", "" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "displacy.render(nlp(str(sentences[20])), style='dep', jupyter = True, options = {'distance': 120})" ] }, { "cell_type": "code", "execution_count": 35, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[('Firing', 'VERB', 'fire'),\n", " ('Mr.', 'PROPN', 'mr.'),\n", " ('Strzok', 'PROPN', 'strzok'),\n", " ('removes', 'VERB', 'remove'),\n", " ('favorite', 'ADJ', 'favorite'),\n", " ('target', 'NOUN', 'target'),\n", " ('Mr.', 'PROPN', 'mr.'),\n", " ('Trump', 'PROPN', 'trump'),\n", " ('ranks', 'NOUN', 'rank'),\n", " ('F.B.I.', 'PROPN', 'f.b.i.'),\n", " ('gives', 'VERB', 'give'),\n", " ('Mr.', 'PROPN', 'mr.'),\n", " ('Bowdich', 'PROPN', 'bowdich'),\n", " ('F.B.I.', 'PROPN', 'f.b.i.'),\n", " ('director', 'NOUN', 'director'),\n", " ('Christopher', 'PROPN', 'christopher'),\n", " ('A.', 'PROPN', 'a.'),\n", " ('Wray', 'PROPN', 'wray'),\n", " ('chance', 'NOUN', 'chance'),\n", " ('president', 'NOUN', 'president'),\n", " ('’s', 'PART', '’s'),\n", " ('ire', 'NOUN', 'ire')]" ] }, "execution_count": 35, "metadata": {}, "output_type": "execute_result" } ], "source": [ "[(x.orth_,x.pos_, x.lemma_) for x in [y \n", " for y\n", " in nlp(str(sentences[20])) \n", " if not y.is_stop and y.pos_ != 'PUNCT']]" ] }, { "cell_type": "code", "execution_count": 36, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'Bowdich': 'PERSON',\n", " 'Christopher A. Wray': 'PERSON',\n", " 'F.B.I.': 'GPE',\n", " 'Strzok': 'PERSON',\n", " 'Trump': 'PERSON'}" ] }, "execution_count": 36, "metadata": {}, "output_type": "execute_result" } ], "source": [ "dict([(str(x), x.label_) for x in nlp(str(sentences[20])).ents])" ] }, { "cell_type": "code", "execution_count": 37, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[(Firing, 'O', ''), (Mr., 'O', ''), (Strzok, 'B', 'PERSON'), (,, 'O', ''), (however, 'O', ''), (,, 'O', ''), (removes, 'O', ''), (a, 'O', ''), (favorite, 'O', ''), (target, 'O', ''), (of, 'O', ''), (Mr., 'O', ''), (Trump, 'B', 'PERSON'), (from, 'O', ''), (the, 'O', ''), (ranks, 'O', ''), (of, 'O', ''), (the, 'O', ''), (F.B.I., 'B', 'GPE'), (and, 'O', ''), (gives, 'O', ''), (Mr., 'O', ''), (Bowdich, 'B', 'PERSON'), (and, 'O', ''), (the, 'O', ''), (F.B.I., 'B', 'GPE'), (director, 'O', ''), (,, 'O', ''), (Christopher, 'B', 'PERSON'), (A., 'I', 'PERSON'), (Wray, 'I', 'PERSON'), (,, 'O', ''), (a, 'O', ''), (chance, 'O', ''), (to, 'O', ''), (move, 'O', ''), (beyond, 'O', ''), (the, 'O', ''), (president, 'O', ''), (’s, 'O', ''), (ire, 'O', ''), (., 'O', '')]\n" ] } ], "source": [ "print([(x, x.ent_iob_, x.ent_type_) for x in sentences[20]])" ] }, { "cell_type": "code", "execution_count": 82, "metadata": { "scrolled": false }, "outputs": [ { "data": { "text/html": [ "
F.B.I. Agent \n", "\n", " Peter Strzok\n", " PERSON\n", "\n", ", \n", "\n", " Who Criticized Trump\n", " PERSON\n", "\n", " in Texts, Is \n", "\n", " Fired\n", " GPE\n", "\n", " - \n", "\n", " The New York Times\n", " ORG\n", "\n", " SectionsSEARCHSkip to contentSkip to site indexPoliticsSubscribeLog InSubscribeLog InToday's \n", "\n", " PaperAdvertisementSupported\n", " ORG\n", "\n", " byF.B.I. Agent \n", "\n", " Peter Strzok\n", " PERSON\n", "\n", ", \n", "\n", " Who Criticized Trump\n", " PERSON\n", "\n", " in Texts, Is FiredImagePeter Strzok, a top \n", "\n", " F.B.I.\n", " GPE\n", "\n", " counterintelligence agent who was taken off the special counsel investigation after his disparaging texts about President \n", "\n", " Trump\n", " PERSON\n", "\n", " were uncovered, was fired.\n", "\n", " CreditT.J. Kirkpatrick\n", " PERSON\n", "\n", " for \n", "\n", " The New York TimesBy Adam Goldman\n", " ORG\n", "\n", " and \n", "\n", " Michael S. SchmidtAug\n", " PERSON\n", "\n", ". \n", "\n", " 13\n", " CARDINAL\n", "\n", ", \n", "\n", " 2018WASHINGTON\n", " CARDINAL\n", "\n", " — \n", "\n", " Peter Strzok\n", " PERSON\n", "\n", ", the \n", "\n", " F.B.I.\n", " GPE\n", "\n", " senior counterintelligence agent who disparaged President \n", "\n", " Trump\n", " PERSON\n", "\n", " in inflammatory text messages and helped oversee the \n", "\n", " Hillary Clinton\n", " PERSON\n", "\n", " email and \n", "\n", " Russia\n", " GPE\n", "\n", " investigations, has been fired for violating bureau policies, Mr. \n", "\n", " Strzok\n", " PERSON\n", "\n", "’s lawyer said \n", "\n", " Monday\n", " DATE\n", "\n", ".Mr. Trump and his allies seized on the texts — exchanged during the \n", "\n", " 2016\n", " DATE\n", "\n", " campaign with a former \n", "\n", " F.B.I.\n", " GPE\n", "\n", " lawyer, \n", "\n", " Lisa Page — in\n", " PERSON\n", "\n", " assailing the \n", "\n", " Russia\n", " GPE\n", "\n", " investigation as an illegitimate “witch hunt.” Mr. \n", "\n", " Strzok\n", " PERSON\n", "\n", ", who rose over \n", "\n", " 20 years\n", " DATE\n", "\n", " at the \n", "\n", " F.B.I.\n", " GPE\n", "\n", " to become one of its most experienced counterintelligence agents, was a key figure in \n", "\n", " the early months\n", " DATE\n", "\n", " of the inquiry.Along with writing the texts, Mr. \n", "\n", " Strzok\n", " PERSON\n", "\n", " was accused of sending a highly sensitive search warrant to his personal email account.The \n", "\n", " F.B.I.\n", " GPE\n", "\n", " had been under immense political pressure by Mr. \n", "\n", " Trump\n", " PERSON\n", "\n", " to dismiss Mr. \n", "\n", " Strzok\n", " PERSON\n", "\n", ", who was removed \n", "\n", " last summer\n", " DATE\n", "\n", " from the staff of the special counsel, \n", "\n", " Robert S. Mueller III\n", " PERSON\n", "\n", ". The president has repeatedly denounced Mr. \n", "\n", " Strzok\n", " PERSON\n", "\n", " in posts on \n", "\n", " Twitter\n", " EVENT\n", "\n", ", and on \n", "\n", " Monday\n", " DATE\n", "\n", " expressed satisfaction that he had been sacked.Mr. \n", "\n", " Trump’s\n", " ORG\n", "\n", " victory traces back to \n", "\n", " June\n", " DATE\n", "\n", ", when Mr. \n", "\n", " Strzok\n", " PERSON\n", "\n", "’s conduct was laid out in a wide-ranging inspector general’s report on how the \n", "\n", " F.B.I.\n", " GPE\n", "\n", " handled the investigation of \n", "\n", " Hillary Clinton’s\n", " PERSON\n", "\n", " emails in the run-up to the \n", "\n", " 2016\n", " DATE\n", "\n", " election. The report was critical of Mr. \n", "\n", " Strzok\n", " PERSON\n", "\n", "’s conduct in sending the texts, and the bureau’s \n", "\n", " Office of Professional Responsibility\n", " ORG\n", "\n", " said that Mr. \n", "\n", " Strzok\n", " PERSON\n", "\n", " should be suspended for \n", "\n", " 60 days\n", " DATE\n", "\n", " and demoted. Mr. \n", "\n", " Strzok\n", " PERSON\n", "\n", " had testified before the \n", "\n", " House\n", " ORG\n", "\n", " in \n", "\n", " July\n", " DATE\n", "\n", " about how he had not allowed his political views to interfere with the investigations he was overseeing.But Mr. \n", "\n", " Strzok\n", " PERSON\n", "\n", "’s lawyer said the deputy director of the \n", "\n", " F.B.I.\n", " GPE\n", "\n", ", \n", "\n", " David Bowdich\n", " PERSON\n", "\n", ", had overruled \n", "\n", " the Office of Professional Responsibility\n", " ORG\n", "\n", " and fired Mr. \n", "\n", " Strzok\n", " PERSON\n", "\n", ".A spokeswoman for the \n", "\n", " F.B.I.\n", " GPE\n", "\n", " did not respond to a message seeking comment about why Mr. \n", "\n", " Strzok\n", " PERSON\n", "\n", " was dismissed rather than demoted. Firing Mr. \n", "\n", " Strzok\n", " PERSON\n", "\n", ", however, removes a favorite target of Mr. \n", "\n", " Trump\n", " PERSON\n", "\n", " from the ranks of the \n", "\n", " F.B.I.\n", " GPE\n", "\n", " and gives Mr. \n", "\n", " Bowdich\n", " PERSON\n", "\n", " and the \n", "\n", " F.B.I.\n", " GPE\n", "\n", " director, \n", "\n", " Christopher A. Wray\n", " PERSON\n", "\n", ", a chance to move beyond the president’s ire.\n", "\n", " Aitan Goelman\n", " PERSON\n", "\n", ", Mr. \n", "\n", " Strzok\n", " PERSON\n", "\n", "’s lawyer, denounced his client’s dismissal. “The decision to fire \n", "\n", " Special Agent Strzok\n", " ORG\n", "\n", " is not only a departure from typical bureau practice, but also contradicts Director \n", "\n", " Wray\n", " PERSON\n", "\n", "’s testimony to \n", "\n", " Congress\n", " ORG\n", "\n", " and his assurances that the \n", "\n", " F.B.I.\n", " GPE\n", "\n", " intended to follow its regular process in this and all personnel matters,” Mr. \n", "\n", " Goelman\n", " PERSON\n", "\n", " said.“This decision should be deeply troubling to all \n", "\n", " Americans\n", " NORP\n", "\n", ",” Mr. \n", "\n", " Goelman\n", " PERSON\n", "\n", " added. “A lengthy investigation and multiple rounds of congressional testimony failed to produce a shred of evidence that \n", "\n", " Special Agent\n", " ORG\n", "\n", " \n", "\n", " Strzok\n", " PERSON\n", "\n", "’s personal views ever affected his work.”Mr. Strzok’s text exchanges with Ms. \n", "\n", " Page\n", " PERSON\n", "\n", " demonstrated animosity toward Mr. \n", "\n", " Trump\n", " PERSON\n", "\n", ". In one, Ms. \n", "\n", " Page\n", " PERSON\n", "\n", " asks: Trump is “not ever going to become president, right? Right?!” Mr. \n", "\n", " Strzok\n", " PERSON\n", "\n", " responds: “No. No he won’t. We’ll stop it.” The inspector general, who uncovered the messages, found no evidence that the pair imposed their political views on their investigative decisions but cited that exchange as “not only indicative of a biased state of mind but, even more seriously, implies a willingness to take official action to impact the presidential candidate’s electoral prospects.”The report by the inspector general, \n", "\n", " Michael E. Horowitz\n", " PERSON\n", "\n", ", that preceded Mr. \n", "\n", " Strzok\n", " PERSON\n", "\n", "’s firing not only criticized his conduct in sending the texts but also his use of personal email accounts to handle sensitive information. In addition, the inspector general criticized Mr. \n", "\n", " Strzok\n", " PERSON\n", "\n", "’s decision not to move swiftly to examine new emails related to the \n", "\n", " Clinton\n", " PERSON\n", "\n", " investigation \n", "\n", " just weeks\n", " DATE\n", "\n", " before the \n", "\n", " 2016\n", " DATE\n", "\n", " election.Mr. \n", "\n", " Horowitz\n", " PERSON\n", "\n", " said in his report that he was “deeply troubled” by the text messages. \n", "\n", " Hundreds\n", " CARDINAL\n", "\n", " exchanged over \n", "\n", " months\n", " DATE\n", "\n", " were found in which the pair disparaged Mr. \n", "\n", " Trump\n", " PERSON\n", "\n", " and, to a lesser extent, Mrs. \n", "\n", " Clinton\n", " PERSON\n", "\n", ", exchanged work gossip and bantered.On \n", "\n", " Twitter\n", " GPE\n", "\n", ", Mr. \n", "\n", " Strzok\n", " PERSON\n", "\n", " said he was “deeply saddened by this decision,” adding, “It has been an honor to serve my country and work with the fine men and women of the \n", "\n", " FBI.”Mr\n", " NORP\n", "\n", ". Strzok became emblematic of Mr. \n", "\n", " Trump\n", " PERSON\n", "\n", "’s unfounded assertions that a so-called deep state of bureaucrats opposed to him was undermining his presidency. Mr. \n", "\n", " Trump\n", " PERSON\n", "\n", " contended that Mr. \n", "\n", " Strzok\n", " PERSON\n", "\n", " targeted the president and accused Mr. \n", "\n", " Strzok\n", " PERSON\n", "\n", " of being “treasonous” and a “disgrace.” Mr. \n", "\n", " Strzok\n", " PERSON\n", "\n", " told lawmakers that he never leaked information about the \n", "\n", " Russia\n", " GPE\n", "\n", " inquiry, which could have upended the election and hurt Mr. \n", "\n", " Trump\n", " PERSON\n", "\n", "’s chances of becoming president.After Mr. \n", "\n", " Horowitz\n", " PERSON\n", "\n", " uncovered the texts, Mr. \n", "\n", " Mueller\n", " PERSON\n", "\n", ", who had by then taken over the investigation, removed Mr. \n", "\n", " Strzok\n", " PERSON\n", "\n", " from his team. He was reassigned to the \n", "\n", " F.B.I.\n", " GPE\n", "\n", "’s human resources division. Ms. \n", "\n", " Page\n", " PERSON\n", "\n", ", who had left Mr. \n", "\n", " Mueller\n", " PERSON\n", "\n", "’s team before the discovery of the text messages, quit the \n", "\n", " F.B.I.\n", " GPE\n", "\n", " in \n", "\n", " May\n", " DATE\n", "\n", ".The inspector general’s report also took issue with the reaction by Mr. \n", "\n", " Strzok\n", " PERSON\n", "\n", " and other \n", "\n", " F.B.I.\n", " GPE\n", "\n", " officials to the discovery of possible new evidence in the \n", "\n", " Clinton\n", " PERSON\n", "\n", " investigation, known internally as \n", "\n", " Midyear Exam\n", " PERSON\n", "\n", ", in \n", "\n", " late September 2016\n", " DATE\n", "\n", " on a laptop that belonged to the disgraced politician \n", "\n", " Anthony D. Weiner\n", " PERSON\n", "\n", ", the husband of a top \n", "\n", " Clinton\n", " PERSON\n", "\n", " aide.At the time, Mr. \n", "\n", " Strzok\n", " PERSON\n", "\n", " was in the early stages of investigating whether any \n", "\n", " Trump\n", " NORP\n", "\n", " associates had conspired with \n", "\n", " Russia\n", " GPE\n", "\n", "’s interference in the presidential election, and \n", "\n", " nearly a month\n", " DATE\n", "\n", " passed before agents and analysts began to act on the emails found on Mr. \n", "\n", " Weiner\n", " PERSON\n", "\n", "’s laptop. Mr. \n", "\n", " Horowitz\n", " PERSON\n", "\n", " could not rule out that Mr. \n", "\n", " Strzok\n", " PERSON\n", "\n", " had slow-walked the examination of the new emails to help Mrs. \n", "\n", " Clinton\n", " PERSON\n", "\n", "’s presidential bid.“Under these circumstances, we did not have confidence that \n", "\n", " Strzok\n", " ORG\n", "\n", "’s decision to prioritize the \n", "\n", " Russia\n", " GPE\n", "\n", " investigation over following up on the \n", "\n", " Midyear\n", " DATE\n", "\n", "-related investigative lead discovered on the \n", "\n", " Weiner\n", " PERSON\n", "\n", " laptop was free from bias,” he wrote.The delays were merely the “result of bureaucratic snafus,” Mr. \n", "\n", " Strzok\n", " PERSON\n", "\n", "’s lawyer wrote \n", "\n", " last month\n", " DATE\n", "\n", " in \n", "\n", " USA\n", " GPE\n", "\n", " Today.But the justifications for the delay were “unpersuasive” and had “far-reaching consequences,” the inspector general said. \n", "\n", " James B. Comey\n", " PERSON\n", "\n", ", the former \n", "\n", " F.B.I.\n", " GPE\n", "\n", " director, has told investigators that if he had known about \n", "\n", " the emails earlier\n", " DATE\n", "\n", ", it might have influenced his decision to alert \n", "\n", " Congress\n", " ORG\n", "\n", " to their existence \n", "\n", " days\n", " DATE\n", "\n", " before the election.In addition, the inspector general said that Mr. \n", "\n", " Strzok\n", " PERSON\n", "\n", " had forwarded a proposed search warrant to his personal email account. The inspector general said the email, which included a draft of the search warrant affidavit, contained information that appeared to be under seal.In a heated congressional hearing \n", "\n", " last month\n", " DATE\n", "\n", ", Mr. \n", "\n", " Strzok\n", " PERSON\n", "\n", " expressed “significant regret” for the texts and rebutted the president’s attacks on the \n", "\n", " Russia\n", " GPE\n", "\n", " inquiry. “This investigation is not politically motivated; it is not a witch hunt; it is not a hoax,” he said.Mr. \n", "\n", " Strzok\n", " NORP\n", "\n", "’s dismissal was not unexpected. He is the \n", "\n", " second\n", " ORDINAL\n", "\n", " senior \n", "\n", " F.B.I.\n", " GPE\n", "\n", " agent to be fired as a result of the inspector general’s investigation. In \n", "\n", " March\n", " DATE\n", "\n", ", \n", "\n", " Andrew G. McCabe\n", " PERSON\n", "\n", ", the former deputy director, was fired after the inspector general repeatedly faulted him for misleading investigators.The firing was politically motivated, Mr. \n", "\n", " McCabe\n", " PERSON\n", "\n", " has said, as an effort to discredit him as a witness in the special counsel investigation.Both men were fired before they were eligible for their pension and health benefits.Mr. \n", "\n", " Strzok\n", " ORG\n", "\n", ", \n", "\n", " 48\n", " DATE\n", "\n", ", a graduate of \n", "\n", " Georgetown University\n", " ORG\n", "\n", ", served as an officer in the \n", "\n", " Army\n", " ORG\n", "\n", " before he joined the F.B.I. He held several key positions in the \n", "\n", " F.B.I.\n", " GPE\n", "\n", ", eventually becoming a top deputy in the counterintelligence division.He handled many important espionage cases including one involving a former C.I.A. officer suspected of working for \n", "\n", " China\n", " GPE\n", "\n", " and a group of \n", "\n", " Russian\n", " NORP\n", "\n", " spies who had been working undercover in \n", "\n", " the United States\n", " GPE\n", "\n", ". \n", "\n", " Follow Adam Goldman\n", " PERSON\n", "\n", " and \n", "\n", " Michael S. Schmidt\n", " PERSON\n", "\n", " on \n", "\n", " Twitter\n", " GPE\n", "\n", ": @adamgoldmanNYT and \n", "\n", " @nytmike\n", " ORG\n", "\n", ".A version of this article appears in print on , on \n", "\n", " Page A1\n", " PERSON\n", "\n", " of the \n", "\n", " New York\n", " GPE\n", "\n", " edition with the headline: F.B.I. Banishes An Agent Who \n", "\n", " Reviled Trump\n", " PERSON\n", "\n", ". Order Reprints | \n", "\n", " Today\n", " DATE\n", "\n", "’s \n", "\n", " Paper | SubscribeRelated CoverageF.B.I. Agent Defends Actions in Russia Inquiry in Contentious House TestimonyJuly 12\n", " WORK_OF_ART\n", "\n", ", 2018ImageReport \n", "\n", " Criticizes Comey but Finds No Bias\n", " ORG\n", "\n", " in F.B.I. Decision on ClintonJune 14, \n", "\n", " 2018ImageAndrew\n", " CARDINAL\n", "\n", " \n", "\n", " McCabe\n", " ORG\n", "\n", ", a \n", "\n", " Target of Trump’s\n", " ORG\n", "\n", " F.B.I. Scorn, Is \n", "\n", " Fired\n", " GPE\n", "\n", " Over \n", "\n", " Candor\n", " GPE\n", "\n", " QuestionsMarch \n", "\n", " 16\n", " CARDINAL\n", "\n", ", 2018ImageAdvertisementSite \n", "\n", " IndexGo\n", " PERSON\n", "\n", " to Home Page »newshome pageworldU.S.politicsNew Yorkbusinesstechscienceclimatesportsobituariesthe upshottoday's \n", "\n", " papercorrectionsopiniontoday\n", " DATE\n", "\n", "'s opinionop-ed columnistseditorialsop-ed \n", "\n", " Contributorsletterssunday\n", " DATE\n", "\n", " reviewvideo: opinionartstoday's artsart & designbooksdancemoviesmusictelevisiontheaterwatchingvideo: artslivingautomobilescrosswordfoodCookingeducationfashion & stylehealthjobsmagazinereal estatet magazinetravelweddingslistings \n", "\n", " & moreReader\n", " ORG\n", "\n", " \n", "\n", " Centertools & servicesN.Y.C.\n", " ORG\n", "\n", " events \n", "\n", " guidemultimediaphotographyvideoNYT\n", " GPE\n", "\n", " storetimes journeysmanage my accountthe learning networknewshome \n", "\n", " pageworldU.S.politicsNew Yorkbusinesstechscienceclimatesportsobituariesthe\n", " LOC\n", "\n", " upshottoday's \n", "\n", " papercorrectionsopiniontoday\n", " DATE\n", "\n", "'s opinionop-ed columnistseditorialsop-ed \n", "\n", " Contributorsletterssunday\n", " DATE\n", "\n", " reviewvideo: opinionartstoday's artsart & designbooksdancemoviesmusictelevisiontheaterwatchingvideo: artslivingautomobilescrosswordfoodCookingeducationfashion & stylehealthjobsmagazinereal estatet magazinetravelweddingsmoreReader \n", "\n", " Centertools & servicesN.Y.C.\n", " ORG\n", "\n", " events \n", "\n", " guidemultimediaphotographyvideoNYT\n", " GPE\n", "\n", " storetimes journeysmanage my accountthe learning networkSubscribehome deliverydigital subscriptionsCrosswordCookingemail newsletterscorporate subscriptionseducation ratemobile applicationsreplica editionSite \n", "\n", " Information Navigation\n", " ORG\n", "\n", "©\n", "\n", "  2018\n", " DATE\n", "\n", "\n", "\n", "  \n", " PERSON\n", "\n", "\n", "\n", " The New York Times\n", " ORG\n", "\n", " CompanyContact UsWork with usAdvertiseYour \n", "\n", " Ad ChoicesPrivacyTerms\n", " GPE\n", "\n", " of \n", "\n", " ServiceTerms of SaleSite MapHelpHelpSubscriptions\n", " ORG\n", "\n", " \n", "\n", " \n", " PERSON\n", "\n", "
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "displacy.render(article, jupyter=True, style='ent')" ] } ], "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.6.4" } }, "nbformat": 4, "nbformat_minor": 2 }