Source Code Cross Referenced for TestRDFSReasoners.java in  » RSS-RDF » Jena-2.5.5 » com » hp » hpl » jena » reasoner » test » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » RSS RDF » Jena 2.5.5 » com.hp.hpl.jena.reasoner.test 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /******************************************************************
002:         * File:        TestRDFSReasoner.java
003:         * Created by:  Dave Reynolds
004:         * Created on:  19-Jun-2003
005:         * 
006:         * (c) Copyright 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
007:         * [See end of file]
008:         * $Id: TestRDFSReasoners.java,v 1.18 2008/01/02 12:08:31 andy_seaborne Exp $
009:         *****************************************************************/package com.hp.hpl.jena.reasoner.test;
010:
011:        //import com.hp.hpl.jena.reasoner.rdfsReasoner1.*;
012:        import com.hp.hpl.jena.reasoner.rulesys.RDFSRuleReasonerFactory;
013:        import com.hp.hpl.jena.reasoner.rulesys.RDFSFBRuleReasonerFactory;
014:        import com.hp.hpl.jena.reasoner.*;
015:        import com.hp.hpl.jena.rdf.model.*;
016:        import com.hp.hpl.jena.vocabulary.*;
017:
018:        import java.io.*;
019:        import java.util.Iterator;
020:
021:        import junit.framework.TestCase;
022:        import junit.framework.TestSuite;
023:
024:        import org.apache.commons.logging.Log;
025:        import org.apache.commons.logging.LogFactory;
026:
027:        /**
028:         * Test the set of admissable RDFS reasoners.
029:         * 
030:         * @author <a href="mailto:der@hplb.hpl.hp.com">Dave Reynolds</a>
031:         * @version $Revision: 1.18 $ on $Date: 2008/01/02 12:08:31 $
032:         */
033:        public class TestRDFSReasoners extends ReasonerTestBase {
034:
035:            /** Base URI for the test names */
036:            public static final String NAMESPACE = "http://www.hpl.hp.com/semweb/2003/query_tester/";
037:
038:            protected static Log logger = LogFactory
039:                    .getLog(TestReasoners.class);
040:
041:            /**
042:             * Boilerplate for junit
043:             */
044:            public TestRDFSReasoners(String name) {
045:                super (name);
046:            }
047:
048:            /**
049:             * Boilerplate for junit.
050:             * This is its own test suite
051:             */
052:            public static TestSuite suite() {
053:                TestSuite suite = new TestSuite();
054:                try {
055:                    // Even though it is deprecated, maintain the tests for now
056:                    //            constructRDFWGtests(suite, RDFSReasonerFactory.theInstance(), null);
057:                    //            constructQuerytests(suite, "rdfs/manifest.rdf", RDFSReasonerFactory.theInstance(), null);
058:
059:                    // FB reasoner doesn't support validation so the full set of wg tests are
060:                    // commented out            
061:                    //            constructRDFWGtests(suite, RDFSFBRuleReasonerFactory.theInstance(), null);
062:                    constructQuerytests(suite,
063:                            "rdfs/manifest-nodirect-noresource.rdf",
064:                            RDFSFBRuleReasonerFactory.theInstance(), null);
065:
066:                    Resource config = newResource().addProperty(
067:                            ReasonerVocabulary.PROPenableCMPScan, "true"); // TODO make boolean value work
068:                    //            config.addProperty(ReasonerVocabulary.PROPtraceOn, true);
069:                    constructRDFWGtests(suite, RDFSRuleReasonerFactory
070:                            .theInstance(), null);
071:                    constructQuerytests(suite, "rdfs/manifest-standard.rdf",
072:                            RDFSRuleReasonerFactory.theInstance(), config);
073:
074:                    suite.addTest(new TestRDFSMisc(RDFSRuleReasonerFactory
075:                            .theInstance(), null));
076:
077:                    Resource configFull = newResource().addProperty(
078:                            ReasonerVocabulary.PROPsetRDFSLevel,
079:                            ReasonerVocabulary.RDFS_FULL);
080:                    constructQuerytests(suite, "rdfs/manifest.rdf",
081:                            RDFSRuleReasonerFactory.theInstance(), configFull);
082:
083:                    // This test was needed for the brief time the rdfs12 rules might have been in the standard
084:                    // That's no longer true but left comment out because we might want them for OWL someday
085:                    //            constructQuerytests(suite, "rdfs/manifest-rdfs12.rdf", RDFSRuleReasonerFactory.theInstance(), configFull);
086:
087:                    Resource configSimple = newResource().addProperty(
088:                            ReasonerVocabulary.PROPsetRDFSLevel,
089:                            ReasonerVocabulary.RDFS_SIMPLE);
090:                    constructQuerytests(suite, "rdfs/manifest-simple.rdf",
091:                            RDFSRuleReasonerFactory.theInstance(), configSimple);
092:
093:                    // Single test case used in debugging, subsumed by above
094:                    //            constructSingleQuerytests(suite, 
095:                    //                                      "rdfs/manifest.rdf", 
096:                    //                                      "http://www.hpl.hp.com/semweb/2003/query_tester/rdfs/test13", 
097:                    //                                      RDFSRuleReasonerFactory.theInstance(), 
098:                    //                                      configFull);
099:
100:                } catch (IOException e) {
101:                    // failed to even built the test harness
102:                    logger.error("Failed to construct RDFS test harness", e);
103:                }
104:                return suite;
105:            }
106:
107:            /**
108:             * Build a single named query test
109:             */
110:            private static void constructSingleQuerytests(TestSuite suite,
111:                    String manifest, String test, ReasonerFactory rf,
112:                    Resource config) throws IOException {
113:                ReasonerTester tester = new ReasonerTester(manifest);
114:                Reasoner r = rf.create(config);
115:                suite.addTest(new TestReasonerFromManifest(tester, test, r));
116:            }
117:
118:            /**
119:             * Build the query tests for the given reasoner.
120:             */
121:            private static void constructQuerytests(TestSuite suite,
122:                    String manifest, ReasonerFactory rf, Resource config)
123:                    throws IOException {
124:                ReasonerTester tester = new ReasonerTester(manifest);
125:                Reasoner r = rf.create(config);
126:                for (Iterator i = tester.listTests().iterator(); i.hasNext();) {
127:                    String test = (String) i.next();
128:                    suite
129:                            .addTest(new TestReasonerFromManifest(tester, test,
130:                                    r));
131:                }
132:            }
133:
134:            /**
135:             * Build the working group tests for the given reasoner.
136:             */
137:            private static void constructRDFWGtests(TestSuite suite,
138:                    ReasonerFactory rf, Resource config) throws IOException {
139:                WGReasonerTester tester = new WGReasonerTester("Manifest.rdf");
140:                for (Iterator i = tester.listTests().iterator(); i.hasNext();) {
141:                    String test = (String) i.next();
142:                    suite.addTest(new TestReasonerWG(tester, test, rf, config));
143:                }
144:            }
145:
146:            /**
147:             * Build the query tests for the given reasoner.
148:             */
149:            public static void constructQuerytests(TestSuite suite,
150:                    String manifest, Reasoner reasoner) throws IOException {
151:                ReasonerTester tester = new ReasonerTester(manifest);
152:                for (Iterator i = tester.listTests().iterator(); i.hasNext();) {
153:                    String test = (String) i.next();
154:                    suite.addTest(new TestReasonerFromManifest(tester, test,
155:                            reasoner));
156:                }
157:            }
158:
159:            /**
160:             * Inner class defining a test framework for invoking a single locally
161:             * defined query-over-inference test.
162:             */
163:            static class TestReasonerFromManifest extends TestCase {
164:
165:                /** The tester which already has the test manifest loaded */
166:                ReasonerTester tester;
167:
168:                /** The name of the specific test to run */
169:                String test;
170:
171:                /** The factory for the reasoner type under test */
172:                Reasoner reasoner;
173:
174:                /** Constructor */
175:                TestReasonerFromManifest(ReasonerTester tester, String test,
176:                        Reasoner reasoner) {
177:                    super (test);
178:                    this .tester = tester;
179:                    this .test = test;
180:                    this .reasoner = reasoner;
181:                }
182:
183:                /**
184:                 * The test runner
185:                 */
186:                public void runTest() throws IOException {
187:                    tester.runTest(test, reasoner, this );
188:                }
189:
190:            }
191:
192:            /**
193:             * Inner class defining a test framework for invoking a single 
194:             * RDFCore working group test.
195:             */
196:            static class TestReasonerWG extends TestCase {
197:
198:                /** The tester which already has the test manifest loaded */
199:                WGReasonerTester tester;
200:
201:                /** The name of the specific test to run */
202:                String test;
203:
204:                /** The factory for the reasoner type under test */
205:                ReasonerFactory reasonerFactory;
206:
207:                /** An optional configuration model */
208:                Resource config;
209:
210:                /** Constructor */
211:                TestReasonerWG(WGReasonerTester tester, String test,
212:                        ReasonerFactory reasonerFactory, Resource config) {
213:                    super (test);
214:                    this .tester = tester;
215:                    this .test = test;
216:                    this .reasonerFactory = reasonerFactory;
217:                    this .config = config;
218:                }
219:
220:                /**
221:                 * The test runner
222:                 */
223:                public void runTest() throws IOException {
224:                    tester.runTest(test, reasonerFactory, this , config);
225:                }
226:
227:            }
228:
229:            /**
230:             * Inner class defining the misc extra tests needed to check out a
231:             * candidate RDFS reasoner.
232:             */
233:            static class TestRDFSMisc extends TestCase {
234:
235:                /** The factory for the reasoner type under test */
236:                ReasonerFactory reasonerFactory;
237:
238:                /** An optional configuration model */
239:                Resource config;
240:
241:                /** Constructor */
242:                TestRDFSMisc(ReasonerFactory reasonerFactory, Resource config) {
243:                    super ("TestRDFSMisc");
244:                    this .reasonerFactory = reasonerFactory;
245:                    this .config = config;
246:                }
247:
248:                /**
249:                 * The test runner
250:                 */
251:                public void runTest() throws IOException {
252:                    ReasonerTester tester = new ReasonerTester(
253:                            "rdfs/manifest.rdf");
254:                    // Test effect of switching off property scan - should break container property test case
255:                    Resource configuration = newResource();
256:                    if (config != null) {
257:                        for (StmtIterator i = config.listProperties(); i
258:                                .hasNext();) {
259:                            Statement s = i.nextStatement();
260:                            configuration.addProperty(s.getPredicate(), s
261:                                    .getObject());
262:                        }
263:                    }
264:                    configuration.addProperty(
265:                            ReasonerVocabulary.PROPenableCMPScan, "false");
266:                    assertTrue("scanproperties off", !tester.runTest(NAMESPACE
267:                            + "rdfs/test17", reasonerFactory, null,
268:                            configuration));
269:
270:                    // Check capabilities description
271:                    Reasoner r = reasonerFactory.create(null);
272:                    assertTrue(r.supportsProperty(RDFS.subClassOf));
273:                    assertTrue(r.supportsProperty(RDFS.domain));
274:                    assertTrue(r.supportsProperty(RDFS.range));
275:
276:                    // Datatype tests
277:                    assertTrue(!doTestRDFSDTRange("dttest1.nt", reasonerFactory));
278:                    assertTrue(!doTestRDFSDTRange("dttest2.nt", reasonerFactory));
279:                    assertTrue(doTestRDFSDTRange("dttest3.nt", reasonerFactory));
280:                }
281:
282:                /**
283:                 * Helper for dt range testing - loads a file, validates it using RDFS/DT
284:                 * and returns error status of the result
285:                 */
286:                private boolean doTestRDFSDTRange(String file,
287:                        ReasonerFactory rf) throws IOException {
288:                    String langType = "RDF/XML";
289:                    if (file.endsWith(".nt")) {
290:                        langType = "N-TRIPLE";
291:                    } else if (file.endsWith("n3")) {
292:                        langType = "N3";
293:                    }
294:                    Model m = ModelFactory.createNonreifyingModel();
295:                    Reader reader = new BufferedReader(new FileReader(
296:                            "testing/reasoners/rdfs/" + file));
297:                    m.read(reader, WGReasonerTester.BASE_URI + file, langType);
298:                    InfGraph g = rf.create(null).bind(m.getGraph());
299:                    ValidityReport report = g.validate();
300:                    if (!report.isValid()) {
301:                        logger.debug("Validation error report:");
302:                        for (Iterator i = report.getReports(); i.hasNext();) {
303:                            logger.debug(i.next().toString());
304:                        }
305:                    }
306:                    return report.isValid();
307:                }
308:
309:            }
310:
311:        }
312:
313:        /*
314:         (c) Copyright 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
315:         All rights reserved.
316:
317:         Redistribution and use in source and binary forms, with or without
318:         modification, are permitted provided that the following conditions
319:         are met:
320:
321:         1. Redistributions of source code must retain the above copyright
322:         notice, this list of conditions and the following disclaimer.
323:
324:         2. Redistributions in binary form must reproduce the above copyright
325:         notice, this list of conditions and the following disclaimer in the
326:         documentation and/or other materials provided with the distribution.
327:
328:         3. The name of the author may not be used to endorse or promote products
329:         derived from this software without specific prior written permission.
330:
331:         THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
332:         IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
333:         OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
334:         IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
335:         INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
336:         NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
337:         DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
338:         THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
339:         (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
340:         THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
341:         */
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.