1 7 package jena.examples.rdf ; 8 9 import com.hp.hpl.jena.rdf.model.*; 10 import com.hp.hpl.jena.util.FileManager; 11 import com.hp.hpl.jena.vocabulary.*; 12 13 import java.io.InputStream ; 14 import java.io.InputStreamReader ; 15 import java.io.PrintWriter ; 16 17 22 public class Tutorial10 extends Object { 23 24 static final String inputFileName = "vc-db-1.rdf"; 25 26 public static void main (String args[]) { 27 Model model = ModelFactory.createDefaultModel(); 29 30 InputStream in = FileManager.get().open( inputFileName ); 32 if (in == null) { 33 throw new IllegalArgumentException ( "File: " + inputFileName + " not found"); 34 } 35 36 model.read(new InputStreamReader (in), ""); 38 39 Bag smiths = model.createBag(); 41 42 StmtIterator iter = model.listStatements( 45 new 46 SimpleSelector(null, VCARD.FN, (RDFNode) null) { 47 public boolean selects(Statement s) { 48 return s.getString().endsWith("Smith"); 49 } 50 }); 51 while (iter.hasNext()) { 53 smiths.add( iter.nextStatement().getSubject()); 54 } 55 56 model.write(new PrintWriter (System.out)); 58 System.out.println(); 59 60 NodeIterator iter2 = smiths.iterator(); 62 if (iter2.hasNext()) { 63 System.out.println("The bag contains:"); 64 while (iter2.hasNext()) { 65 System.out.println(" " + 66 ((Resource) iter2.next()) 67 .getRequiredProperty(VCARD.FN) 68 .getString()); 69 } 70 } else { 71 System.out.println("The bag is empty"); 72 } 73 } 74 } 75 76 102 | Popular Tags |