01: /*
02: * (c) Copyright 2003, 2004, Hewlett-Packard Development Company, LP
03: * All rights reserved.
04: * [See end of file]
05: * $Id: Tutorial08.java,v 1.3 2005/10/06 17:49:05 andy_seaborne Exp $
06: */
07: package jena.examples.rdf;
08:
09: 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.*;
14:
15: /** Tutorial 8 - demonstrate Selector methods
16: *
17: * @author bwm - updated by kers/Daniel
18: * @version Release='$Name: $' Revision='$Revision: 1.3 $' Date='$Date: 2005/10/06 17:49:05 $'
19: */
20: public class Tutorial08 extends Object {
21:
22: static final String inputFileName = "vc-db-1.rdf";
23:
24: public static void main(String args[]) {
25: // create an empty model
26: Model model = ModelFactory.createDefaultModel();
27:
28: // use the FileManager to find the input file
29: InputStream in = FileManager.get().open(inputFileName);
30: if (in == null) {
31: throw new IllegalArgumentException("File: " + inputFileName
32: + " not found");
33: }
34:
35: // read the RDF/XML file
36: model.read(in, "");
37:
38: // select all the resources with a VCARD.FN property
39: // whose value ends with "Smith"
40: StmtIterator iter = model.listStatements(new SimpleSelector(
41: null, VCARD.FN, (RDFNode) null) {
42: public boolean selects(Statement s) {
43: return s.getString().endsWith("Smith");
44: }
45: });
46: if (iter.hasNext()) {
47: System.out.println("The database contains vcards for:");
48: while (iter.hasNext()) {
49: System.out.println(" "
50: + iter.nextStatement().getString());
51: }
52: } else {
53: System.out.println("No Smith's were found in the database");
54: }
55: }
56: }
57:
58: /*
59: * (c) Copyright 2003, 2004 Hewlett-Packard Development Company, LP
60: * All rights reserved.
61: *
62: * Redistribution and use in source and binary forms, with or without
63: * modification, are permitted provided that the following conditions
64: * are met:
65: * 1. Redistributions of source code must retain the above copyright
66: * notice, this list of conditions and the following disclaimer.
67: * 2. Redistributions in binary form must reproduce the above copyright
68: * notice, this list of conditions and the following disclaimer in the
69: * documentation and/or other materials provided with the distribution.
70: * 3. The name of the author may not be used to endorse or promote products
71: * derived from this software without specific prior written permission.
72: *
73: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
74: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
75: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
76: * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
77: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
78: * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
79: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
80: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
81: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
82: * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
83: */
|