forked from kevin.shehu/GGD
49 lines
1.8 KiB
Java
49 lines
1.8 KiB
Java
|
|
import org.apache.jena.rdf.model.*;
|
|
import org.apache.jena.vocabulary.*;
|
|
|
|
public class main {
|
|
public static void main (String args[]) {
|
|
|
|
// 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)
|
|
.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(" .");
|
|
}
|
|
}
|
|
}
|
|
|