KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > hp > hpl > jena > reasoner > rulesys > test > TestRDFS9


1 /******************************************************************
2  * File: TestRDFS9.java
3  * Created by: Dave Reynolds
4  * Created on: 24-Jun-2003
5  *
6  * (c) Copyright 2003, 2004, 2005 Hewlett-Packard Development Company, LP
7  * [See end of file]
8  * $Id: TestRDFS9.java,v 1.4 2005/02/21 12:18:13 andy_seaborne Exp $
9  *****************************************************************/

10 package com.hp.hpl.jena.reasoner.rulesys.test;
11
12 import com.hp.hpl.jena.graph.*;
13 import com.hp.hpl.jena.graph.compose.Union;
14 import com.hp.hpl.jena.mem.GraphMem;
15 import com.hp.hpl.jena.reasoner.*;
16 import com.hp.hpl.jena.reasoner.test.TestUtil;
17 import com.hp.hpl.jena.vocabulary.*;
18
19 import java.util.*;
20
21 import junit.framework.TestCase;
22 import junit.framework.TestSuite;
23
24 /**
25  * Test harness used in debugging some issues with execution
26  * of modified versions of rule rdfs9.
27  *
28  * @author <a HREF="mailto:der@hplb.hpl.hp.com">Dave Reynolds</a>
29  * @version $Revision: 1.4 $ on $Date: 2005/02/21 12:18:13 $
30  */

31 public class TestRDFS9 extends TestCase {
32     
33     /**
34      * Boilerplate for junit
35      */

36     public TestRDFS9( String JavaDoc name ) {
37         super( name );
38     }
39     
40     /**
41      * Boilerplate for junit.
42      * This is its own test suite
43      */

44     public static TestSuite suite() {
45         return new TestSuite(TestRDFS9.class);
46     }
47
48     /**
49      * Test a type inheritance example.
50      */

51     public void testRDFSInheritance() {
52         Node C1 = Node.createURI("C1");
53         Node C2 = Node.createURI("C2");
54         Node C3 = Node.createURI("C3");
55         Node C4 = Node.createURI("C4");
56         Node D = Node.createURI("D");
57         Node a = Node.createURI("a");
58         Node b = Node.createURI("b");
59         Node p = Node.createURI("p");
60         Node q = Node.createURI("q");
61         Node r = Node.createURI("r");
62         Node sC = RDFS.subClassOf.asNode();
63         Node ty = RDF.type.asNode();
64         
65         Graph tdata = new GraphMem();
66         tdata.add(new Triple(C1, sC, C2));
67         tdata.add(new Triple(C2, sC, C3));
68         tdata.add(new Triple(p, RDFS.subPropertyOf.asNode(), q));
69         tdata.add(new Triple(q, RDFS.subPropertyOf.asNode(), r));
70         tdata.add(new Triple(r, RDFS.domain.asNode(), D));
71         Graph data = new GraphMem();
72         data.add(new Triple(a, p, b));
73         InfGraph igraph = ReasonerRegistry.getRDFSReasoner().bind(new Union(tdata, data));
74         TestUtil.assertIteratorValues(this, igraph.find(a, ty, null),
75         new Object JavaDoc[] {
76             new Triple(a, ty, D),
77             new Triple(a, ty, RDFS.Resource.asNode()),
78         });
79         // Check if first of these is in the wildcard listing
80
boolean ok = false;
81         Triple target = new Triple(a,ty,D);
82         for (Iterator i = igraph.find(null,ty,null); i.hasNext(); ) {
83             Triple t = (Triple)i.next();
84             if (t.equals(target)) {
85                 ok = true;
86                 break;
87             }
88         }
89         assertTrue(ok);
90         igraph = ReasonerRegistry.getRDFSReasoner().bindSchema(tdata).bind(data);
91         TestUtil.assertIteratorValues(this, igraph.find(a, ty, null),
92         new Object JavaDoc[] {
93             new Triple(a, ty, D),
94             new Triple(a, ty, RDFS.Resource.asNode()),
95         });
96         // Check if first of these is in the wildcard listing
97
ok = false;
98         target = new Triple(a,ty,D);
99         for (Iterator i = igraph.find(null,ty,null); i.hasNext(); ) {
100             Triple t = (Triple)i.next();
101             if (t.equals(target)) {
102                 ok = true;
103                 break;
104             }
105         }
106         assertTrue(ok);
107     }
108 }
109
110
111 /*
112     (c) Copyright 2003, 2004, 2005 Hewlett-Packard Development Company, LP
113     All rights reserved.
114
115     Redistribution and use in source and binary forms, with or without
116     modification, are permitted provided that the following conditions
117     are met:
118
119     1. Redistributions of source code must retain the above copyright
120        notice, this list of conditions and the following disclaimer.
121
122     2. Redistributions in binary form must reproduce the above copyright
123        notice, this list of conditions and the following disclaimer in the
124        documentation and/or other materials provided with the distribution.
125
126     3. The name of the author may not be used to endorse or promote products
127        derived from this software without specific prior written permission.
128
129     THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
130     IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
131     OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
132     IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
133     INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
134     NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
135     DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
136     THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
137     (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
138     THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
139 */
Popular Tags