...
Code Block |
---|
{ "actual_name": "CRM Buddy", "dimension": "Who", "disambiguated_name": "FocalCRM", "doccount": 0, "frequency": 1, "index": "focalcrm/twitterhandle", "linkdata": ["http://www.twitter.com/FocalCRM"], "relevance": 0, "totalfrequency": -1, "type": "TwitterHandle" }, |
Metadata
The metadata that document metadata used to create the JSON objectreveals how the value for actual_name
was derived from the displayName
from the original document.
Code Block |
---|
], "mediaType": ["Social"], "metadata": {"json": [{ "actor": { "displayName": "CRM Buddy", "followersCount": "245", "friendsCount": "0", "id": "id:twitter.com:835627776", "image": "http://a0.twimg.com/profile_images/2630355549/8cad59efaddd57283dbb159332336744_normal.jpeg", "languages": ["en"], "link": "http://www.twitter.com/FocalCRM", "links": [{"rel": "me"}], "listedCount": "6", "objectType": "person", "postedTime": "2012-09-20T13:59:56.000Z", "preferredUsername": "FocalCRM", "statusesCount": "3688", "summary": "", "verified": "false" }, |
...
Extracting Entities From Arrays
You can use manual entities with iterateOver
to create an entity for each object in the array, when the document metadata contains an array for a specific metadata field.
Source
In the example below, the source for entities Entities has been configured to iterateOver
the document metadata "victimsvictim."
In the example, frequency
calls uses $FUNC to call the function getVictimCount
, which was previously imported into the script engine, using the $FUNC() block. For more information about calling imported javascript functions, see Using Javascript globals.
Code Block |
---|
}, { "dimension": "Who", "disambiguated_name": "$FUNC( getVictim(); )", "frequency": "$FUNC( getVictimCount(); )", "type": "VictimType", "useDocGeo": false, "iterateOver": "victim" }, { "dimension": "Who", "disambiguated_name": "$FUNC( getVictim(); )", "frequency": "$hostagecount", "type": "HostageType", "useDocGeo": false, "iterateOver": "victim" } ] }, |
Sample Output
In the The sample output you can see some of the entities outputted based on the example source. The entities have been created displays the entities created based on the array that was returned for the metadata field "victim."
Code Block |
---|
}, { "actual_name": "Targeted, Civilian, Adult from Afghanistan", "dimension": "Who", "disambiguated_name": "Targeted, Civilian, Adult from Afghanistan", "doccount": 0, "frequency": 5, "index": "targeted, civilian, adult from afghanistan/victimtype", "relevance": 0, "totalfrequency": -1, "type": "VictimType" }, { "actual_name": "Targeted, Civilian, Child from Afghanistan", "dimension": "Who", "disambiguated_name": "Targeted, Civilian, Child from Afghanistan", "doccount": 0, "frequency": 2, "index": "targeted, civilian, child from afghanistan/victimtype", "relevance": 0, "totalfrequency": -1, "type": "VictimType" }, |
Metadata
The original document metadata was used by Manual entities to create the two entities for metadata value "victim" entities."
Code Block |
---|
"victim": [ { "child": "No", "combatant": "No", "deadcount": "1", "definingcharacteristic": "Unknown", "hostagecount": "0", "indicator": "Targeted", "nationality": "Afghanistan", "targetedcharacteristic": "Unknown", "victimtype": "Civilian", "woundedcount": "4" }, { "child": "Yes", "combatant": "No", "deadcount": "2", "definingcharacteristic": "Unknown", "hostagecount": "0", "indicator": "Targeted", "nationality": "Afghanistan", "targetedcharacteristic": "Unknown", "victimtype": "Civilian", "woundedcount": "0" } ], |
...
In the example source, the entity block is configured to output an entity using the with dimension "where." The location is determined using javascript, and the scripts are calling on function methods defined in the javascript Globals section$SCRIPT is used to call functions already declared in globals.
In the example, inline javascript is used by enclosing the javascript in the $SCRIPT() block. For more information about inline javascript, see Using Javascript globals.
Code Block |
---|
}, { "dimension": "Where", "disambiguated_name": "$metadata.json.actor.location.displayName", "geotag": { "city": "$SCRIPT( return getAddressVal( _doc.metadata.json[0].actor.location.displayName, 0 ) )", "stateProvince": "$SCRIPT( return getRegion(getAddressVal( _doc.metadata.json[0].actor.location.displayName, 1 )) )", "countryCode": "US", "alternatives": [ { "stateProvince": "$SCRIPT( return getRegion(getAddressVal( _doc.metadata.json[0].actor.location.displayName, 1 )) )", "countryCode": "US" } ] }, |
...
The alternatives are tried in order until one of them works or there are no more to try.
Globals:
Code Block |
---|
{
"globals": {
"scripts": [
"function getAddressVal( addressStr, number) { try { var addressArray = addressStr.split(/ *, */); if (addressArray != null && addressArray.length > 0) { if (addressArray[number].toLowerCase()=='ny') { return 'new york'; } else if (addressArray[number].toLowerCase()=='long island' || addressArray[number].toLowerCase()=='li') { return 'medford'; } else { return addressArray[number]; } } else { return ''; } } catch (err) { return ''; } } function getRegion( code ) { if (code.toLowerCase()=='ny') {return 'New York';} else if (code.toLowerCase()=='nj') {return 'New Jersey';} else if (code.toLowerCase()=='ct') {return 'Connecticut';} else if (code.toLowerCase()=='md') {return 'Maryland';} else if (code.toLowerCase()=='va') {return 'Virginia';} else if (code.toLowerCase()=='pa') {return 'Pennsylvania';} else if (code.toLowerCase()=='nj') {return 'New Jersey';} else {return 'New York';} }"
]
} |
Panel |
---|
Footnotes: Legacy documentation:
Legacy documentation: |
...