Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 51 lines (38 sloc) 1.351 kb
efb1e7d @gigasquid add more query examples
authored
1 require 'javalib/jena-2.6.4.jar'
2 require 'javalib/arq-2.8.8.jar'
3 require 'javalib/icu4j-3.4.4.jar'
4 require 'javalib/iri-0.8.jar'
5 require 'javalib/log4j-1.2.13.jar'
6 require 'javalib/slf4j-api-1.5.8.jar'
7 require 'javalib/slf4j-log4j12-1.5.8.jar'
8 require 'javalib/xercesImpl-2.7.1.jar'
9 require 'java'
10
11 java_import 'com.hp.hpl.jena.query.QueryFactory'
12 java_import 'com.hp.hpl.jena.query.QueryExecutionFactory'
13
14 #Querying Dbpedia
15 #Find all Musical Artist Sopranos with the hometown as the US
16
17
18 query = %q(
19 PREFIX dbpedia2: <http://dbpedia.org/property/>
20 PREFIX dbowl: <http://dbpedia.org/ontology/>
21 PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
22 SELECT ?person ?voiceType ?hometown
23 where {
24 ?person rdf:type <http://dbpedia.org/ontology/MusicalArtist>.
25 ?person dbpedia2:voiceType ?voiceType .
26 ?person dbowl:hometown ?hometown .
27 ?person dbowl:hometown <http://dbpedia.org/resource/United_States>
28 FILTER regex(?voiceType, "soprano", "i")
29 }
30 )
31
32
33 #creating query object
34 query = QueryFactory.create(query)
35 qexec = QueryExecutionFactory.sparql_service("http://dbpedia.org/sparql", query)
36
37 results = qexec.exec_select
38 while results.has_next
39 result = results.next
40 person = result.get("person").uri
41 voice_type = result.get("voiceType").string
42 hometown = result.get("hometown").uri
43 puts "#{person} #{voice_type} #{hometown}"
44 end
45 qexec.close
46
47
48
49
50
Something went wrong with that request. Please try again.