Appery Entity Extraction

CordovaMlPlugin

Entity Extraction

Extract entities from text

EntityExtractor.extractEntities

Parameters
  • {string} text - text to extract entities from
  • {string} modelIdentifier - identifier of a model used for entity extraction
  • {function} success - callback function which takes a parameter data which will be invoked on success
  • {function} error - callback function which takes a parameter err which will be invoked on failure
  • {object} options - options for entity extraction
Important notice:

Model used for entity extraction should be downloaded before calling extractEntities.

Check it with EntityExtractor.getDownloadedEntityExtractionModels and then call EntityExtractor.downloadEntityExtractionModel if desired model is missing (see below).

Supported model identifiers can be retrieved via EntityExtractor.getSupportedEntityExtractionModels.

Supported options
PropertyDescriptionExamples
referenceTimeReference time based on which relative dates (e.g. “tomorrow”) should be interpreted. Represented as a number of milliseconds from the epoch of 1970-01-01T00:00:00 (UTC timezone) A null value means that the current time (when entity extraction is invoked) should be used.1619440306658
preferredLocaleA preferred locale that can be used to disambiguate potential values for date-time entities. Any of (or a subset of): en-* (en-US, en-UK, en-CA, ...), ar-*, de-, es-, fr-*, it-, ja-, ko-*, nl-, pl-, pt-*, ru-, th-, tr-*, zh-*. If not specified - the device’s system locale is used."en-UK"
typesFilterThe subset of entity types that will be detected by the entity extractor. Types not present in the set will not be returned even if they are present in the input text. If not specified - all types of entities are detected. Check the list of supported entity types["address", "flight"]
referenceTimeZoneTimezone string in tzdata compatible format. Reference time zone based on which relative dates (e.g. “tomorrow”) should be interpreted. If this is not set, the current time zone (when entity extraction is invoked) will be used."America/New_York"
downloadModelIfNeededBoolean flag, it enables automatic downloading of an extraction model if it isn't yet downloadedtrue
Response format

For each found entity its location is specified with two fields:

  • location - index of the first character of the entity
  • length - number of characters in the entity

entities field contain a list of entity descriptors. Each descriptor has a typefield which contains entity type code (look here for a list of possible values) and possibly other fields which are specific for an entity type.

Entity Types
CodeDescriptionExampleAdditional fields in entity descriptor
addressAddress350 third street, Cambridge MA
flightFlight Number (IATA flight codes only)LX37
  • airlineCode - The IATA airline designator (two or three letters).
  • flightNumber - The flight number (1 to 4 digit number).
ibanIBANCH52 0483 0000 0000 0000 9
  • IBAN - The full IBAN number in canonical form.
  • countryCode - The ISO 3166-1 alpha-2 country code (two letters).
datetimeDate-Time2019/09/29, let's meet tomorrow at 6pm
  • dateTime - The parsed date and time. Represented as a number of milliseconds from the epoch of 1970-01-01T00:00:00 (UTC timezone)
  • granularity - The granularity of the date and time (possible values: year, month, week, day, hour, minute or second)
isbnISBN (version 13 only)978-1101904190
  • ISBN - The full ISBN number in canonical form
phonePhone Number(555) 225-3556
payment_cardPayment / Credit Cards4111 1111 1111 1111
  • paymentCardNetwork - The payment card network. Possible values
  • paymentCardNumber - The payment card number in canonical form
emailEmail address[email protected]
tracking_numberTracking Number (standardized international formats)1Z204E380338943508
  • parcelCarrier - The parcel tracking carrier. Possible values
  • parcelTrackingNumber - The parcel tracking number in canonical form.
moneyMoney/Currency (Arabic numerals only)$12, 25 USD
  • unnormalizedCurrency - The currency part of the detected annotation. No formatting is applied so this will return a subset of the initial string.
  • integerPart - The integer part of the detected annotation. This is the integer written to the left of the decimal separator.
  • fractionalPart - The fractional part of the detected annotation. This is the integer written to the right of the decimal separator.
urlURLhttps://en.wikipedia.org/wiki/Platypus
Parcel carrier codes
CodeValue
fedExFedEX
upsUPS
dhlDHL
uspsUSPS
ontracOntrac
lasershipLasership
israelPostIsrael Post
swissPostSwiss Post
mscMSC
amazonAmazon
iParcelIParcel
unknownUnknown carrier
Payment card network codes
CodeValue
amexAmex
dinersClubDinersClub
discoverDiscover
interPaymentInterPayment
jcbJCB
maestroMaestro
mastercardMastercard
mirMir
troyTroy
unionPayUnionpay
visaVisa
unknownUnknown network
Example
ApperyioMLCordovaPlugin.EntityExtractor.extractEntities(
    "You can contact the test team tomorrow at [email protected] to determine the best timeline. To follow the progress of your delivery please use this tracking number: 9612804152073070474837",
    "english",
    results => console.log(results),
    error => console.log(error),
    {"preferredLocale": "en-UK"});

Sample JSON callback: entity_extraction.json

Get supported extraction models

EntityExtractor.getSupportedEntityExtractionModels

Parameters
  • {function} success - callback function which takes a parameter data which will be invoked on success
  • {function} error - callback function which takes a parameter err which will be invoked on failure
Example
ApperyioMLCordovaPlugin.EntityExtractor.getSupportedEntityExtractionModels(
    results => console.log(results),
    error => console.log(error));

Sample JSON callback: supported_entity_extraction_models.json

Get downloaded entity extraction models

EntityExtractor.getDownloadedEntityExtractionModels

List of language models that have been downloaded to the device.

Parameters
  • {function} success - callback function which takes a parameter data which will be invoked on success
  • {function} error - callback function which takes a parameter err which will be invoked on failure
Example
ApperyioMLCordovaPlugin.EntityExtractor.getSupportedEntityExtractionModels(
    results=>console.log(results),
    error => console.log(error));

Sample JSON callback: downloaded_entity_extraction_models.json

Download and delete entity extraction models

EntityExtractor.downloadEntityExtractionModel

EntityExtractor.deleteEntityExtractionModel

Download or delete an entity extraction model with specified model identifier.

Parameters
  • {string} modelIdentifier - model identifier
  • {function} success - callback function which takes a parameter data which will be invoked on success
  • {function} error - callback function which takes a parameter err which will be invoked on failure
Example
ApperyioMLCordovaPlugin.EntityExtractor.downloadEntityExtractionModel("russian", successCallback, errorCallback)
ApperyioMLCordovaPlugin.EntityExtractor.deleteEntityExtractionModel("russian", successCallback, errorCallback)

Sample JSON callback: download_delete_entity_extraction_model.json