qminer
Version:
A C++ based data analytics platform for processing large-scale real-time streams containing structured and unstructured data
125 lines (82 loc) • 3.38 kB
JavaScript
/**
* Copyright (c) 2015, Jozef Stefan Institute, Quintelligence d.o.o. and contributors
* All rights reserved.
*
* This source code is licensed under the FreeBSD license found in the
* LICENSE file in the root directory of this source tree.
*/
var http = require('http');
function replaceAll(find, replace, str) {
var find = find.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
return str.replace(new RegExp(find, 'g'), replace);
}
module.exports = {
suggest: function (prefix, resultCallback) {
http.get('http://eventregistry.org/json/suggestConcepts?prefix='+prefix+'&lang=eng', function(res) {
var value='';
res.on('data', function onData(d) {
value += d;
});
res.on('end', function() {
resultCallback(JSON.parse(value))
});
});
},
getEventsByUri: function (wikipediaUri, count, resultCallback) {
wikipediaUri = encodeURIComponent(wikipediaUri);
http.get('http://eventregistry.org/json/event?action=getEvents&conceptUri='+wikipediaUri+'&eventsConceptLang=eng&eventsCount='+count+'&eventsPage=0&eventsSortBy=rel&resultType=events', function(res) {
var value='';
res.on('data', function onData(d) {
value += d;
});
res.on('end', function() {
resultCallback(JSON.parse(value))
});
});
},
getEventsByName: function (wikipediaName, count, resultCallback) {
wikipediaName = replaceAll(' ', '_', wikipediaName);
http.get('http://eventregistry.org/json/event?action=getEvents&conceptUri=http:%2F%2Fen.wikipedia.org%2Fwiki%2F'+wikipediaName+'&eventsConceptLang=eng&eventsCount='+count+'&eventsPage=0&eventsSortBy=rel&resultType=events', function(res) {
var value='';
res.on('data', function onData(d) {
value += d;
});
res.on('end', function() {
resultCallback(JSON.parse(value))
});
});
},
getArticles: function (eventId, count, resultCallback) {
http.get('http://eventregistry.org/json/event?action=getEvent&articlesCount='+count+'&articlesLang=eng&articlesPage=0&articlesSortBy=cosSim&eventUri='+eventId+'&resultType=articles',function(res) {
var value='';
res.on('data', function onData(d) {
value += d;
});
res.on('end', function() {
resultCallback(JSON.parse(value));
});
});
},
getRecentActivity: function (articleCount, eventCount, sim, resultCallback) {
http.get('http://eventregistry.org/json/overview?action=getRecentActivity&recentActivityArticlesLastArticleActivityId=0&recentActivityArticlesMaxArticleCount='+articleCount+'&recentActivityEventsLastEventActivityId=0&recentActivityEventsMaxEventCount='+eventCount+'&recentActivityEventsMinAvgCosSim='+sim,function(res) {
var value='';
res.on('data', function onData(d) {
value += d;
});
res.on('end', function() {
resultCallback(JSON.parse(value));
});
});
},
searchEvents: function (term, count, resultCallback) {
http.get('http://www.eventregistry.org/json/event?action=getEvents&eventsConceptLang=eng&eventsCount='+count+'&eventsPage=0&eventsSortBy=rel&ignoreKeywords=&keywords='+term+'&resultType=events',function(res) {
var value='';
res.on('data', function onData(d) {
value += d;
});
res.on('end', function() {
resultCallback(JSON.parse(value));
});
});
}
}