@Test public void ruleTest1b() throws Exception { final OWLAxiom[] axioms = { OWL.classAssertion(_a, _A), OWL.classAssertion(_b, _B), OWL.propertyAssertion(_a, _p, _b), SWRL.rule(SWRL.antecedent(SWRL.classAtom(_A, _x)), SWRL.consequent(SWRL.classAtom(_B, _x))), SWRL.rule(SWRL.antecedent(SWRL.classAtom(_B, _x), SWRL.propertyAtom(_p, _x, _y), SWRL.classAtom(_B, _y)), SWRL.consequent(SWRL.classAtom(_C, _x))) }; setupGenerators(Stream.of(axioms)); testExplanations(OWL.classAssertion(_a, _A), 0, new OWLAxiom[] { axioms[0] }); testExplanations(OWL.classAssertion(_a, _B), 0, new OWLAxiom[] { axioms[0], axioms[3] }); testExplanations(OWL.classAssertion(_a, _C), 1, axioms); }
@Test public void ruleBuiltinTest2() throws Exception { final OWLAxiom[] axioms = { OWL.classAssertion(_a, _A), OWL.propertyAssertion(_a, dp, OWL.constant(9)), SWRL.rule(SWRL.antecedent(SWRL.classAtom(_A, _x), SWRL.propertyAtom(dp, _x, _dx), SWRL.greaterThan(_dx, SWRL.constant(5)), SWRL.lessThan(_dx, SWRL.constant(10))), SWRL.consequent(SWRL.classAtom(_B, _x))) }; setupGenerators(Stream.of(axioms)); testExplanations(OWL.classAssertion(_a, _B), 0, axioms); }
public static SWRLRule rule(final IRI uri, final Set<? extends SWRLAtom> antecendent, final Set<? extends SWRLAtom> consequent) { if (null == uri) return OWL._factory.getSWRLRule(antecendent, consequent); return OWL._factory.getSWRLRule(antecendent, consequent, Collections.singleton(labelAnnotation(uri))); }
final OWLNamedIndividual a = OWL.Individual(NS + "A"); final OWLNamedIndividual b = OWL.Individual(NS + "B"); final SWRLIndividualArgument swrlIndA = SWRL.individual(a); final SWRLIndividualArgument swrlIndB = SWRL.individual(b); final OWLLiteral ten = OWL.constant(10.); final OWLLiteral eleven = OWL.constant(11.); final SWRLVariable varX = SWRL.variable(NS + "x"); final SWRLVariable varY = SWRL.variable(NS + "y"); final SWRLLiteralArgument sup = SWRL.constant("sup"); final SWRLLiteralArgument inf = SWRL.constant("inf"); owl.addAxiom(SWRL.rule(// SWRL.antecedent(// SWRL.propertyAtom(dpA, swrlIndA, varX), // SWRL.propertyAtom(dpA, swrlIndB, varY), // SWRL.greaterThan(varX, varY)), // SWRL.consequent(SWRL.propertyAtom(dpB, swrlIndA, sup)))); owl.addAxiom(SWRL.rule(// SWRL.antecedent(// SWRL.propertyAtom(dpA, swrlIndA, varX), // SWRL.propertyAtom(dpA, swrlIndB, varY), // SWRL.lessThan(varX, varY)), // SWRL.consequent(SWRL.propertyAtom(dpB, swrlIndA, inf))));
@Test public void ruleBuiltinTest3() throws Exception { final SWRLVariable y = SWRL.variable(ontologyURI + "year"); final SWRLVariable m = SWRL.variable(ontologyURI + "month"); final SWRLVariable d = SWRL.variable(ontologyURI + "day"); final OWLDataProperty year = OWL.DataProperty(ontologyURI + "year"); final OWLDataProperty month = OWL.DataProperty(ontologyURI + "month"); final OWLDataProperty day = OWL.DataProperty(ontologyURI + "day"); final OWLAxiom[] axioms = { // OWL.propertyAssertion(_a, dp, // OWL.constant("2009-01-02", XSD.DATE)), // SWRL.rule(// SWRL.antecedent(SWRL.propertyAtom(dp, _x, _dx), // SWRL.builtIn(SWRLBuiltInsVocabulary.DATE, _dx, y, m, d)), // SWRL.consequent(SWRL.propertyAtom(year, _x, y), // SWRL.propertyAtom(month, _x, m), // SWRL.propertyAtom(day, _x, d)// )// ) // }; setupGenerators(Stream.of(axioms)); testExplanations(OWL.propertyAssertion(_a, year, OWL.constant(2009)), 1, new OWLAxiom[] { axioms[0], axioms[1] }); }
@Test public void testAxiomConverterRules1() { final KnowledgeBase kb = new KnowledgeBaseImpl(); final AxiomConverter converter = new AxiomConverter(kb, OWL._factory); final ATermAppl C = ATermUtils.makeTermAppl("C"); final ATermAppl D = ATermUtils.makeTermAppl("D"); final ATermAppl x = ATermUtils.makeVar("x"); kb.addClass(C); kb.addClass(D); final ATermAppl[] head = new ATermAppl[] { ATermUtils.makeTypeAtom(x, D) }; final ATermAppl[] body = new ATermAppl[] { ATermUtils.makeTypeAtom(x, C) }; final ATermAppl rule = ATermUtils.makeRule(head, body); final OWLAxiom actual = converter.convert(rule); final Set<SWRLAtom> antecedent = new HashSet<>(); final Set<SWRLAtom> consequent = new HashSet<>(); antecedent.add(classAtom(Class("C"), variable("x"))); consequent.add(classAtom(Class("D"), variable("x"))); final OWLAxiom expected = rule(antecedent, consequent); assertEquals(expected, actual); }
@Test public void testAxiomConverterRules4() { final KnowledgeBase kb = new KnowledgeBaseImpl(); final AxiomConverter converter = new AxiomConverter(kb, OWL._manager.getOWLDataFactory()); final ATermAppl r = ATermUtils.makeTermAppl("r"); final ATermAppl s = ATermUtils.makeTermAppl("s"); final ATermAppl x = ATermUtils.makeVar("x"); final ATermAppl y = ATermUtils.makeVar("y"); kb.addDatatypeProperty(r); kb.addDatatypeProperty(s); final ATermAppl[] head = new ATermAppl[] { ATermUtils.makePropAtom(r, x, y) }; final ATermAppl[] body = new ATermAppl[] { ATermUtils.makePropAtom(s, x, y) }; final ATermAppl rule = ATermUtils.makeRule(head, body); final OWLAxiom actual = converter.convert(rule); final Set<SWRLAtom> antecedent = new HashSet<>(); final Set<SWRLAtom> consequent = new HashSet<>(); antecedent.add(propertyAtom(DataProperty("s"), variable("x"), variable("y"))); consequent.add(propertyAtom(DataProperty("r"), variable("x"), variable("y"))); final OWLAxiom expected = rule(antecedent, consequent); assertEquals(expected, actual); }
@Test public void testAxiomConverterRules2() { final KnowledgeBase kb = new KnowledgeBaseImpl(); final AxiomConverter converter = new AxiomConverter(kb, OWL._manager.getOWLDataFactory()); final ATermAppl C = ATermUtils.makeTermAppl("C"); final ATermAppl D = ATermUtils.makeTermAppl("D"); final ATermAppl i = ATermUtils.makeTermAppl("i"); kb.addClass(C); kb.addClass(D); kb.addIndividual(i); final ATermAppl[] head = new ATermAppl[] { ATermUtils.makeTypeAtom(i, D) }; final ATermAppl[] body = new ATermAppl[] { ATermUtils.makeTypeAtom(i, C) }; final ATermAppl rule = ATermUtils.makeRule(head, body); final OWLAxiom actual = converter.convert(rule); final Set<SWRLAtom> antecedent = new HashSet<>(); final Set<SWRLAtom> consequent = new HashSet<>(); antecedent.add(classAtom(Class("C"), SWRL.individual(OWL.Individual("i")))); consequent.add(classAtom(Class("D"), SWRL.individual(OWL.Individual("i")))); final OWLAxiom expected = rule(antecedent, consequent); assertEquals(expected, actual); }
axiom = _factory.getSWRLRule(antecedent, consequent); else axiom = SWRL.rule(name.getAFun().getName(), antecedent, consequent); // FIXME : make an SWRL producer that take an factory as parameter.
final OWLNamedIndividual a = OWL.Individual(NS + "A"); final OWLNamedIndividual b = OWL.Individual(NS + "B"); final SWRLIndividualArgument swrlIndA = SWRL.individual(a); final OWLLiteral ten = OWL.constant(10.); final OWLLiteral eleven = OWL.constant(11.); final SWRLVariable varX = SWRL.variable(NS + "x"); final SWRLLiteralArgument sup = SWRL.constant("sup"); final SWRLLiteralArgument inf = SWRL.constant("inf"); owl.addAxiom(SWRL.rule(// SWRL.antecedent(// SWRL.propertyAtom(dpA, swrlIndA, varX), // SWRL.greaterThan(varX, SWRL.constant(11.))), // SWRL.consequent(SWRL.propertyAtom(dpB, swrlIndA, sup)))); owl.addAxiom(SWRL.rule(// SWRL.antecedent(// SWRL.propertyAtom(dpA, swrlIndA, varX), // SWRL.lessThan(varX, SWRL.constant(11.))), // SWRL.consequent(SWRL.propertyAtom(dpB, swrlIndA, inf))));
public void testAxiomConverterRules1c() { final KnowledgeBase kb = new KnowledgeBaseImpl(); final AxiomConverter converter = new AxiomConverter(kb, OWL._manager.getOWLDataFactory()); final ATermAppl C = ATermUtils.makeTermAppl("C"); final ATermAppl D = ATermUtils.makeTermAppl("D"); final ATermAppl x = ATermUtils.makeVar("x"); final ATermAppl name = ATermUtils.makeBnode("MyRule"); kb.addClass(C); kb.addClass(D); final ATermAppl[] head = new ATermAppl[] { ATermUtils.makeTypeAtom(x, D) }; final ATermAppl[] body = new ATermAppl[] { ATermUtils.makeTypeAtom(x, C) }; final ATermAppl rule = ATermUtils.makeRule(name, head, body); final OWLAxiom actual = converter.convert(rule); final Set<SWRLAtom> antecedent = new HashSet<>(); final Set<SWRLAtom> consequent = new HashSet<>(); antecedent.add(classAtom(Class("C"), variable("x"))); consequent.add(classAtom(Class("D"), variable("x"))); final OWLAxiom expected = rule(name.getArgument(0).toString(), true, antecedent, consequent); assertEquals(expected, actual); }
@Test public void testAxiomConverterRules3() { final KnowledgeBase kb = new KnowledgeBaseImpl(); final OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); final OWLDataFactory df = manager.getOWLDataFactory(); final AxiomConverter converter = new AxiomConverter(kb, df); final ATermAppl p = ATermUtils.makeTermAppl("p"); final ATermAppl q = ATermUtils.makeTermAppl("q"); final ATermAppl x = ATermUtils.makeVar("x"); final ATermAppl y = ATermUtils.makeVar("y"); kb.addObjectProperty(p); kb.addObjectProperty(q); final ATermAppl[] head = new ATermAppl[] { ATermUtils.makePropAtom(q, x, y) }; final ATermAppl[] body = new ATermAppl[] { ATermUtils.makePropAtom(p, x, y) }; final ATermAppl rule = ATermUtils.makeRule(head, body); final OWLAxiom actual = converter.convert(rule); final Set<SWRLAtom> antecedent = new HashSet<>(); final Set<SWRLAtom> consequent = new HashSet<>(); antecedent.add(propertyAtom(ObjectProperty("p"), variable("x"), variable("y"))); consequent.add(propertyAtom(ObjectProperty("q"), variable("x"), variable("y"))); final OWLAxiom expected = rule(antecedent, consequent); assertEquals(expected, actual); }
axiom = _factory.getSWRLRule(antecedent, consequent); else axiom = SWRL.rule(name.getAFun().getName(), antecedent, consequent); // FIXME : make an SWRL producer that take an factory as parameter.
@Test public void ruleTest1() throws Exception { final OWLAxiom[] axioms = { OWL.classAssertion(_a, _A), OWL.classAssertion(_b, _B), OWL.propertyAssertion(_a, _p, _b), SWRL.rule(SWRL.antecedent(SWRL.classAtom(_A, _x)), SWRL.consequent(SWRL.classAtom(_B, _x))), SWRL.rule(SWRL.antecedent(SWRL.classAtom(_B, _x), SWRL.propertyAtom(_p, _x, _y), SWRL.classAtom(_B, _y)), SWRL.consequent(SWRL.classAtom(_C, _x))) }; setupGenerators(Stream.of(axioms)); testExplanations(OWL.classAssertion(_a, _A), 0, new OWLAxiom[] { axioms[0] }); testExplanations(OWL.classAssertion(_a, _B), 0, new OWLAxiom[] { axioms[0], axioms[3] }); testExplanations(OWL.classAssertion(_a, _C), 1, axioms); }
final OWLNamedIndividual a = OWL.Individual(NS + "A"); final OWLNamedIndividual b = OWL.Individual(NS + "B"); final SWRLIndividualArgument swrlIndA = SWRL.individual(a); final SWRLIndividualArgument swrlIndB = SWRL.individual(b); final OWLLiteral ten = OWL.constant(10.); final OWLLiteral eleven = OWL.constant(11.); final SWRLVariable varX = SWRL.variable(NS + "x"); final SWRLVariable varY = SWRL.variable(NS + "y"); final SWRLLiteralArgument sup = SWRL.constant("sup"); final SWRLLiteralArgument inf = SWRL.constant("inf"); owl.addAxiom(SWRL.rule(// SWRL.antecedent(// SWRL.propertyAtom(dpA, swrlIndA, varX), // SWRL.propertyAtom(dpA, swrlIndB, varY), // SWRL.greaterThan(varX, varY)), // SWRL.consequent(SWRL.propertyAtom(dpB, swrlIndA, sup)))); owl.addAxiom(SWRL.rule(// SWRL.antecedent(// SWRL.propertyAtom(dpA, swrlIndA, varX), // SWRL.propertyAtom(dpA, swrlIndB, varY), // SWRL.lessThan(varX, varY)), // SWRL.consequent(SWRL.propertyAtom(dpB, swrlIndA, inf))));
@Test public void ruleBuiltinTest1() throws Exception { final OWLAxiom[] axioms = { OWL.classAssertion(_a, _A), OWL.propertyAssertion(_a, dp, OWL.constant(9)), SWRL.rule(SWRL.antecedent(SWRL.classAtom(_A, _x), SWRL.propertyAtom(dp, _x, _dx), SWRL.lessThan(_dx, SWRL.constant(10))), SWRL.consequent(SWRL.classAtom(_B, _x))) }; setupGenerators(Stream.of(axioms)); testExplanations(OWL.classAssertion(_a, _B), 0, axioms); }
@Test public void testAxiomConverterRules1b() { final KnowledgeBase kb = new KnowledgeBaseImpl(); final AxiomConverter converter = new AxiomConverter(kb, OWL._manager.getOWLDataFactory()); final ATermAppl C = ATermUtils.makeTermAppl("C"); final ATermAppl D = ATermUtils.makeTermAppl("D"); final ATermAppl x = ATermUtils.makeVar("x"); final ATermAppl name = ATermUtils.makeTermAppl("MyRule"); kb.addClass(C); kb.addClass(D); final ATermAppl[] head = new ATermAppl[] { ATermUtils.makeTypeAtom(x, D) }; final ATermAppl[] body = new ATermAppl[] { ATermUtils.makeTypeAtom(x, C) }; final ATermAppl rule = ATermUtils.makeRule(name, head, body); final OWLAxiom actual = converter.convert(rule); final Set<SWRLAtom> antecedent = new HashSet<>(); final Set<SWRLAtom> consequent = new HashSet<>(); antecedent.add(classAtom(Class("C"), variable("x"))); consequent.add(classAtom(Class("D"), variable("x"))); final OWLAxiom expected = rule(name.getName(), antecedent, consequent); assertEquals(expected, actual); }
public static SWRLRule rule(final String label, final Set<? extends SWRLAtom> antecendent, final Set<? extends SWRLAtom> consequent) { if (null == label) return OWL._factory.getSWRLRule(antecendent, consequent); return OWL._factory.getSWRLRule(antecendent, consequent, Collections.singleton(labelAnnotation(label))); }
axiom = _factory.getSWRLRule(antecedent, consequent); else axiom = SWRL.rule(name.getAFun().getName(), antecedent, consequent); // FIXME : make an SWRL producer that take an factory as parameter.
@Test public void ruleTest5() throws Exception { final OWLAxiom[] axioms = { OWL.propertyAssertion(_a, _p, _b), SWRL.rule(SWRL.antecedent(SWRL.propertyAtom(_p, _x, _y)), SWRL.consequent(SWRL.classAtom(_A, _x), SWRL.classAtom(_B, _y))) }; setupGenerators(Stream.of(axioms)); testExplanations(OWL.classAssertion(_a, _A), 1, axioms); testExplanations(OWL.classAssertion(_b, _B), 1, axioms); }