commit a75a16dee00ccd2657c49b6192a942ac8d660587 Author: J.Fernando Sánchez Date: Thu Mar 15 05:34:22 2012 +0100 First commit diff --git a/README.md b/README.md new file mode 100644 index 0000000..a37aa07 --- /dev/null +++ b/README.md @@ -0,0 +1,15 @@ +![GSI Logo](http://gsi.dit.upm.es/templates/jgsi/images/logo.png) +[Web 4.0](http://gsi.dit.upm.es) +================================== + +Description +--------------------- +This module is part of the Web4.0 project. + +So far, it performs basic queries to dbpedia, but the same code could be use to query any other sparql endpoint. + +Dependencies +-------------------- +coffee-script +sparql +hook.io diff --git a/bin/index.js b/bin/index.js new file mode 100644 index 0000000..0f4d4bb --- /dev/null +++ b/bin/index.js @@ -0,0 +1,4 @@ +require('coffee-script') +var Hook = require('../lib/hook.io-dbpedia').DBPediaHook +var SparHook = new Hook() +SparHook.start() diff --git a/lib/hook.io-dbpedia.coffee b/lib/hook.io-dbpedia.coffee new file mode 100644 index 0000000..ae07f90 --- /dev/null +++ b/lib/hook.io-dbpedia.coffee @@ -0,0 +1,41 @@ +# Imports +sparql = require 'sparql' +Hook = require('hook.io').Hook + +examplequery = " + SELECT DISTINCT ?label ?abstract ?population + WHERE { ?place rdf:type dbpedia-owl:PopulatedPlace. + ?place foaf:name ?label. + ?place dbpprop:population ?population. + OPTIONAL{ + ?place dbpedia-owl:abstract ?abstract. + FILTER langMatches( lang(?abstract), 'en') + } + } LIMIT 10" + + +class DBPediaHook extends Hook + constructor: (options) -> + self = this + Hook.call(self, options) + @client = new sparql.Client 'http://dbpedia.org/sparql' + #Set some initial namespaces + @client.prefix_map.dbprop = 'http://dbpedia.org/property/' + @client.prefix_map.dbpedia = 'http://dbpedia.org/resource/' + @client.prefix_map.rdf = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#' + @client.prefix_map.dbpedia-owl = 'http://dbpedia.org/ontology/' + + self.on 'hook::ready', -> + self.on '*::query', (data,fn) -> + @queryDBPedia data , (res) -> + console.log res + fn res + console.log "Created" + + + queryDBPedia: (query, cb) -> + console.log ">>Going to query" + @client.rows query, (err, res) -> + cb res + +exports.DBPediaHook = DBPediaHook