jena

How can I easily convert RDF triples to/from an idiomatic Java POJO business object?

谁都会走 提交于 2019-11-29 12:05:32
I'm a Java developer just getting started with linked data/RDF. I can create triples, put them in a triple store, query them, etc, but it's very awkward. Most of my code is focused on the mechanics of RDF and I'd really like to work with this data in a way that's more idiomatic Java. How can I convert a POJO to/from RDF triples with Jena without hand-coding everything? I'd like something that can convert a pile of triples with a defined structure back and forth between a Java POJO and RDF. Like JAXB or and ORM does for XML and a relational database, respectively. Also, I can't be locked in too

Using Jena to create a SPARQL query on DBpedia

谁说胖子不能爱 提交于 2019-11-29 04:07:30
Im trying to create a SPARQL query using Jena to query DBpedia. The query is working when I use it with standalone tools (Twinkle) but when I plug it in this Java code it returns an empty set. String sparqlQueryString1 = "PREFIX dbont: <http://dbpedia.org/ontology/> " + "PREFIX dbp: <http://dbpedia.org/property/>" + "PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>" + " SELECT ?musician ?place" + " FROM<http://dbpedia.org/resource/Daphne_Oram>" + " WHERE { " + " ?musician dbont:birthPlace ?place ." + " }"; Query query = QueryFactory.create(sparqlQueryString1); QueryExecution qexec =

How to write SPARQL query that efficiently matches string literals while ignoring case

回眸只為那壹抹淺笑 提交于 2019-11-29 03:33:28
I am using Jena ARQ to write a SPARQL query against a large ontology being read from Jena TDB in order to find the types associated with concepts based on rdfs label: SELECT DISTINCT ?type WHERE { ?x <http://www.w3.org/2000/01/rdf-schema#label> "aspirin" . ?x <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> ?type . } This works pretty well and is actually quite speedy (<1 second). Unfortunately, for some terms, I need to perform this query in a case-insensitive way. For instance, because the label "Tylenol" is in the ontology, but not "tylenol" , the following query comes up empty: SELECT

Import RDF (XML or Turtle) into Neo4j

这一生的挚爱 提交于 2019-11-29 00:42:50
i downloaded the Database dump of Freebase. The format of the file is rdf turtle. I need to get all the data into the neo4j database. I already wrote an importer with help of tinkerpop.blueprints. First it seemed to work but after 30 minutes of importing an exception occured because the rdf file contained characters at positions where they are not allowed to be. A little bit later (after some investigation) i found out that the jena parser i used (RDFReader) is deprecated and shouldnt be used. What i need to know now: Is there any way to import that rdf file into neo4j? Jena is able to

Parsing schema.org ttl/owl file using Jena

末鹿安然 提交于 2019-11-28 14:30:42
I'm writing a code generator that generate entities (POJO's in Java language) from the schema defined here http://schema.rdfs.org/all.ttl . I'm using Jena to parse the ttl file and retrieve the meta data that I need to generate them. Jena parses the file successfully, however, for some reason it does not list all the attributes of a given entity, e.g., Person. I'm not sure whether I'm doing something wrong, using the wrong API, etc. Here's the code sample that recreates the scenario: public class PersonParser { public static void main(String[] args) { OntModel model = ModelFactory

SPARQL - Insert data from remote endpoint

不问归期 提交于 2019-11-28 11:33:22
问题 How can i query a remote endpoint (like endpoints of DBPedia or Wikidata) and insert resulting triples in a local graph? So far, i know that there are commands like INSERT, ADD, COPY etc. which can be used for such tasks. What i don't understand is how to address a remote endpoint while updating my local graph. Could someone provide a minimum example or the main steps? I'm using Apache Jena Fuseki v2 on Windows and this is my query so far: PREFIX wdt: <http://www.wikidata.org/prop/direct/>

Jena TDB java.lang.ExceptionInInitializerError

守給你的承諾、 提交于 2019-11-28 11:32:28
I'm using Jena TDB for loading an RDF dataset and making SPARQL queries against it. I'm using the following maven dependency: <dependency> <groupId>org.apache.jena</groupId> <artifactId>apache-jena-libs</artifactId> <type>pom</type> <version>3.0.1</version> </dependency> And here's the java code where I'm trying to create a TDB dataset: public void loadDirectory(String outputFile){ Dataset dataset = TDBFactory.createDataset(directoryPath); Model tdb = dataset.getDefaultModel(); FileManager.get().readModel(tdb, outputFile); tdb.close(); dataset.close(); LOG.info("RDF dataset loaded to memory");

RDF list subjects with their objects in a single line

别说谁变了你拦得住时间么 提交于 2019-11-28 08:57:17
问题 I have an RDF file and I need to extract some information from it and write it to a file. I understood how it basically works, but I'm stuck with this: String queryString = "select ?person ?children where { ?person ?hasChildren ?children}"; TupleQuery tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, queryString); TupleQueryResult result = tupleQuery.evaluate(); while (result.hasNext()) { BindingSet bindingSet = result.next(); Value p1 = bindingSet.getValue("person"); Value p2 =

Unresolved prefixed name: rdfs:subClassOf in SPARQL query

对着背影说爱祢 提交于 2019-11-28 08:48:18
问题 import java.awt.*; import java.awt.event.*; import java.applet.*; import java.lang.*; import java.util.regex.*; import java.io.*; import com.hp.hpl.jena.sparql.*; import com.hp.hpl.jena.*; import com.hp.hpl.jena.rdf.model.Model; import com.hp.hpl.jena.rdf.model.ModelFactory; import com.hp.hpl.jena.query.*; import com.hp.hpl.jena.query.QueryExecution; import com.hp.hpl.jena.query.QueryExecutionFactory; import com.hp.hpl.jena.query.QueryFactory; import com.hp.hpl.jena.query.ResultSet; import

Fuseki how to add Pellet reasoner

倾然丶 夕夏残阳落幕 提交于 2019-11-28 06:28:44
问题 I want to use pellet reasoner with my Fuseki 2.3.1 First: I added Pellet reasoner to my config.ttl as this: ja:reasoner [ ja:reasonerClass "org.mindswap.pellet.jena.PelletReasonerFactory";] So now I have to add the jar for Pellet to fuseki This page explains how to add jars (not specificaly pellete) to fuseki https://jena.apache.org/documentation/permissions/example.html So I commet this line exec $JAVA $JVM_ARGS -jar "$JAR" "$@" and I uncommet this line java $JVM_ARGS -cp "$JAR:$APPJAR" org