Skip to content

Instantly share code, notes, and snippets.

@tomasonjo
Created August 30, 2019 17:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomasonjo/5855f43a805c536220e27f9ca2969807 to your computer and use it in GitHub Desktop.
Save tomasonjo/5855f43a805c536220e27f9ca2969807 to your computer and use it in GitHub Desktop.
# Analyze the first chapter
c = chapters[0]
# Get a list of persons
doc=nlp(c)
involved = list(set([ent.text for ent in doc.ents if ent.label_=='PERSON']))
# replace names of involved in the text
# with an id and save the mapping
decode = dict()
for i,x in enumerate(involved):
# Get mapping
decode['$${}$$'.format(i)] = x
# Preprocess text
c = c.replace(x,' $${}$$ '.format(i))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment