calais-entity-extractor
Advanced tools
Comparing version 1.2.1 to 1.3.0
@@ -8,3 +8,3 @@ | ||
//You can enter options as the second parameter. | ||
var calais = new Calais('ENTER API KEY HERE'); | ||
var calais = new Calais('API KEY HERE'); | ||
@@ -18,9 +18,11 @@ // You can set options after the constructor using .set(option, value). The example below sets | ||
// Example entity lookup | ||
/* | ||
// Example entity lookup | ||
calais.lookup("1-4295861160", function(result, err) { | ||
if (err) | ||
return console.log("Error: " + err); | ||
console.log("Result: " + util.inspect(result, false, null)); | ||
}); | ||
*/ | ||
@@ -37,5 +39,6 @@ | ||
/* | ||
//Example text entity tagging functionality. | ||
/* | ||
calais.extractFromText(function(result, err) { //perform the request | ||
@@ -55,22 +58,21 @@ if (err) { | ||
console.log('\nTags: ' + util.inspect(result.tags, false, null)); | ||
}); | ||
*/ | ||
//Now lets try analyzing a webpage. We supply a URL. | ||
calais.extractFromUrl('http://www.reuters.com/article/2015/10/07/us-iran-us-talks-idUSKCN0S10P220151007', function(result, err) { | ||
if (err) { | ||
console.log('Uh oh, we got an error! : ' + err); | ||
return; | ||
} | ||
//Now lets try analyzing a webpage. We supply a URL. | ||
calais.extractFromUrl('https://www.washingtonpost.com/politics/its-cruz-not-trump-who-looks-more-like-the-favorite-to-win-gop-primary/2015/12/13/bf8c57de-a1a9-11e5-b53d-972e2751f433_story.html', function(result, err) { | ||
if (err) { | ||
console.log('Uh oh, we got an error! : ' + err); | ||
return; | ||
} | ||
//The results have the same format as the extractFromText function. | ||
//The results have the same format as the extractFromText function. | ||
//'entities' contains a list of the detected entities, and gives basic info & confidence | ||
console.log('Entities: ' + util.inspect(result.entities, false, null)); | ||
//'entities' contains a list of the detected entities, and gives basic info & confidence | ||
console.log('Entities: ' + util.inspect(result.entities, false, null)); | ||
//'tags' are a list of string tags (the "socialTags" from Calais). | ||
console.log('\nTags: ' + util.inspect(result.tags, false, null)); | ||
}); | ||
//'tags' are a list of string tags (the "socialTags" from Calais). | ||
console.log('\nTags: ' + util.inspect(result.tags, false, null)); | ||
}); | ||
*/ |
@@ -62,28 +62,62 @@ var request = require('request'); | ||
if (p.hasOwnProperty('_type')) { | ||
var type = p._type; | ||
var confidenceLevel = 0.0; | ||
var name = ""; | ||
var fullName = ""; | ||
if (p.hasOwnProperty('confidencelevel')) | ||
confidenceLevel = p.confidencelevel; | ||
var entity = { 'type' : p._type, 'name' : p[key] }; | ||
if (p.hasOwnProperty("confidencelevel")) | ||
entity['confidence'] = p.confidencelevel; | ||
if (p.hasOwnProperty('resolutions')) { | ||
name = p[key]; | ||
fullName = p.resolutions[0].name; | ||
if (entity.confidence < minConfidence) | ||
continue; | ||
var resolution = null; | ||
if (p.hasOwnProperty('resolutions')) | ||
resolution = p.resolutions[0]; | ||
if (entity.type == 'Person') { | ||
if (p.hasOwnProperty("persontype") && p.persontype != "N/A") | ||
entity.persontype = p.persontype; | ||
if (p.hasOwnProperty("nationality") && p.nationality != "N/A") | ||
entity.nationality = p.nationality; | ||
if (p.hasOwnProperty("commonname")) | ||
entity.commonname = p.commonname; | ||
if (p.hasOwnProperty("firstname")) | ||
entity.firstname = p.firstname; | ||
if (p.hasOwnProperty("middlename")) | ||
entity.middlename = p.middlename; | ||
if (p.hasOwnProperty("lastname")) | ||
entity.lastname = p.lastname; | ||
} else if (entity.type == "Company") { | ||
if (p.hasOwnProperty("CompanyFounded")) | ||
entity.companyFounded = p.CompanyFounded; | ||
if (p.hasOwnProperty("CompanyTicker")) | ||
entity.ticker = p.CompanyTicker; | ||
if (resolution) { | ||
if (resolution.hasOwnProperty("name")) | ||
entity.fullName = resolution.name; | ||
if (resolution.hasOwnProperty("permid")) | ||
entity.permid = "1-" + resolution.permid; | ||
if (resolution.hasOwnProperty("primaryric")) | ||
entity.ric = resolution.primaryric; | ||
if (resolution.hasOwnProperty("commonname")) | ||
entity.name = resolution.commonname; | ||
} | ||
} else if (entity.type == "City") { | ||
if (resolution) { | ||
if (resolution.hasOwnProperty("name")) | ||
entity.fullName = resolution.name; | ||
if (resolution.hasOwnProperty("shortname")) | ||
entity.name = resolution.shortname; | ||
if (resolution.hasOwnProperty("containedbycountry")) | ||
entity.country = resolution.containedbycountry; | ||
if (resolution.hasOwnProperty("permid")) | ||
entity.permid = "1-" + resolution.permid; | ||
} | ||
} else | ||
name = p[key]; | ||
continue; | ||
//No further full name? Use the 'short' name | ||
if (fullName.length == 0) | ||
fullName = name; | ||
if (confidenceLevel >= minConfidence) | ||
entities.push({ | ||
'type': type, | ||
'name': name, | ||
'fullName': fullName, | ||
'confidence': confidenceLevel | ||
}); | ||
if (!p.hasOwnProperty("fullName") || p.fullName.length == 0 && p.name.length != 0) | ||
p['fullName'] = entity.name; | ||
entities.push(entity); | ||
} | ||
@@ -90,0 +124,0 @@ } else if (p._typeGroup == 'industry') { |
{ | ||
"name": "calais-entity-extractor", | ||
"version": "1.2.1", | ||
"version": "1.3.0", | ||
"description": "Extract entities from text using Open Calais.", | ||
@@ -5,0 +5,0 @@ "scripts": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
35238
517