2012-03-15 15:09:37 +00:00
|
|
|
# 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) ->
|
2012-03-15 15:35:38 +00:00
|
|
|
@query data , (res) ->
|
2012-03-15 15:09:37 +00:00
|
|
|
console.log res
|
|
|
|
fn res
|
|
|
|
console.log "Created"
|
|
|
|
|
|
|
|
|
|
|
|
query: (query, cb) ->
|
|
|
|
console.log ">>Going to query"
|
|
|
|
@client.rows query, (err, res) ->
|
2012-03-15 16:19:43 +00:00
|
|
|
cb? res
|
2012-03-15 15:09:37 +00:00
|
|
|
|
|
|
|
addPreffix: (key,url) ->
|
|
|
|
@client.prefix_map[key] = url
|
|
|
|
|
|
|
|
exports.SPARQLHook = SPARQLHook
|