@Override public void visit(final SWRLRule rule) { if (!OpenlletOptions.DL_SAFE_RULES) return; if (!_addAxioms) { _reloadRequired = true; return; } final List<RuleAtom> head = parseAtomList(asList(rule.head())); final List<RuleAtom> body = parseAtomList(asList(rule.body())); if (head == null || body == null) { addUnsupportedAxiom(rule); return; } final Rule pelletRule = new Rule(head, body); _kb.addRule(pelletRule); }
@Override public void visit(final SWRLRule rule) { if (!OpenlletOptions.DL_SAFE_RULES) return; if (!_addAxioms) { _reloadRequired = true; return; } final List<RuleAtom> head = parseAtomList(asList(rule.head())); final List<RuleAtom> body = parseAtomList(asList(rule.body())); if (head == null || body == null) { addUnsupportedAxiom(rule); return; } final Rule pelletRule = new Rule(head, body); _kb.addRule(pelletRule); }
@Override public void visit(final SWRLRule rule) { if (!OpenlletOptions.DL_SAFE_RULES) return; if (!_addAxioms) { _reloadRequired = true; return; } final List<RuleAtom> head = parseAtomList(asList(rule.head())); final List<RuleAtom> body = parseAtomList(asList(rule.body())); if (head == null || body == null) { addUnsupportedAxiom(rule); return; } final Rule pelletRule = new Rule(head, body); _kb.addRule(pelletRule); }
private void defineRule(final Node node) { final List<RuleAtom> head = parseAtomList(getObject(node, SWRL.head.asNode())); final List<RuleAtom> body = parseAtomList(getObject(node, SWRL.body.asNode())); if (head == null || body == null) { String whichPart = "head and body"; if (head != null) whichPart = "body"; else if (body != null) whichPart = "head"; addUnsupportedFeature("Ignoring SWRL rule (unsupported " + whichPart + "): " + node); return; } final ATermAppl name = JenaUtils.makeATerm(node); final Rule rule = new Rule(name, head, body); _kb.addRule(rule); }
private void defineRule(final Node node) { final List<RuleAtom> head = parseAtomList(getObject(node, SWRL.head.asNode())); final List<RuleAtom> body = parseAtomList(getObject(node, SWRL.body.asNode())); if (head == null || body == null) { String whichPart = "head and body"; if (head != null) whichPart = "body"; else if (body != null) whichPart = "head"; addUnsupportedFeature("Ignoring SWRL rule (unsupported " + whichPart + "): " + node); return; } final ATermAppl name = JenaUtils.makeATerm(node); final Rule rule = new Rule(name, head, body); _kb.addRule(rule); }
private void defineRule(final Node node) { final List<RuleAtom> head = parseAtomList(getObject(node, SWRL.head.asNode())); final List<RuleAtom> body = parseAtomList(getObject(node, SWRL.body.asNode())); if (head == null || body == null) { String whichPart = "head and body"; if (head != null) whichPart = "body"; else if (body != null) whichPart = "head"; addUnsupportedFeature("Ignoring SWRL rule (unsupported " + whichPart + "): " + node); return; } final ATermAppl name = JenaUtils.makeATerm(node); final Rule rule = new Rule(name, head, body); _kb.addRule(rule); }
@Test public void testEmptyRuleHead1() { final ATermAppl i = term("i"); final ATermAppl C = term("C"); final AtomIVariable x = new AtomIVariable("x"); _kb.addClass(C); _kb.addIndividual(i); _kb.addType(i, C); final List<RuleAtom> body = new ArrayList<>(); final List<RuleAtom> head = new ArrayList<>(); body.add(new ClassAtom(C, x)); _kb.addRule(new Rule(head, body)); assertFalse(_kb.isConsistent()); }
@Test public void testEmptyRuleHead4() { final ATermAppl i = term("i"); final ATermAppl R = term("R"); final ATermAppl l = literal("l"); final AtomIVariable v = new AtomIVariable("v"); final AtomDConstant c = new AtomDConstant(l); _kb.addIndividual(i); _kb.addDatatypeProperty(R); _kb.addPropertyValue(R, i, l); final List<RuleAtom> body = new ArrayList<>(); final List<RuleAtom> head = new ArrayList<>(); body.add(new DatavaluedPropertyAtom(R, v, c)); _kb.addRule(new Rule(head, body)); assertFalse(_kb.isConsistent()); }
@Test public void testEmptyRuleHead3() { final ATermAppl i = term("i"); final ATermAppl C = term("C"); final ATermAppl D = term("D"); final AtomIVariable x = new AtomIVariable("x"); _kb.addClass(C); _kb.addClass(D); _kb.addSubClass(C, D); _kb.addIndividual(i); _kb.addType(i, D); final List<RuleAtom> body = new ArrayList<>(); final List<RuleAtom> head = new ArrayList<>(); body.add(new ClassAtom(D, x)); _kb.addRule(new Rule(head, body)); assertFalse(_kb.isConsistent()); }
@Test public void testEmptyRuleHead2() { final ATermAppl i = term("i"); final ATermAppl C = term("C"); final ATermAppl D = term("D"); final AtomIVariable x = new AtomIVariable("x"); _kb.addClass(C); _kb.addClass(D); _kb.addSubClass(C, D); _kb.addIndividual(i); _kb.addType(i, C); final List<RuleAtom> body = new ArrayList<>(); final List<RuleAtom> head = new ArrayList<>(); body.add(new ClassAtom(C, x)); _kb.addRule(new Rule(head, body)); assertFalse(_kb.isConsistent()); }
@Test public void testEmptyRuleHead5() { final ATermAppl i = term("i"); final ATermAppl C = term("C"); final ATermAppl D = term("D"); final ATermAppl CuD = or(C, D); final AtomIVariable x = new AtomIVariable("x"); _kb.addClass(C); _kb.addClass(D); _kb.addClass(CuD); _kb.addIndividual(i); _kb.addType(i, C); final List<RuleAtom> body = new ArrayList<>(); final List<RuleAtom> head = new ArrayList<>(); body.add(new ClassAtom(CuD, x)); _kb.addRule(new Rule(head, body)); assertFalse(_kb.isConsistent()); }
@Test public void testRuleIndividuals() { final ATermAppl c = term("C"), d = term("D"), i = term("i"); _kb.addClass(c); _kb.addClass(d); _kb.addIndividual(i); _kb.addType(i, c); _kb.addRule(new Rule(Arrays.asList(new RuleAtom[] { new ClassAtom(d, new AtomIConstant(i)) }), Arrays.asList(new RuleAtom[] { new ClassAtom(c, new AtomIConstant(i)) }))); _kb.realize(); assertTrue(_kb.getTypes(i).contains(Collections.singleton(d))); }
@Test public void testTriangle() { objectProperties(_p, _q); individuals(_a, _b, _c, _d, _e); _kb.addPropertyValue(_p, _a, _b); _kb.addPropertyValue(_p, _b, _c); _kb.addPropertyValue(_p, _a, _c); _kb.addPropertyValue(_p, _b, _e); _kb.addPropertyValue(_p, _c, _e); final AtomIVariable x = new AtomIVariable("x"); final AtomIVariable y = new AtomIVariable("y"); final AtomIVariable z = new AtomIVariable("z"); final List<RuleAtom> body = Arrays.<RuleAtom> asList(new IndividualPropertyAtom(_p, x, y), new IndividualPropertyAtom(_p, y, z), new IndividualPropertyAtom(_p, x, z)); final List<RuleAtom> head = Arrays.<RuleAtom> asList(new IndividualPropertyAtom(_q, x, z)); _kb.addRule(new Rule(head, body)); assertIteratorValues(_kb.getObjectPropertyValues(_q, _a).iterator(), _c); assertIteratorValues(_kb.getObjectPropertyValues(_q, _b).iterator(), _e); assertIteratorValues(_kb.getObjectPropertyValues(_q, _c).iterator()); assertIteratorValues(_kb.getObjectPropertyValues(_q, _d).iterator()); }
private void nonTrivialBuiltInTest() { final ATermAppl d1 = literal("1", Datatypes.INT), d2 = literal("2", Datatypes.INT), d12 = literal("3", Datatypes.INTEGER), i = term("i"), p = term("p"), q = term("q"), r = term("r"); _kb.addDatatypeProperty(p); _kb.addDatatypeProperty(q); _kb.addDatatypeProperty(r); _kb.addIndividual(i); _kb.addSubClass(TOP, hasValue(p, d1)); _kb.addSubClass(TOP, hasValue(q, d2)); final AtomIVariable x = new AtomIVariable("x"); final AtomDVariable z1 = new AtomDVariable("z1"); final AtomDVariable z2 = new AtomDVariable("z2"); final AtomDVariable z3 = new AtomDVariable("z3"); final List<RuleAtom> body = new ArrayList<>(); body.add(new DatavaluedPropertyAtom(p, x, z1)); body.add(new DatavaluedPropertyAtom(q, x, z2)); body.add(new BuiltInAtom(SWRLB + "add", z3, z1, z2)); final List<RuleAtom> head = new ArrayList<>(); head.add(new DatavaluedPropertyAtom(r, x, z3)); _kb.addRule(new Rule(head, body)); _kb.realize(); assertTrue(_kb.hasPropertyValue(i, r, d12)); }
@Test public void testNoVarPropertyAtom() { classes(_A); dataProperties(_p, _q); individuals(_a, _b); _kb.addType(_a, _A); _kb.addPropertyValue(_p, _b, TermFactory.literal(true)); final ATermAppl t = TermFactory.literal("t"); final ATermAppl f = TermFactory.literal("f"); final AtomIVariable x = new AtomIVariable("x"); List<RuleAtom> body = Arrays.<RuleAtom> asList(new ClassAtom(_A, x), new DatavaluedPropertyAtom(_p, new AtomIConstant(_b), new AtomDConstant(TermFactory.literal(true)))); List<RuleAtom> head = Arrays.<RuleAtom> asList(new DatavaluedPropertyAtom(_q, x, new AtomDConstant(t))); _kb.addRule(new Rule(head, body)); body = Arrays.<RuleAtom> asList(new ClassAtom(_A, x), new DatavaluedPropertyAtom(_p, new AtomIConstant(_b), new AtomDConstant(TermFactory.literal(false)))); head = Arrays.<RuleAtom> asList(new DatavaluedPropertyAtom(_q, x, new AtomDConstant(f))); _kb.addRule(new Rule(head, body)); assertIteratorValues(_kb.getDataPropertyValues(_q, _a).iterator(), t); assertIteratorValues(_kb.getDataPropertyValues(_q, _b).iterator()); }
@Test public void testNoSharedVarFixedObject() { classes(_A); dataProperties(_p, _q); objectProperties(_r, _s); individuals(_a, _b, _c, _d); _kb.addType(_a, _A); _kb.addPropertyValue(_r, _c, _b); _kb.addPropertyValue(_p, _c, TermFactory.literal(true)); _kb.addPropertyValue(_s, _d, _b); _kb.addPropertyValue(_p, _d, TermFactory.literal(false)); final ATermAppl t = TermFactory.literal("t"); final ATermAppl f = TermFactory.literal("f"); final AtomIVariable x = new AtomIVariable("x"); final AtomIVariable y = new AtomIVariable("y"); List<RuleAtom> body = Arrays.<RuleAtom> asList(new ClassAtom(_A, x), new IndividualPropertyAtom(_r, y, new AtomIConstant(_b)), new DatavaluedPropertyAtom(_p, y, new AtomDConstant(TermFactory.literal(true)))); List<RuleAtom> head = Arrays.<RuleAtom> asList(new DatavaluedPropertyAtom(_q, x, new AtomDConstant(t))); _kb.addRule(new Rule(head, body)); body = Arrays.<RuleAtom> asList(new ClassAtom(_A, x), new IndividualPropertyAtom(_r, y, new AtomIConstant(_b)), new DatavaluedPropertyAtom(_p, y, new AtomDConstant(TermFactory.literal(false)))); head = Arrays.<RuleAtom> asList(new DatavaluedPropertyAtom(_q, x, new AtomDConstant(f))); _kb.addRule(new Rule(head, body)); assertIteratorValues(_kb.getDataPropertyValues(_q, _a).iterator(), t); assertIteratorValues(_kb.getDataPropertyValues(_q, _b).iterator()); }
@Test public void testBindingBuiltins() { classes(_A); dataProperties(_p, _q); individuals(_a, _b, _c, _d); _kb.addPropertyValue(_p, _a, TermFactory.literal(1)); _kb.addPropertyValue(_p, _b, TermFactory.literal(5)); _kb.addPropertyValue(_p, _c, TermFactory.literal(10)); _kb.addPropertyValue(_p, _d, TermFactory.literal(15)); final AtomIVariable x = new AtomIVariable("x"); final AtomDVariable y = new AtomDVariable("y"); final AtomDVariable z = new AtomDVariable("z"); final List<RuleAtom> body = Arrays.<RuleAtom> asList(new DatavaluedPropertyAtom(_p, x, y), new BuiltInAtom(SWRLB + "pow", z, y, new AtomDConstant(TermFactory.literal(2))), new BuiltInAtom(SWRLB + "lessThan", z, new AtomDConstant(TermFactory.literal(100)))); final List<RuleAtom> head = Arrays.<RuleAtom> asList(new ClassAtom(_A, x)); _kb.addRule(new Rule(head, body)); assertIteratorValues(_kb.getInstances(_A).iterator(), _a, _b); }
@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 ruleInteractionWithInverses() { // Tests #446 classes(_A); objectProperties(_p, _q, _r, _f); dataProperties(_p); individuals(_a, _b, _c); final AtomIVariable x = new AtomIVariable("x"); final AtomIVariable y = new AtomIVariable("y"); final AtomIVariable z = new AtomIVariable("z"); _kb.addSymmetricProperty(_p); _kb.addInverseProperty(_q, _r); _kb.addPropertyValue(_p, _c, _a); _kb.addPropertyValue(_f, _a, _b); final List<RuleAtom> body = Arrays.<RuleAtom> asList(new IndividualPropertyAtom(_f, x, y), new IndividualPropertyAtom(_p, x, z)); final List<RuleAtom> head = Arrays.<RuleAtom> asList(new IndividualPropertyAtom(_r, z, y)); final Rule rule = new Rule(head, body); _kb.addRule(rule); explainEntailment(_kb.hasPropertyValue(_b, _q, _c), ATermUtils.makePropAtom(_p, _c, _a), ATermUtils.makePropAtom(_f, _a, _b), ATermUtils.makeSymmetric(_p), ATermUtils.makeInvProp(_q, _r), new RulesToATermTranslator().translate(rule)); }
public void testUncleRule() { final ATermAppl hasParent = term("hasParent"), hasSibling = term("hasSibling"), hasUncle = term("hasUncle"), male = term("Male"); final ATermAppl c11 = term("c11"), c12 = term("c12"), p1a = term("p1a"), p2a = term("p2a"); _kb.addClass(male); _kb.addObjectProperty(hasParent); _kb.addObjectProperty(hasSibling); _kb.addObjectProperty(hasUncle); _kb.addIndividual(c11); _kb.addIndividual(c12); _kb.addIndividual(p1a); _kb.addIndividual(p2a); _kb.addPropertyValue(hasParent, c11, p1a); _kb.addPropertyValue(hasSibling, c11, c12); _kb.addPropertyValue(hasParent, c12, p1a); _kb.addPropertyValue(hasSibling, c12, c11); _kb.addPropertyValue(hasSibling, p1a, p2a); _kb.addType(p2a, male); final AtomIVariable x = new AtomIVariable("x"), y = new AtomIVariable("y"), z = new AtomIVariable("z"); _kb.addRule(new Rule(Arrays.asList(new RuleAtom[] { new IndividualPropertyAtom(hasUncle, y, z) }), Arrays.asList(new RuleAtom[] { new IndividualPropertyAtom(hasParent, y, x), new ClassAtom(male, z), new IndividualPropertyAtom(hasSibling, x, z), }))); assertIteratorValues(_kb.getObjectPropertyValues(hasUncle, c11).iterator(), new Object[] { p2a, }); }