1
0
mirror of https://github.com/balkian/hook.io-sparql.git synced 2025-09-02 09:32:21 +00:00

Converted the dbpedia example to a generic lib

This commit is contained in:
J.Fernando Sánchez
2012-03-15 16:09:37 +01:00
parent 55925f7272
commit 38bd4b859f
3 changed files with 42 additions and 1 deletions

39
lib/hook.io-sparql.coffee Normal file
View File

@@ -0,0 +1,39 @@
# 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 SPARQLHook extends Hook
constructor: (options) ->
self = this
Hook.call(self, options)
@client = new sparql.Client options.url
self.on 'hook::ready', ->
self.on '*::query', (data,fn) ->
@queryDBPedia data , (res) ->
console.log res
fn res
console.log "Created"
query: (query, cb) ->
console.log ">>Going to query"
@client.rows query, (err, res) ->
cb res
addPreffix: (key,url) ->
@client.prefix_map[key] = url
exports.SPARQLHook = SPARQLHook