
entity.extract( node as Node, [dictionaries as cts.entityDictionary[]], [options as String[]], [map as Object] ) as Sequence
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-numberIDENTIFIER:CREDIT_CARD_NUM)e:coordinateIDENTIFIER:LATITUDE_LONGITUDE)e:dateTEMPORAL:DATE)e:distanceIDENTIFIER:DISTANCE)e:emailIDENTIFIER:EMAIL) e:gpeGPE)e:facilityFACILITY) e:idIDENTIFIER) e:locationLOCATION) e:moneyIDENTIFIER:MONEY) e:nationalityNATIONALITY) e:numberIDENTIFIER:NUMBER)e:organizationORGANIZATION)e:personPERSON)e:phone-numberIDENTIFIER:PHONE_NUMBER) e:religionRELIGION)e:titleTITLE)e:urlIDENTIFIER:URL)e:utmIDENTIFIER:UTM)e:timeTEMPORAL:TIME)
// Extract entities using the people onotology from the
// entity.dictionaryLoad 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('p', 'Nixon went to Paris')
.toNode();
entity.extract(node, cts.entityDictionaryGet('/ontology/people'), null, mapping);
// Returns the extracted entity. 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.