Skip to content

Instantly share code, notes, and snippets.

@ageitgey
Created July 16, 2018 23:31
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ageitgey/99debc6682295d1580fff1b803648dd4 to your computer and use it in GitHub Desktop.
Save ageitgey/99debc6682295d1580fff1b803648dd4 to your computer and use it in GitHub Desktop.
import spacy
import textacy.extract
# Load the large English NLP model
nlp = spacy.load('en_core_web_lg')
# The text we want to examine
text = """London is the capital and most populous city of England and the United Kingdom.
Standing on the River Thames in the south east of the island of Great Britain,
London has been a major settlement for two millennia. It was founded by the Romans,
who named it Londinium.
"""
# Parse the document with spaCy
doc = nlp(text)
# Extract semi-structured statements
statements = textacy.extract.semistructured_statements(doc, "London")
# Print the results
print("Here are the things I know about London:")
for statement in statements:
subject, verb, fact = statement
print(f" - {fact}")
@niko-la-petrovic
Copy link

The textacy.extract API has changed. The function semistructured_statements no longer takes in only two positional arguments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment