@Test public void testMax() { final StringWriter s = new StringWriter(); final ATermRenderer r = new ATermManchesterSyntaxRenderer(); r.setWriter(new PrintWriter(s)); final ATermAppl C = term("C"); final ATermAppl p = term("p"); r.visit(max(p, 3, C)); final String expected = "(p max 3 C)"; final String actual = s.toString(); assertEquals(expected, actual); }
@Test public void testMax() { final StringWriter s = new StringWriter(); final ATermRenderer r = new ATermManchesterSyntaxRenderer(); r.setWriter(new PrintWriter(s)); final ATermAppl C = term("C"); final ATermAppl p = term("p"); r.visit(max(p, 3, C)); final String expected = "(p max 3 C)"; final String actual = s.toString(); assertEquals(expected, actual); }
@Test public void testInverseCardinality1() { final ATermAppl C = term("C"); final ATermAppl p = term("p"); final ATermAppl invP = term("invP"); final ATermAppl a = term("a"); final ATermAppl b = term("b"); _kb.addClass(C); _kb.addObjectProperty(p); _kb.addObjectProperty(invP); _kb.addIndividual(a); _kb.addIndividual(b); _kb.addSubClass(C, max(invP, 0, TOP)); _kb.addInverseProperty(p, invP); _kb.addPropertyValue(p, b, a); _kb.addType(a, C); assertFalse(_kb.isConsistent()); final Set<ATermAppl> explanation = _kb.getExplanationSet(); assertIteratorValues(explanation.iterator(), new Object[] { ATermUtils.makeSub(C, max(invP, 0, TOP)), ATermUtils.makeInvProp(p, invP), ATermUtils.makePropAtom(p, b, a), ATermUtils.makeTypeAtom(a, C) }); }
@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 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 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 max1Inv() { classes(_C, _D); objectProperties(_f); _kb.addSubClass(_D, some(inv(_f), _C)); _kb.addSubClass(_C, and(some(_f, not(_D)), max(_f, 1, TOP))); assertTrue(_kb.isConsistent()); assertTrue(_kb.isSatisfiable(_C)); assertFalse(_kb.isSatisfiable(_D)); }
@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 }); }
@Test public void testInverseCardinality2() { final ATermAppl C = term("C"); final ATermAppl p = term("p"); final ATermAppl invP = term("invP"); final ATermAppl a = term("a"); final ATermAppl b = term("b"); final ATermAppl c = term("c"); final ATermList inds = makeList(new ATerm[] { a, b, c }); _kb.addClass(C); _kb.addObjectProperty(p); _kb.addObjectProperty(invP); _kb.addIndividual(a); _kb.addIndividual(b); _kb.addIndividual(c); _kb.addSubClass(C, max(invP, 1, TOP)); _kb.addInverseProperty(p, invP); _kb.addPropertyValue(p, b, a); _kb.addPropertyValue(p, c, a); _kb.addType(a, C); _kb.addAllDifferent(inds); assertFalse(_kb.isConsistent()); final Set<ATermAppl> explanation = _kb.getExplanationSet(); assertIteratorValues(explanation.iterator(), new Object[] { ATermUtils.makeSub(C, max(invP, 1, TOP)), ATermUtils.makeInvProp(p, invP), ATermUtils.makeAllDifferent(inds), ATermUtils.makePropAtom(p, b, a), ATermUtils.makePropAtom(p, c, a), ATermUtils.makeTypeAtom(a, C) }); }
@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 }); }
@Test public void testComplexTypes() { final KnowledgeBase kb = new KnowledgeBaseImpl(); final ATermAppl a = term("a"); final ATermAppl p = term("p"); final ATermAppl q = term("q"); kb.addIndividual(a); kb.addType(a, min(p, 3, TOP)); kb.addType(a, max(q, 2, TOP)); kb.addType(a, min(q, 1, TOP)); kb.addType(a, min(q, 1, TOP)); kb.addObjectProperty(p); kb.addObjectProperty(q); assertTrue(kb.isConsistent()); }
@Test public void test532b() { // variation of the _condition in 532 where the _nodes involved in MaxBranch are merged classes(_C, _D, _E); individuals(_a, _b, _c, _d, _e, _f); objectProperties(_p); _kb.addType(_a, max(_p, 2, TOP)); _kb.addType(_a, min(_p, 2, TOP)); _kb.addPropertyValue(_p, _a, _b); _kb.addPropertyValue(_p, _a, _c); _kb.addPropertyValue(_p, _a, _d); assertTrue(_kb.isConsistent()); _kb.addSame(_c, _e); _kb.addSame(_d, _e); assertTrue(_kb.isConsistent()); }
@Test public void doubleBlockingExample() { classes(_C, _D); objectProperties(_f, _r); _kb.addTransitiveProperty(_r); _kb.addSubProperty(_f, _r); _kb.addEquivalentClass(_D, and(_C, some(_f, not(_C)))); _kb.addSubClass(TOP, max(_f, 1, TOP)); assertTrue(_kb.isConsistent()); assertFalse(_kb.isSatisfiable(and(not(_C), some(inv(_f), _D), all(inv(_r), some(inv(_f), _D))))); }
@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 maxCardinalitySubTrans() { classes(_A); objectProperties(_r, _f); _kb.addSubClass(TOP, max(_f, 1, TOP)); _kb.addTransitiveProperty(_r); _kb.addSubProperty(_f, _r); _kb.addEquivalentClass(_D, and(_C, some(_f, not(_C)))); assertTrue(_kb.isConsistent()); assertTrue(_kb.isSatisfiable(and(not(_A), some(inv(_f), _A), all(inv(_r), some(inv(_f), _A))))); }
@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 maxCardinalitySub() { classes(_C, _D); objectProperties(_p, _r, _f); _kb.addSubClass(TOP, max(_f, 1, TOP)); _kb.addSubProperty(_p, _f); _kb.addSubProperty(_r, _f); assertTrue(_kb.isConsistent()); assertTrue(_kb.isSatisfiable(_C)); assertTrue(_kb.isSatisfiable(all(inv(_r), not(_C)))); assertFalse(_kb.isSatisfiable(and(_C, some(_r, TOP), some(_p, all(inv(_r), not(_C)))))); }
@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 testMerge3() { classes(_person, _man, _dog); objectProperties(_sibling, _owns); individuals(_mary, _chris, _victor, _john, _bill); _kb.addPropertyValue(_sibling, _bill, _mary); _kb.addPropertyValue(_sibling, _bill, _john); _kb.addSubClass(_man, some(_owns, _dog)); assertTrue(_kb.isConsistent()); assertFalse(_kb.getABox().getNode(_mary).isSame(_kb.getABox().getNode(_john))); _kb.addType(_bill, max(_sibling, 1, TOP)); _kb.addType(_mary, or(_man, _dog)); _kb.addType(_chris, or(_man, _dog)); assertTrue(_kb.isConsistent()); assertTrue(_kb.getABox().getNode(_mary).isSame(_kb.getABox().getNode(_john))); _kb.removeType(_bill, max(_sibling, 1, TOP)); assertTrue(_kb.isConsistent()); assertFalse(_kb.getABox().getNode(_mary).isSame(_kb.getABox().getNode(_john))); assertFalse(_kb.getABox().getNode(_john).hasType(_man) || _kb.getABox().getNode(_john).hasType(_dog)); assertTrue(_kb.getABox().getNode(_mary).hasType(_man) || _kb.getABox().getNode(_mary).hasType(_dog)); }
@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)))); }