forked from kevin.shehu/GGD
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.rdfconnection.RDFConnection;
|
||||
import org.apache.jena.rdfconnection.RDFConnectionFactory;
|
||||
import org.apache.jena.system.Txn;
|
||||
import org.apache.jena.rdfconnection.RDFConnectionFuseki;
|
||||
import org.apache.jena.rdfconnection.RDFConnectionRemoteBuilder;
|
||||
|
||||
|
||||
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);
|
||||
RDFConnectionRemoteBuilder builder = RDFConnectionFuseki.create()
|
||||
.destination("http://localhost:3030/fuseki");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,28 +1,48 @@
|
|||
|
||||
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;
|
||||
import org.apache.jena.rdf.model.*;
|
||||
import org.apache.jena.vocabulary.*;
|
||||
|
||||
public class main {
|
||||
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 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)
|
||||
Resource johnSmith
|
||||
= model.createResource(personURI)
|
||||
.addProperty(VCARD.FN, fullName)
|
||||
.addProperty(VCARD.N,
|
||||
model.createResource()
|
||||
.addProperty(VCARD.Given, givenName)
|
||||
.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