public static ATermAppl oneOf(final ATermAppl... terms) { ATermList list = ATermUtils.EMPTY_LIST; for (final ATermAppl term : terms) list = list.insert(value(term)); return ATermUtils.makeOr(list); }
public static ATermAppl oneOf(final ATermAppl... terms) { ATermList list = ATermUtils.EMPTY_LIST; for (final ATermAppl term : terms) list = list.insert(value(term)); return ATermUtils.makeOr(list); }
@Override public void visit(final SameIndividualAtom atom) { final ATermAppl ind1 = _binding.get(atom.getArgument1()).getName(); final ATermAppl ind2 = _binding.get(atom.getArgument2()).getName(); final ATermAppl cls = value(ind2); addType(ind1, cls); }
@Override public void visit(final SameIndividualAtom atom) { final ATermAppl ind1 = _binding.get(atom.getArgument1()).getName(); final ATermAppl ind2 = _binding.get(atom.getArgument2()).getName(); final ATermAppl cls = value(ind2); addType(ind1, cls); }
@Override public void visit(final DifferentIndividualsAtom atom) { final ATermAppl ind1 = _binding.get(atom.getArgument1()).getName(); final ATermAppl ind2 = _binding.get(atom.getArgument2()).getName(); final ATermAppl cls = not(value(ind2)); addType(ind1, cls); }
@Override public void visit(final DifferentIndividualsAtom atom) { final ATermAppl ind1 = _binding.get(atom.getArgument1()).getName(); final ATermAppl ind2 = _binding.get(atom.getArgument2()).getName(); final ATermAppl cls = not(value(ind2)); addType(ind1, cls); }
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); } }
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); } }
@Test public void intersectAnyURINegatedTextValue() throws InvalidConstrainingFacetException, InvalidLiteralException, UnrecognizedDatatypeException { final Collection<ATermAppl> types = Arrays.asList(ANY_URI, not(value(literal("http://example.org")))); assertTrue(reasoner.isSatisfiable(types)); assertTrue(reasoner.containsAtLeast(2, types)); assertTrue(reasoner.isSatisfiable(types, literal("http://example.com", Datatypes.ANY_URI))); assertTrue(reasoner.isSatisfiable(types, literal("http://example.org", Datatypes.ANY_URI))); }
@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 intersectAnyURINegatedURIValue() throws InvalidConstrainingFacetException, InvalidLiteralException, UnrecognizedDatatypeException { final Collection<ATermAppl> types = Arrays.asList(ANY_URI, not(value(literal("http://example.org", ANY_URI)))); assertTrue(reasoner.isSatisfiable(types)); assertTrue(reasoner.containsAtLeast(2, types)); assertTrue(reasoner.isSatisfiable(types, literal("http://example.com", Datatypes.ANY_URI))); assertFalse(reasoner.isSatisfiable(types, literal("http://example.org", Datatypes.ANY_URI))); }
@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 intersectIntegerNegatedIntegerValue() throws InvalidConstrainingFacetException, InvalidLiteralException, UnrecognizedDatatypeException { final Collection<ATermAppl> types = Arrays.asList(INTEGER, not(value(literal(3)))); assertTrue(reasoner.isSatisfiable(types)); assertTrue(reasoner.containsAtLeast(2, types)); assertTrue(reasoner.isSatisfiable(types, reasoner.getValue(literal(1)))); assertFalse(reasoner.isSatisfiable(types, reasoner.getValue(literal(3)))); }
@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 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 }); }
@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 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 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))))); }