001: /*
002: (c) Copyright 2007, 2008 Hewlett-Packard Development Company, LP
003: All rights reserved.
004: $Id: TestRestrictionsDontNeedTyping.java,v 1.4 2008/01/02 12:08:19 andy_seaborne Exp $
005: */
006:
007: package com.hp.hpl.jena.reasoner.rulesys.test;
008:
009: import com.hp.hpl.jena.ontology.*;
010: import com.hp.hpl.jena.rdf.model.*;
011: import com.hp.hpl.jena.rdf.model.test.ModelTestBase;
012: import com.hp.hpl.jena.shared.PrefixMapping;
013: import com.hp.hpl.jena.vocabulary.*;
014:
015: /**
016: Test that restriction inference works even when the restriction isn't given an
017: explicit type (ie we're not caught in a forward rule -> backward rule
018: layering problem).
019:
020: @author kers
021: */
022: public class TestRestrictionsDontNeedTyping extends ModelTestBase {
023: static final Property ANY = null;
024:
025: public TestRestrictionsDontNeedTyping(String name) {
026: super (name);
027: }
028:
029: public void testAllValuesFromFullRules() {
030: testAllValuesFrom(OntModelSpec.OWL_MEM_RULE_INF);
031: }
032:
033: public void testAllValuesFromMiniRules() {
034: testAllValuesFrom(OntModelSpec.OWL_MEM_MINI_RULE_INF);
035: }
036:
037: public void testAllValuesFromMicroRules() {
038: /* micro doesn't support this anyway */
039: // testAllValuesFrom( OntModelSpec.OWL_MEM_MICRO_RULE_INF );
040: }
041:
042: private void testAllValuesFrom(OntModelSpec owlSpec) {
043: Model m = model("V owl:equivalentClass _R; _R owl:onProperty P; _R owl:allValuesFrom T; X rdf:type V; X P t");
044: OntModel ont = ModelFactory.createOntologyModel(owlSpec, m);
045: assertTrue(ont.contains(resource("t"), RDF.type, resource("T")));
046: }
047:
048: public void testSomeValuesFromMiniRules() {
049: testSomeValuesFrom(OntModelSpec.OWL_MEM_MINI_RULE_INF);
050: }
051:
052: public void testSomeValuesFromMicroRules() {
053: testSomeValuesFrom(OntModelSpec.OWL_MEM_MICRO_RULE_INF);
054: }
055:
056: public void testSomeValuesFromFullRules() {
057: testSomeValuesFrom(OntModelSpec.OWL_MEM_RULE_INF);
058: }
059:
060: private void testSomeValuesFrom(OntModelSpec owlSpec) {
061: Model m = model("V owl:equivalentClass _R; _R owl:onProperty P; _R owl:someValuesFrom T; X P t; t rdf:type T");
062: OntModel ont = ModelFactory.createOntologyModel(owlSpec, m);
063: assertTrue(ont.contains(resource("X"), RDF.type, resource("V")));
064: }
065:
066: public void testCardinalityFullRules() {
067: testCardinality(OntModelSpec.OWL_MEM_RULE_INF);
068: }
069:
070: // public void testCardinalityMiniRules()
071: // { testCardinality( OntModelSpec.OWL_MEM_MINI_RULE_INF ); }
072: //
073: // public void testCardinalityMicroRules()
074: // { testCardinality( OntModelSpec.OWL_MEM_MICRO_RULE_INF ); }
075:
076: private void testCardinality(OntModelSpec owlSpec) {
077: Model m = model("V owl:equivalentClass _R; _R rdf:type owl:Restriction; _R owl:onProperty P; _R owl:cardinality 1; X rdf:type V");
078: OntModel ont = ModelFactory.createOntologyModel(owlSpec, m);
079: assertEquals(1, ont.listStatements(resource("X"),
080: property("P"), ANY).toList().size());
081: }
082:
083: Model model(String statements) {
084: Model result = ModelFactory.createDefaultModel();
085: result.setNsPrefixes(PrefixMapping.Extended);
086: return modelAdd(result, statements);
087: }
088: }
089:
090: /*
091: * (c) Copyright 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
092: * All rights reserved.
093: *
094: * Redistribution and use in source and binary forms, with or without
095: * modification, are permitted provided that the following conditions
096: * are met:
097: * 1. Redistributions of source code must retain the above copyright
098: * notice, this list of conditions and the following disclaimer.
099: * 2. Redistributions in binary form must reproduce the above copyright
100: * notice, this list of conditions and the following disclaimer in the
101: * documentation and/or other materials provided with the distribution.
102: * 3. The name of the author may not be used to endorse or promote products
103: * derived from this software without specific prior written permission.
104: *
105: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
106: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
107: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
108: * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
109: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
110: * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
111: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
112: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
113: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
114: * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
115: */
|