Permalink
Browse files

add more query examples

  • Loading branch information...
gigasquid committed Jul 10, 2011
1 parent e645da1 commit efb1e7defe2ec5e8968f051b51ff71af3bb717f4
Showing with 58 additions and 0 deletions.
  1. +6 −0 README.md
  2. +1 −0 query_dbpedia_example.rb
  3. +50 −0 query_dbpedia_example2.rb
  4. +1 −0 query_dbpedia_geo_example.rb
View
@@ -16,6 +16,12 @@ in [Jean API Docs](http://openjena.org/tutorial/RDF_API/index.html).
* example_10.rb: Tutorial 10 - Demonstrate a container
* example_11.rb: Tutorial 11 - More on literals
+Also examples of querying DBPedia with
+* query_dbpedia_example.rb : German Musicians with a birth place of
+Berlin
+* query_dbpedia_geo_example.rb: Places nearby the White House
+* query_dbpedia_example2.rb: Musical Artist Sopranos with the hometown as the US
+
## Running
Run the examples with jruby
View
@@ -12,6 +12,7 @@
java_import 'com.hp.hpl.jena.query.QueryExecutionFactory'
#Querying Dbpedia
+#German Musicians with birthplace of Berlin
query = %q(
View
@@ -0,0 +1,50 @@
+require 'javalib/jena-2.6.4.jar'
+require 'javalib/arq-2.8.8.jar'
+require 'javalib/icu4j-3.4.4.jar'
+require 'javalib/iri-0.8.jar'
+require 'javalib/log4j-1.2.13.jar'
+require 'javalib/slf4j-api-1.5.8.jar'
+require 'javalib/slf4j-log4j12-1.5.8.jar'
+require 'javalib/xercesImpl-2.7.1.jar'
+require 'java'
+
+java_import 'com.hp.hpl.jena.query.QueryFactory'
+java_import 'com.hp.hpl.jena.query.QueryExecutionFactory'
+
+#Querying Dbpedia
+#Find all Musical Artist Sopranos with the hometown as the US
+
+
+query = %q(
+PREFIX dbpedia2: <http://dbpedia.org/property/>
+PREFIX dbowl: <http://dbpedia.org/ontology/>
+PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
+SELECT ?person ?voiceType ?hometown
+where {
+?person rdf:type <http://dbpedia.org/ontology/MusicalArtist>.
+?person dbpedia2:voiceType ?voiceType .
+?person dbowl:hometown ?hometown .
+?person dbowl:hometown <http://dbpedia.org/resource/United_States>
+FILTER regex(?voiceType, "soprano", "i")
+}
+)
+
+
+#creating query object
+query = QueryFactory.create(query)
+qexec = QueryExecutionFactory.sparql_service("http://dbpedia.org/sparql", query)
+
+results = qexec.exec_select
+while results.has_next
+ result = results.next
+ person = result.get("person").uri
+ voice_type = result.get("voiceType").string
+ hometown = result.get("hometown").uri
+ puts "#{person} #{voice_type} #{hometown}"
+end
+qexec.close
+
+
+
+
+
@@ -12,6 +12,7 @@
java_import 'com.hp.hpl.jena.query.QueryExecutionFactory'
#Querying Dbpedia with GEO information
+#Places nearby to the White House
query = %q(
PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>

0 comments on commit efb1e7d

Please sign in to comment.