1 7 package jena.examples.rdf ; 8 9 import com.hp.hpl.jena.rdf.model.*; 10 import com.hp.hpl.jena.vocabulary.*; 11 12 13 18 public class Tutorial03 extends Object { 19 public static void main (String args[]) { 20 21 String personURI = "http://somewhere/JohnSmith"; 23 String givenName = "John"; 24 String familyName = "Smith"; 25 String fullName = givenName + " " + familyName; 26 Model model = ModelFactory.createDefaultModel(); 28 29 Resource johnSmith 32 = model.createResource(personURI) 33 .addProperty(VCARD.FN, fullName) 34 .addProperty(VCARD.N, 35 model.createResource() 36 .addProperty(VCARD.Given, givenName) 37 .addProperty(VCARD.Family, familyName)); 38 39 StmtIterator iter = model.listStatements(); 41 42 while (iter.hasNext()) { 44 Statement stmt = iter.nextStatement(); Resource subject = stmt.getSubject(); Property predicate = stmt.getPredicate(); RDFNode object = stmt.getObject(); 49 System.out.print(subject.toString()); 50 System.out.print(" " + predicate.toString() + " "); 51 if (object instanceof Resource) { 52 System.out.print(object.toString()); 53 } else { 54 System.out.print(" \"" + object.toString() + "\""); 56 } 57 System.out.println(" ."); 58 } 59 } 60 } 61 62 88 | Popular Tags |