FIX : RDF Conn Test
parent
e64bf080ff
commit
c4286cf81f
|
@ -1,24 +1,16 @@
|
||||||
import org.apache.jena.query.*;
|
import org.apache.jena.query.Query;
|
||||||
|
import org.apache.jena.query.QueryFactory;
|
||||||
import org.apache.jena.query.ResultSetFormatter;
|
import org.apache.jena.query.ResultSetFormatter;
|
||||||
import org.apache.jena.rdfconnection.RDFConnection;
|
import org.apache.jena.rdfconnection.RDFConnectionFuseki;
|
||||||
import org.apache.jena.rdfconnection.RDFConnectionFactory;
|
import org.apache.jena.rdfconnection.RDFConnectionRemoteBuilder;
|
||||||
import org.apache.jena.system.Txn;
|
|
||||||
|
|
||||||
public class RDFConnectionExample {
|
public class RDFConnectionExample {
|
||||||
public static void main(String ...args) {
|
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, () ->{
|
RDFConnectionRemoteBuilder builder = RDFConnectionFuseki.create()
|
||||||
System.out.println("Load a file");
|
.destination("http://localhost:3030/fuseki");
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,28 +1,48 @@
|
||||||
|
|
||||||
import org.apache.jena.rdf.model.Model;
|
import org.apache.jena.rdf.model.*;
|
||||||
import org.apache.jena.rdf.model.ModelFactory;
|
import org.apache.jena.vocabulary.*;
|
||||||
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[]){
|
public static void main (String args[]) {
|
||||||
String personURI = "http://localhost:8080/JohnSmith";
|
|
||||||
|
// some definitions
|
||||||
|
String personURI = "http://localhost:3030/GGD/JohnSmith";
|
||||||
String givenName = "John";
|
String givenName = "John";
|
||||||
String familyName = "Smith";
|
String familyName = "Smith";
|
||||||
String fullName = givenName + " " + familyName;
|
String fullName = givenName + " " + familyName;
|
||||||
|
|
||||||
// create an empty model
|
// create an empty model
|
||||||
Model model = ModelFactory.createDefaultModel();
|
Model model = ModelFactory.createDefaultModel();
|
||||||
|
|
||||||
// create the resource
|
// create the resource
|
||||||
// and add the properties cascading style
|
// and add the properties cascading style
|
||||||
Resource johnSmith = model.createResource(personURI)
|
Resource johnSmith
|
||||||
|
= model.createResource(personURI)
|
||||||
.addProperty(VCARD.FN, fullName)
|
.addProperty(VCARD.FN, fullName)
|
||||||
.addProperty(VCARD.N,
|
.addProperty(VCARD.N,
|
||||||
model.createResource()
|
model.createResource()
|
||||||
.addProperty(VCARD.Given, givenName)
|
.addProperty(VCARD.Given, givenName)
|
||||||
.addProperty(VCARD.Family, familyName));
|
.addProperty(VCARD.Family, familyName));
|
||||||
|
|
||||||
}
|
// list the statements in the graph
|
||||||
}
|
StmtIterator iter = model.listStatements();
|
||||||
|
|
||||||
|
// print out the predicate, subject and object of each statement
|
||||||
|
while (iter.hasNext()) {
|
||||||
|
Statement stmt = iter.nextStatement(); // get next statement
|
||||||
|
Resource subject = stmt.getSubject(); // get the subject
|
||||||
|
Property predicate = stmt.getPredicate(); // get the predicate
|
||||||
|
RDFNode object = stmt.getObject(); // get the object
|
||||||
|
|
||||||
|
System.out.print(subject.toString());
|
||||||
|
System.out.print(" " + predicate.toString() + " ");
|
||||||
|
if (object instanceof Resource) {
|
||||||
|
System.out.print(object.toString());
|
||||||
|
} else {
|
||||||
|
// object is a literal
|
||||||
|
System.out.print(" \"" + object.toString() + "\"");
|
||||||
|
}
|
||||||
|
System.out.println(" .");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue