ADD : RDF Conn Test

master
Kevin Shehu 2020-09-17 16:16:52 +02:00
parent 319a236dd0
commit e64bf080ff
3 changed files with 62 additions and 1 deletions

11
pom.xml
View File

@ -14,6 +14,17 @@
<type>pom</type> <type>pom</type>
<version>3.16.0</version> <version>3.16.0</version>
</dependency> </dependency>
<dependency>
<groupId>org.apache.jena</groupId>
<artifactId>jena-fuseki-war</artifactId>
<type>war</type>
<version>3.16.0</version>
</dependency>
<dependency>
<groupId>org.apache.jena</groupId>
<artifactId>jena-fuseki-main</artifactId>
<version>3.16.0</version>
</dependency>
</dependencies> </dependencies>

View File

@ -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);
}
}

View File

@ -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 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));
} }
}