@Test public void testQualifiedCardinalityObjectProperty() { final ATermAppl sub = term("sub"); final ATermAppl sup = term("sup"); classes(_c, _d, sub, sup); objectProperties(_p, _f); _kb.addFunctionalProperty(_f); _kb.addSubClass(sub, sup); assertSatisfiable(_kb, and(min(_p, 2, and(_c, _d)), max(_p, 2, _c), some(_p, or(and(_c, not(_d)), _c)))); assertSubClass(_kb, min(_p, 4, TOP), min(_p, 2, TOP)); assertNotSubClass(_kb, min(_p, 1, TOP), min(_p, 2, TOP)); assertNotSubClass(_kb, min(_p, 1, _c), min(_p, 1, _d)); assertNotSubClass(_kb, and(some(_p, _c), some(_p, not(_c))), min(_p, 2, _d)); assertSubClass(_kb, min(_p, 3, _c), min(_p, 2, _c)); assertSubClass(_kb, min(_p, 3, _c), min(_p, 2, TOP)); assertSubClass(_kb, min(_p, 2, _c), min(_p, 2, TOP)); assertNotSubClass(_kb, min(_p, 2, _c), min(_p, 2, _d)); assertSubClass(_kb, min(_p, 2, and(_c, _d)), some(_p, _c)); assertSubClass(_kb, max(_p, 1, sup), max(_p, 2, sub)); assertSubClass(_kb, and(max(_f, 1, TOP), all(_f, _c)), max(_f, 1, _c)); assertSubClass(_kb, and(min(_p, 2, _c), min(_p, 2, not(_c))), min(_p, 4, TOP)); }
@Test public void testFindPrimitives() { testFindPrimitives(some(_p, not(_c)), new ATermAppl[] { _c }); testFindPrimitives(and(_c, _b, all(_p, _a)), new ATermAppl[] { _a, _b, _c }); testFindPrimitives(max(_p, 1, not(some(_p, or(_a, _b)))), new ATermAppl[] { _a, _b }); testFindPrimitives(min(_p, 2, or(_a, and(_b, not(_c)))), new ATermAppl[] { _a, _b, _c }); testFindPrimitives(and(some(_p, ATermUtils.TOP), all(_p, _a), and(some(_p, value(_r)), or(self(_p), max(_p, 1, _b)))), new ATermAppl[] { ATermUtils.TOP, _a, _b }); testFindPrimitives(and(_d1, _d2, _d3), new ATermAppl[] { _d3 }); testFindPrimitives(not(and(not(_d1), _d2, _d3)), new ATermAppl[] { _d3 }); testFindPrimitives(some(_p, and(_d1, _d3)), new ATermAppl[] { _d3 }); }
private static Collection<ATermAppl> getUnsatisfiableDecimalEnumerations() { final Collection<ATermAppl> dataranges = Arrays.asList(oneOf(literal("1.0", DECIMAL), literal("2.0", DECIMAL), literal("3.0", DECIMAL)), oneOf(literal("4.0", DECIMAL), literal("5.0", DECIMAL), literal("6.0", DECIMAL))); return dataranges; }
@Test public void intersectNegatedFloatInterval() throws InvalidConstrainingFacetException, InvalidLiteralException, UnrecognizedDatatypeException { final ATermAppl floatInterval1 = restrict(FLOAT, minInclusive(literal(0.0f)), maxInclusive(literal(1.0f))); final ATermAppl floatInterval2 = restrict(FLOAT, minInclusive(literal(2.0f)), maxInclusive(literal(3.0f))); assertSatisfiable(floatInterval1, not(floatInterval2)); }
@Test public void testNNF() { testNNF(not(some(_p, _c)), all(_p, not(_c))); testNNF(not(all(_p, _c)), some(_p, not(_c))); testNNF(not(min(_p, 1, _c)), max(_p, 0, _c)); testNNF(not(max(_p, 0, _c)), min(_p, 1, _c)); testNNF(not(max(_p, 1, not(some(_p, _c)))), min(_p, 2, all(_p, not(_c)))); testNNF(and(_d1, _d2, _d3), and(_d1, _d2, _d3)); testNNF(not(and(_d1, _d2, _d3)), or(not(_d1), not(_d2), not(_d3))); testNNF(some(_p, and(_d1, _d3)), some(_p, and(_d1, _d3))); testNNF(not(some(_p, and(_d1, _d3))), all(_p, or(not(_d1), not(_d3)))); }
@Test public void testQualifiedCardinality3() { final KnowledgeBase kb = new KnowledgeBaseImpl(); final ATermAppl c = term("z"); final ATermAppl d = term("d"); final ATermAppl e = term("e"); final ATermAppl notD = term("notD"); final ATermAppl p = term("p"); final ATermAppl x = term("x"); final ATermAppl y3 = term("y3"); kb.addObjectProperty(p); kb.addClass(c); kb.addClass(d); kb.addClass(e); kb.addClass(notD); kb.addDisjointClass(d, notD); // _kb.addSubClass( c, or(e,not(d)) ); kb.addIndividual(x); kb.addIndividual(y3); kb.addType(x, and(min(p, 2, and(d, e)), max(p, 2, d))); kb.addType(y3, not(e)); kb.addType(y3, some(inv(p), value(x))); kb.addType(y3, or(d, c)); assertTrue(kb.isConsistent()); }
@Test public void bottomObjectInverseManual() { final KnowledgeBaseImpl kb = new KnowledgeBaseImpl(); final ATermAppl c = term("_C_"); final ATermAppl notC = not(c); final ATermAppl r = BOTTOM_OBJECT_PROPERTY; final ATermAppl test = and(c, or(some(r, all(r, notC)), some(r, all(r, notC)))); assertFalse(kb.isSatisfiable(test)); }
@Test public void testRemovePruned() { final KnowledgeBase kb = new KnowledgeBaseImpl(); final ATermAppl A = term("A"); final ATermAppl B = term("B"); final ATermAppl C = term("C"); final ATermAppl p = term("p"); final ATermAppl a = term("a"); final ATermAppl b = term("b"); kb.addClass(A); kb.addClass(B); kb.addClass(C); kb.addObjectProperty(p); kb.addIndividual(a); kb.addIndividual(b); kb.addEquivalentClass(A, value(a)); kb.addSubClass(A, all(inv(p), not(B))); kb.addSubClass(B, or(some(p, A), C)); kb.addType(b, B); assertTrue(kb.isConsistent()); assertTrue(kb.isType(b, C)); assertFalse(kb.isType(a, C)); }
@Test public void testCachedNominalEdge() { final KnowledgeBase kb = new KnowledgeBaseImpl(); final ATermAppl A = term("A"); final ATermAppl B = term("B"); final ATermAppl C = term("C"); final ATermAppl D = term("D"); final ATermAppl p = term("p"); final ATermAppl b = term("b"); final ATermAppl c = term("c"); kb.addClass(A); kb.addClass(B); kb.addClass(C); kb.addClass(D); kb.addObjectProperty(p); kb.addIndividual(b); kb.addIndividual(c); kb.addEquivalentClass(A, oneOf(b, c)); kb.addEquivalentClass(B, hasValue(p, b)); kb.addEquivalentClass(C, hasValue(p, c)); kb.addEquivalentClass(D, and(some(p, A), min(p, 1, value(b)), min(p, 1, value(c)), max(p, 1, TOP))); assertTrue(kb.isConsistent()); kb.classify(); assertTrue(kb.isSubClassOf(D, B)); assertTrue(kb.isSubClassOf(D, C)); }
@Test public void testNormalize() { testNormalize(some(_p, not(_c)), not(all(_p, _c))); testNormalize(all(_p, not(_c)), all(_p, not(_c))); testNormalize(all(_p, some(_q, _c)), all(_p, not(all(_q, not(_c))))); testNormalize(min(_p, 1, not(not(_c))), min(_p, 1, _c)); testNormalize(min(_p, 1, some(_p, _c)), min(_p, 1, not(all(_p, not(_c))))); testNormalize(min(_p, 0, _c), ATermUtils.TOP); testNormalize(min(_p, 1, ATermUtils.BOTTOM), ATermUtils.BOTTOM); testNormalize(max(_p, 0, _c), not(min(_p, 1, _c))); testNormalize(max(_p, 1, _c), not(min(_p, 2, _c))); testNormalize(max(_p, 1, not(some(_p, not(not(_c))))), not(min(_p, 2, all(_p, not(_c))))); testNormalize(max(_p, 1, ATermUtils.BOTTOM), ATermUtils.TOP); testNormalize(some(_p, not(value(_a))), not(all(_p, value(_a)))); testNormalize(some(_p, not(_d1)), not(all(_p, _d1))); testNormalize(all(_p, not(_d1)), all(_p, not(_d1))); testNormalize(all(_p, some(_q, _d1)), all(_p, not(all(_q, not(_d1))))); }
@Test public void testSHOIN() { final KnowledgeBase kb = new KnowledgeBaseImpl(); kb.addObjectProperty(term("R1")); kb.addObjectProperty(term("invR1")); kb.addObjectProperty(term("R2")); kb.addObjectProperty(term("invR2")); kb.addObjectProperty(term("S1")); kb.addObjectProperty(term("invS1")); kb.addObjectProperty(term("S2")); kb.addObjectProperty(term("invS2")); kb.addInverseProperty(term("R1"), term("invR1")); kb.addInverseProperty(term("R2"), term("invR2")); kb.addInverseProperty(term("S1"), term("invS1")); kb.addInverseProperty(term("S2"), term("invS2")); kb.addIndividual(term("o1")); kb.addIndividual(term("o2")); kb.addSubClass(value(term("o1")), and(max(term("invR1"), 2, ATermUtils.TOP), all(term("invR1"), some(term("S1"), some(term("invS2"), some(term("R2"), value(term("o2")))))))); kb.addSubClass(value(term("o2")), and(max(term("invR2"), 2, ATermUtils.TOP), all(term("invR2"), some(term("S2"), some(term("invS1"), some(term("R1"), value(term("o1")))))))); assertTrue(kb.isConsistent()); assertTrue(kb.isSatisfiable(and(value(term("o1")), some(term("invR1"), TOP)))); }
@Test public void maxCardinalityInvTrans() { final ATermAppl invF = term("invF"); final ATermAppl invR = term("invR"); classes(_C, _D); objectProperties(_r, _f, invF, invR); _kb.addSubClass(TOP, max(_f, 1, TOP)); // _kb.addSubClass( TOP, max( inv( f ), 1, TOP ) ); _kb.addInverseProperty(_f, invF); _kb.addTransitiveProperty(_r); _kb.addInverseProperty(_r, invR); _kb.addSubProperty(_f, _r); _kb.addEquivalentClass(_D, and(_C, some(_f, not(_C)))); assertTrue(_kb.isConsistent()); assertFalse(_kb.isSatisfiable(and(not(_C), some(invF, _D), all(invR, some(invF, _D))))); }
@Test public void bottomDataAssertion() { final KnowledgeBaseImpl kb = new KnowledgeBaseImpl(); final ATermAppl x = term("x"); final ATermAppl y = literal("y"); kb.addIndividual(x); assertFalse(kb.hasPropertyValue(x, BOTTOM_DATA_PROPERTY, y)); assertTrue(kb.isType(x, not(some(BOTTOM_DATA_PROPERTY, TOP_LIT)))); assertTrue(kb.isType(x, not(hasValue(BOTTOM_DATA_PROPERTY, y)))); kb.addPropertyValue(BOTTOM_DATA_PROPERTY, x, y); assertFalse(kb.isConsistent()); }
@Test public void test560() { classes(_A, _B); individuals(_a); objectProperties(_p, _q); _kb.addFunctionalProperty(_p); _kb.addSubProperty(_q, _p); _kb.addSubClass(_A, hasValue(_q, _a)); _kb.addType(_a, all(inv(_q), all(inv(_p), oneOf(_a)))); assertTrue(_kb.isConsistent()); assertTrue(_kb.isSatisfiable(and(some(_p, _A), some(_q, _B)))); }
@Test public void testCRonDTP() { // Test for ticket #143 final Properties newOptions = new PropertiesBuilder().set("SILENT_UNDEFINED_ENTITY_HANDLING", "false").build(); final Properties savedOptions = OpenlletOptions.setOptions(newOptions); try { final KnowledgeBase kb = new KnowledgeBaseImpl(); final ATermAppl p = term("p"); final ATermAppl c = and(all(p, value(literal("s"))), min(p, 2, value(literal("l")))); kb.addDatatypeProperty(p); assertFalse(kb.isSatisfiable(c)); } finally { OpenlletOptions.setOptions(savedOptions); } }
@Test public void intersectTextNegatedTextValue() throws InvalidConstrainingFacetException, InvalidLiteralException, UnrecognizedDatatypeException { final Collection<ATermAppl> types = Arrays.asList(PLAIN_LITERAL, not(value(literal("http://example.org")))); assertTrue(reasoner.isSatisfiable(types)); assertTrue(reasoner.containsAtLeast(2, types)); assertTrue(reasoner.isSatisfiable(types, literal("http://example.com"))); assertFalse(reasoner.isSatisfiable(types, literal("http://example.org"))); }
@Test public void testHasValue() { final StringWriter s = new StringWriter(); final ATermRenderer r = new ATermManchesterSyntaxRenderer(); r.setWriter(new PrintWriter(s)); final ATermAppl l = literal("foobar"); final ATermAppl p = term("p"); r.visit(hasValue(p, l)); final String expected = "(p value \"foobar\")"; final String actual = s.toString(); assertEquals(expected, actual); }
@Test public void test518() { // tests if the interaction between some values restriction and inverses ends up creating a cycle in the // completion graph classes(_A, _B, _C); objectProperties(_p, _q); _kb.addInverseFunctionalProperty(_p); _kb.addSubProperty(_q, inv(_p)); assertFalse(_kb.isSatisfiable(some(_p, some(_q, all(_p, BOTTOM))))); }
private void addEdge(final ATermAppl p, final ATermAppl s, final ATermAppl o) { DependencySet edgeDS = _ds; Individual node1 = _abox.getIndividual(s); if (node1.isMerged()) { edgeDS = node1.getMergeDependency(true); node1 = node1.getSame(); } if (_negated) { final ATermAppl cls = all(p, not(value(o))); _strategy.addType(node1, cls, _ds); } else { Node node2 = _abox.getNode(o); if (node2.isMerged()) { edgeDS = node2.getMergeDependency(true); node2 = node2.getSame(); } _strategy.addEdge(node1, _abox.getRole(p), node2, edgeDS); } }