Extract or consolidate entities from parsed documents
Source:R/entity-functions.R
entity_extract.RdFrom an object parsed by spacy_parse(), extract the entities as a
separate object, or convert the multi-word entities into single "token"
consisting of the concatenated elements of the multi-word entities.
Usage
entity_extract(x, type = c("named", "extended", "all"), concatenator = "_")
entity_consolidate(x, concatenator = "_")Arguments
- x
output from
spacy_parse().- type
type of named entities, either
named,extended, orall. Extended entities are those of typesDATE,TIME,PERCENT,MONEY,QUANTITY,ORDINALandCARDINAL, and named entities are those of all other types. The entity types are those of the language model; see its "Label scheme" on https://spacy.io/models.- concatenator
the character(s) used to join the elements of multi-word named entities
Value
entity_extract() returns a data.frame of all named
entities, containing the following fields:
doc_idname of the document containing the entitysentence_idthe sentence ID containing the entity, within the documententitythe named entityentity_typethe type of named entities (e.g. PERSON, ORG, PERCENT, etc.)
entity_consolidate returns a modified data.frame of
parsed results, where the named entities have been combined into a single
"token". Currently, dependency parsing is removed when this consolidation
occurs. If x has the columns start and end of
spacy_parse(offsets = TRUE), a consolidated entity runs from the start
of its first token to the end of its last.
Examples
if (FALSE) { # \dontrun{
spacy_initialize()
# entity extraction
txt <- "Mr. Smith of moved to San Francisco in December."
parsed <- spacy_parse(txt, entity = TRUE)
entity_extract(parsed)
entity_extract(parsed, type = "all")
} # }
if (FALSE) { # \dontrun{
# consolidating multi-word entities
txt <- "The House of Representatives voted to suspend aid to South Dakota."
parsed <- spacy_parse(txt, entity = TRUE)
entity_consolidate(parsed)
} # }