entity:extract( $node as node(), [$dictionaries as cts:entity-dictionary*], [$options as xs:string*], [$map as map:map] ) as element()*
Extract entities from a document using the provided entity dictionary. The matching entities are returned.
Mapping can be done piecemeal. The type of an entity is split into
segments, delimited by a colon, and then each segment is matched in
turn against map
until a match is found. If the value of
a segment matches a mapping entry whose value is itself a map, then that
submap is used to match subsequent segments of the type. If the submap
contains no match, then the empty string is used to find a match within
the submap.
The default map defines a set of default recommended entity names:
e:credit-card-number
IDENTIFIER:CREDIT_CARD_NUM
)e:coordinate
IDENTIFIER:LATITUDE_LONGITUDE
)e:date
TEMPORAL:DATE
)e:distance
IDENTIFIER:DISTANCE
)e:email
IDENTIFIER:EMAIL
) e:gpe
GPE
)e:facility
FACILITY
) e:id
IDENTIFIER
) e:location
LOCATION
) e:money
IDENTIFIER:MONEY
) e:nationality
NATIONALITY
) e:number
IDENTIFIER:NUMBER
)e:organization
ORGANIZATION
)e:person
PERSON
)e:phone-number
IDENTIFIER:PHONE_NUMBER
) e:religion
RELIGION
)e:title
TITLE
)e:url
IDENTIFIER:URL
)e:utm
IDENTIFIER:UTM
)e:time
TEMPORAL:TIME
)(: extract entities, using the people ontology from the : entity:dictionary-load example :) import module namespace entity="http://marklogic.com/entity" at "/MarkLogic/entity.xqy"; let $map := map:new(( map:entry("",xs:QName("entity:entity")), map:entry("administrative district",xs:QName("entity:gpe")), map:entry("facilty",xs:QName("entity:facility")), map:entry("person",xs:QName("entity:person")), map:entry("land",xs:QName("entity:location")), map:entry("location",xs:QName("entity:location")), map:entry("organization",xs:QName("entity:organization")), map:entry("region",xs:QName("entity:gpe")) )) return entity:extract(<p>Nixon went to Paris</p>, cts:entity-dictionary-get("/ontology/people"), (), $map) (: Returns the extracted entity(s). For example: : : <entity:person xmlns:entity="http://marklogic.com/entity">Nixon</entity:person> : <entity:gpe xmlns:entity="http://marklogic.com/entity">Paris</entity:gpe> : <entity:gpe xmlns:entity="http://marklogic.com/entity">Paris</entity:gpe> : <entity:entity type="imaginary being:mythical being" xmlns:entity="http://marklogic.com/entity">Paris</entity:entity> :)
Stack Overflow: Get the most useful answers to questions from the MarkLogic community, or ask your own question.