mirror of
https://github.com/balkian/hook.io-dbpedia.git
synced 2024-11-21 10:42:30 +00:00
Remastered to use the sparql hook
This commit is contained in:
parent
55925f7272
commit
7a0176205f
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
*.swp
|
@ -6,12 +6,10 @@ 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.
|
||||
So far, it performs basic queries to dbpedia, using the SPARQL Hook.
|
||||
|
||||
Dependencies
|
||||
--------------------
|
||||
To run this project, you will need to install the following dependencies through npm:
|
||||
|
||||
- coffee-script
|
||||
- sparql
|
||||
- hook.io
|
||||
- hook.io-sparql
|
||||
|
@ -1,4 +0,0 @@
|
||||
require('coffee-script')
|
||||
var Hook = require('../lib/hook.io-dbpedia').DBPediaHook
|
||||
var SparHook = new Hook()
|
||||
SparHook.start()
|
21
hook.io-dbpedia.coffee
Normal file
21
hook.io-dbpedia.coffee
Normal file
@ -0,0 +1,21 @@
|
||||
# Imports
|
||||
Hook = require('hook.io-sparql').SPARQLHook
|
||||
|
||||
|
||||
hook = new Hook({ 'url': 'http://dbpedia.org/sparql'})
|
||||
|
||||
hook.addPreffix 'dbprop','http://dbpedia.org/property/'
|
||||
hook.addPreffix 'dbpedia','http://dbpedia.org/resource/'
|
||||
hook.addPreffix 'rdf','http://www.w3.org/1999/02/22-rdf-syntax-ns#'
|
||||
hook.addPreffix 'dbpedia-owl' , 'http://dbpedia.org/ontology/'
|
||||
|
||||
|
||||
hook.on 'hook::ready', ->
|
||||
hook.on '*::query', (data,fn) ->
|
||||
hook.query data , (res) ->
|
||||
console.log res
|
||||
fn res
|
||||
console.log "Created"
|
||||
|
||||
|
||||
hook.start()
|
2
index.js
Normal file
2
index.js
Normal file
@ -0,0 +1,2 @@
|
||||
require('coffee-script')
|
||||
require('./hook.io-dbpedia')
|
@ -1,41 +0,0 @@
|
||||
# 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
|
Loading…
Reference in New Issue
Block a user