From e64bf080ff958c8ccccb81c562564bf6a0d1b2ef Mon Sep 17 00:00:00 2001 From: Kevin Shehu Date: Thu, 17 Sep 2020 16:16:52 +0200 Subject: [PATCH] ADD : RDF Conn Test --- pom.xml | 11 ++++++++++ src/main/java/RDFConnectionExample.java | 24 +++++++++++++++++++++ src/main/java/main.java | 28 ++++++++++++++++++++++++- 3 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 src/main/java/RDFConnectionExample.java diff --git a/pom.xml b/pom.xml index edc019d..5b967ac 100644 --- a/pom.xml +++ b/pom.xml @@ -14,6 +14,17 @@ pom 3.16.0 + + org.apache.jena + jena-fuseki-war + war + 3.16.0 + + + org.apache.jena + jena-fuseki-main + 3.16.0 + diff --git a/src/main/java/RDFConnectionExample.java b/src/main/java/RDFConnectionExample.java new file mode 100644 index 0000000..12a17f6 --- /dev/null +++ b/src/main/java/RDFConnectionExample.java @@ -0,0 +1,24 @@ +import org.apache.jena.query.*; +import org.apache.jena.query.ResultSetFormatter; +import org.apache.jena.rdfconnection.RDFConnection; +import org.apache.jena.rdfconnection.RDFConnectionFactory; +import org.apache.jena.system.Txn; + +public class RDFConnectionExample { + public static void main(String ...args) { + Query query = QueryFactory.create("SELECT * { {?s ?p ?o } UNION { GRAPH ?g { ?s ?p ?o } } }"); + Dataset dataset = DatasetFactory.createTxnMem(); + RDFConnection conn = RDFConnectionFactory.connect(dataset); + + Txn.executeWrite(conn, () ->{ + System.out.println("Load a file"); + conn.load("data.ttl"); + conn.load("http://localhost:3030/GGD", "data.ttl"); + System.out.println("In write transaction"); + conn.queryResultSet(query, ResultSetFormatter::out); + }); + // And again - implicit READ transaction. + System.out.println("After write transaction"); + conn.queryResultSet(query, ResultSetFormatter::out); + } +} diff --git a/src/main/java/main.java b/src/main/java/main.java index abaa52d..a3edf58 100644 --- a/src/main/java/main.java +++ b/src/main/java/main.java @@ -1,2 +1,28 @@ + +import org.apache.jena.rdf.model.Model; +import org.apache.jena.rdf.model.ModelFactory; +import org.apache.jena.rdf.model.Resource; +import org.apache.jena.vocabulary.VCARD; + public class main { -} + public static void main(String args[]){ + String personURI = "http://localhost:8080/JohnSmith"; + String givenName = "John"; + String familyName = "Smith"; + String fullName = givenName + " " + familyName; + + // create an empty model + Model model = ModelFactory.createDefaultModel(); + + // create the resource + // and add the properties cascading style + Resource johnSmith = model.createResource(personURI) + .addProperty(VCARD.FN, fullName) + .addProperty(VCARD.N, + model.createResource() + .addProperty(VCARD.Given, givenName) + .addProperty(VCARD.Family, familyName)); + + } + } +