-
Notifications
You must be signed in to change notification settings - Fork 1
/
namedEntityRecognition.js
53 lines (50 loc) · 2.09 KB
/
namedEntityRecognition.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/**
* A module to query the EEXCESS named entitiy recognition and disambiguation service.
*
* @module c4/namedEntityRecognition
*/
/**
* Callback for the entitiesAndCategories function
* @callback namedEntityRecognition~onResponse
* @param {String} status Indicates the status of the request, either "success" or "error".
* @param {Object} data Contains the response data. In the case of an error, it is the error message and in the case of success, it is the response returned from the named entity recognition service. TODO: add link to documentation
*/
define(['jquery'], function($) {
var endpoint = 'https://eexcess.joanneum.at/eexcess-privacy-proxy-issuer-1.0-SNAPSHOT/issuer/recognizeEntity';
var xhr;
return {
/**
* Retrieves named entities and associated categories for a set of paragraphs.
* @param {Array<{id:String,headline:String,content:String}>} paragraphs The paragraphs to annotate.
* @param {namedEntityRecognition~onResponse} callback Callback function called on success or error.
*/
entitiesAndCategories: function(paragraphs, callback) {
if (xhr && xhr.readyState !== 4) {
xhr.abort();
}
xhr = $.ajax({
url: endpoint,
data: JSON.stringify(paragraphs),
type: 'POST',
contentType: 'application/json',
dataType: 'json',
timeout:10000
});
xhr.done(function(response) {
if (typeof callback !== 'undefined') {
callback({status: 'success', data: response});
}
});
xhr.fail(function(jqXHR, textStatus, errorThrown) {
if (textStatus !== 'abort') {
console.log(jqXHR);
console.log(textStatus);
console.log(errorThrown);
if (typeof callback !== 'undefined') {
callback({status: 'error', data: textStatus});
}
}
});
}
};
});