Created
May 21, 2009 17:52
-
-
Save tommorris/115594 to your computer and use it in GitHub Desktop.
some experiments with Jena running on top of JRuby
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "jenasupport_j" # just to prevent me going mad, I suffix all my JRuby stuff with _j | |
model = ModelFactory.createDefaultModel() | |
tommorris = model.createResource("http://tommorris.org/") | |
tommorris.addProperty(model.createProperty("http://xmlns.com/foaf/0.1/name"), "Tom Morris") | |
model.setNsPrefix("foaf", "http://xmlns.com/foaf/0.1/") | |
model.write(java.lang.System.out) | |
# Let's run a SPARQL query over it! | |
query = "SELECT ?s ?p ?o WHERE { ?s ?p ?o . }" | |
queryobj = QueryFactory.create(query) | |
qexec = QueryExecutionFactory.create(query, model) | |
results = qexec.execSelect() | |
soln = results.nextSolution() #=> #<Java::ComHpHplJenaSparqlCore::ResultBinding:0xb6c909 @java_object=#<Java::JavaObject:0x488344>> | |
soln.get("s") #=> #<Java::ComHpHplJenaRdfModelImpl::ResourceImpl:0x6bc75c @java_object=#<Java::JavaObject:0xed8363>> | |
soln.get("s").to_s #=> "http://tommorris.org/" | |
soln.get("p").to_s #=> "http://xmlns.com/foaf/0.1/name" | |
soln.get("o").to_s #=> "Tom Morris" | |
soln.get("o").class #=> Java::ComHpHplJenaRdfModelImpl::LiteralImpl | |
soln.get("p").class #=> Java::ComHpHplJenaRdfModelImpl::PropertyImpl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "java" | |
require "jena.jar" | |
require "arq-extra.jar" | |
require "arq.jar" | |
require "icu4j_3_4.jar" | |
require "iri.jar" | |
require "jenatest.jar" | |
require "json.jar" | |
require "junit-4.5.jar" | |
require "log4j-1.2.12.jar" | |
require "lucene-core-2.3.1.jar" | |
require "slf4j-api-1.5.6.jar" | |
require "slf4j-log4j12-1.5.6.jar" | |
require "stax-api-1.0.jar" | |
require "wstx-asl-3.0.0.jar" | |
require "xercesImpl.jar" | |
include_class "com.hp.hpl.jena.rdf.model.ModelFactory" | |
include_class "com.hp.hpl.jena.query.Query" | |
include_class "com.hp.hpl.jena.query.QueryFactory" | |
include_class "com.hp.hpl.jena.query.QueryExecutionFactory" | |
include_class "com.hp.hpl.jena.query.QueryExecution" | |
include_class "com.hp.hpl.jena.query.ResultSet" | |
include_class "com.hp.hpl.jena.query.QuerySolution" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment