01: /*
02: * (c) Copyright 2003, 2004, Hewlett-Packard Development Company, LP
03: * All rights reserved.
04: * [See end of file]
05: * $Id: Tutorial03.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.vocabulary.*;
11:
12: /** Tutorial 3 Statement attribute accessor methods
13: *
14: * @author bwm - updated by kers/Daniel
15: * @version Release='$Name: $' Revision='$Revision: 1.3 $' Date='$Date: 2005/10/06 17:49:05 $'
16: */
17: public class Tutorial03 extends Object {
18: public static void main(String args[]) {
19:
20: // some definitions
21: String personURI = "http://somewhere/JohnSmith";
22: String givenName = "John";
23: String familyName = "Smith";
24: String fullName = givenName + " " + familyName;
25: // create an empty model
26: Model model = ModelFactory.createDefaultModel();
27:
28: // create the resource
29: // and add the properties cascading style
30: Resource johnSmith = model.createResource(personURI)
31: .addProperty(VCARD.FN, fullName).addProperty(
32: VCARD.N,
33: model.createResource().addProperty(VCARD.Given,
34: givenName).addProperty(VCARD.Family,
35: familyName));
36:
37: // list the statements in the graph
38: StmtIterator iter = model.listStatements();
39:
40: // print out the predicate, subject and object of each statement
41: while (iter.hasNext()) {
42: Statement stmt = iter.nextStatement(); // get next statement
43: Resource subject = stmt.getSubject(); // get the subject
44: Property predicate = stmt.getPredicate(); // get the predicate
45: RDFNode object = stmt.getObject(); // get the object
46:
47: System.out.print(subject.toString());
48: System.out.print(" " + predicate.toString() + " ");
49: if (object instanceof Resource) {
50: System.out.print(object.toString());
51: } else {
52: // object is a literal
53: System.out.print(" \"" + object.toString() + "\"");
54: }
55: System.out.println(" .");
56: }
57: }
58: }
59:
60: /*
61: * (c) Copyright 2003, 2004 Hewlett-Packard Development Company, LP
62: * All rights reserved.
63: *
64: * Redistribution and use in source and binary forms, with or without
65: * modification, are permitted provided that the following conditions
66: * are met:
67: * 1. Redistributions of source code must retain the above copyright
68: * notice, this list of conditions and the following disclaimer.
69: * 2. Redistributions in binary form must reproduce the above copyright
70: * notice, this list of conditions and the following disclaimer in the
71: * documentation and/or other materials provided with the distribution.
72: * 3. The name of the author may not be used to endorse or promote products
73: * derived from this software without specific prior written permission.
74: *
75: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
76: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
77: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
78: * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
79: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
80: * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
81: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
82: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
83: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
84: * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
85: */
|