entity.enrich( node as Node, [dictionaries as cts.entityDictionary[]], [options as String[]], [map as Object] ) as Node
Returns the entity-enriched XML for the given XML node using the provided dictionary. If a text node that is being enriched has a parent element with a schema definition that does not allow element children, then that text node is not enriched. Entity markup is not added within other entities.
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
)// Enrich content using the people ontology from the // entity:dictionary-load example. 'use strict'; const entity = require('/MarkLogic/entity'); const mapping = { '' : fn.QName('http://marklogic.com/entity', 'entity:entity'), 'administrative district': fn.QName('http://marklogic.com/entity', 'entity:gpe'), facility: fn.QName('http://marklogic.com/entity', 'entity:facility'), person: fn.QName('http://marklogic.com/entity', 'entity:person'), land: fn.QName('http://marklogic.com/entity', 'entity:location'), location: fn.QName('http://marklogic.com/entity', 'entity:location'), organization: fn.QName('http://marklogic.com/entity', 'entity:organization'), region: fn.QName('http://marklogic.com/entity', 'entity:gpe') }; const node = new NodeBuilder() .addElement('node', 'Nixon visited Paris') .toNode(); entity.enrich(node, cts.entityDictionaryGet("/ontology/people"), null, mapping); // Returns the enriched node. For example: // // <node xmlns:entity="http://marklogic.com/entity"> // <entity:person>Richard Nixon</entity:person> visited <entity:gpe>Paris</entity:gpe>. // </node>
// Enrich content using the people ontology from the // entity:dictionary-load example. 'use strict'; const entity = require('/MarkLogic/entity'); const mapping = { '' : fn.QName('http://marklogic.com/entity', 'entity:entity'), 'administrative district': fn.QName('http://marklogic.com/entity', 'entity:gpe'), facility: fn.QName('http://marklogic.com/entity', 'entity:facility'), person: fn.QName('http://marklogic.com/entity', 'entity:person'), land: fn.QName('http://marklogic.com/entity', 'entity:location'), location: fn.QName('http://marklogic.com/entity', 'entity:location'), organization: fn.QName('http://marklogic.com/entity', 'entity:organization'), region: fn.QName('http://marklogic.com/entity', 'entity:gpe') }; const node = fn.head(xdmp.unquote( '<message xmlns="URN:ietf:params:email-xml" xmlns:rfc822="URN:ietf:params:rfc822:">' + '<rfc822:subject>Paris Visit</rfc822:subject>' + '<content>Richard Nixon visited Paris for secret talks.</content>' + '</message>' )); entity.enrich(node, cts.entityDictionaryGet("/ontology/people"), null, mapping); // Returns markup similar to following. Notice that the text inside // the rfc822:subject element is not enriched because the email schema // does not allow child elements in the subject. // // <message xmlns="URN:ietf:params:email-xml" // xmlns:entity="http://marklogic.com/entity" // xmlns:rfc822="URN:ietf:params:rfc822:"> // <rfc822:subject>Paris Visit</rfc822:subject> // <content> // <entity:person>Richard Nixon</entity:person> visited <entity:gpe>Paris</entity:gpe> for secret talks. // </content> // </message>
Stack Overflow: Get the most useful answers to questions from the MarkLogic community, or ask your own question.