@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 test370() { // test case for issue #370. dataProperties(_p); individuals(_a); final ATermAppl dt = restrict(Datatypes.DECIMAL, minExclusive(literal("0.99", Datatypes.DECIMAL)), maxExclusive(literal("1.01", Datatypes.DECIMAL))); _kb.addType(_a, min(_p, 3, dt)); assertTrue(_kb.isConsistent()); }
@Test public void testMin() { 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(min(p, 3, C)); final String expected = "(p min 3 C)"; final String actual = s.toString(); assertEquals(expected, actual); }
@Test public void testMin() { 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(min(p, 3, C)); final String expected = "(p min 3 C)"; final String actual = s.toString(); assertEquals(expected, actual); }
@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 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 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 minCardinalityOnIrreflexive() { // related to #400 classes(_A); objectProperties(_p); individuals(_a); _kb.addIrreflexiveProperty(_p); _kb.addSubClass(_A, min(_p, 1, TOP)); _kb.addEquivalentClass(_A, oneOf(_a)); _kb.addEquivalentClass(TOP, _A); assertFalse(_kb.isConsistent()); }
@Test public void anyURI383() { final ATermAppl C = TermFactory.term("C"); final ATermAppl D = TermFactory.term("D"); final ATermAppl p = TermFactory.term("p"); final ATermAppl uri = TermFactory.literal(URI.create("http://www.example.org")); final KnowledgeBaseImpl kb = new KnowledgeBaseImpl(); kb.addClass(C); kb.addClass(D); kb.addDatatypeProperty(p); kb.addRange(p, ANY_URI); kb.addEquivalentClass(C, hasValue(p, uri)); kb.addEquivalentClass(D, min(p, 1, TOP_LIT)); assertSubClass(kb, C, D, true); assertSubClass(kb, D, C, false); }
@Test public void testRuleEquality() { final ATermAppl r = term("r"); final ATermAppl i = term("i"); final ATermAppl j = term("j"); final AtomIObject x = new AtomIVariable("x"); final AtomIObject y = new AtomIVariable("y"); _kb.addIndividual(i); _kb.addIndividual(j); _kb.addObjectProperty(r); _kb.addSubClass(TOP, min(r, 1, TOP)); _kb.addSubClass(TOP, oneOf(i, j)); _kb.addRule(new Rule(Collections.singletonList(new DifferentIndividualsAtom(x, y)), Collections.singletonList(new IndividualPropertyAtom(r, x, y)))); _kb.realize(); assertTrue(_kb.isConsistent()); assertTrue(_kb.isDifferentFrom(i, j)); }
@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 userDefinedDatatypes303a() { final ATermAppl c = TermFactory.term("C"); final ATermAppl v = TermFactory.term("v"); final ATermAppl i = TermFactory.term("i"); final ATermAppl one = TermFactory.literal(1); final KnowledgeBaseImpl kb = new KnowledgeBaseImpl(); kb.addClass(c); kb.addDatatypeProperty(v); kb.addIndividual(i); kb.addSubClass(c, TermFactory.min(v, 1, INTEGER)); kb.addRange(v, TermFactory.oneOf(one)); kb.addType(i, c); assertTrue(kb.hasPropertyValue(i, v, one)); }
@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 testDataOneOf() { final KnowledgeBase kb = new KnowledgeBaseImpl(); final ATermAppl A = term("A"); final ATermAppl p = term("p"); final ATermAppl q = term("q"); final ATermAppl a = term("a"); final ATermAppl lit1 = literal("test"); final ATermAppl lit2 = literal("1", Datatypes.DECIMAL); kb.addClass(A); kb.addDatatypeProperty(p); kb.addDatatypeProperty(q); kb.addIndividual(a); kb.addType(a, A); kb.addSubClass(A, min(p, 1, TOP_LIT)); kb.addRange(p, oneOf(lit1)); kb.addSubClass(A, some(q, TOP_LIT)); kb.addRange(q, oneOf(lit2)); assertTrue(kb.isConsistent()); assertEquals(singletonList(lit1), kb.getDataPropertyValues(p, a)); assertEquals(singletonList(lit2), kb.getDataPropertyValues(q, a)); assertTrue(kb.hasPropertyValue(a, p, lit1)); assertTrue(kb.hasPropertyValue(a, q, lit2)); }
@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); } }
@SuppressWarnings("unused") @Test public void inferredProperties() throws Exception { final ATermAppl d = literal("foo"), i = term("i"), j = term("j"), k = term("k"), p = term("p"), r = term("r"); _kb.addIndividual(i); _kb.addIndividual(j); _kb.addIndividual(k); _kb.addDatatypeProperty(p); _kb.addObjectProperty(r); _kb.addSubClass(TOP, min(r, 3, TOP)); _kb.addSubClass(TOP, or(value(i), value(j), value(k))); _kb.addPropertyValue(p, i, d); final AtomIVariable x = new AtomIVariable("x"), y = new AtomIVariable("y"); final AtomDVariable z = new AtomDVariable("z"); final RuleAtom head = new DatavaluedPropertyAtom(p, x, z); final RuleAtom body1 = new DatavaluedPropertyAtom(p, y, z); final RuleAtom body2 = new IndividualPropertyAtom(r, x, y); final Rule rule = new Rule(Collections.singletonList(head), Arrays.asList(body1, body2)); _kb.addRule(rule); _kb.ensureConsistency(); assertTrue(_kb.hasPropertyValue(j, r, i)); assertTrue(_kb.hasPropertyValue(k, r, i)); assertTrue(_kb.hasPropertyValue(j, p, d)); assertTrue(_kb.hasPropertyValue(k, p, 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 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 }); }