@Override public void visit(final SWRLIndividualArgument iobj) { iobj.getIndividual().accept(this); _swrlIObject = new AtomIConstant(_term); }
@Override public void visit(final SWRLIndividualArgument iobj) { iobj.getIndividual().accept(this); _swrlIObject = new AtomIConstant(_term); }
@Override public void visit(final SWRLIndividualArgument iobj) { iobj.getIndividual().accept(this); _swrlIObject = new AtomIConstant(_term); }
private AtomIObject convertAtomIObject(final ATermAppl t) { if (ATermUtils.isVar(t)) return new AtomIVariable(((ATermAppl) t.getArgument(0)).getName()); else if (_originalKB.isIndividual(t)) return new AtomIConstant(t); else if (ATermUtils.isAnon(t)) return new AtomIConstant(t); throw new InternalReasonerException("Unrecognized term: " + t); }
private AtomIObject convertAtomIObject(final ATermAppl t) { if (ATermUtils.isVar(t)) return new AtomIVariable(((ATermAppl) t.getArgument(0)).getName()); else if (_originalKB.isIndividual(t)) return new AtomIConstant(t); else if (ATermUtils.isAnon(t)) return new AtomIConstant(t); throw new InternalReasonerException("Unrecognized term: " + t); }
public Individual set(final AtomIVariable key, final ATermAppl value) { final AtomIConstant constant = new AtomIConstant(value); final IndividualValueCollector collector = new IndividualValueCollector(); constant.accept(collector); return set(key, collector.getValue()); }
public Individual set(final AtomIVariable key, final ATermAppl value) { final AtomIConstant constant = new AtomIConstant(value); final IndividualValueCollector collector = new IndividualValueCollector(); constant.accept(collector); return set(key, collector.getValue()); }
@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 testDatavalueBindingGeneratorObjects() { final DatavaluedPropertyAtom pattern = new DatavaluedPropertyAtom(dp2, new AtomIConstant(mary), _z); final BindingHelper genHelper = new DatavaluePropertyBindingHelper(_kb.getABox(), pattern); final BindingGenerator gen = new BindingGeneratorImpl(new VariableBinding(_kb.getABox()), Collections.singletonList(genHelper)); assertIteratorValues(new BindingToMapIterator(gen.iterator()), new Object[] { Collections.singletonMap(_z, data1), Collections.singletonMap(_z, data2), }); }
final AtomIConstant arg = new AtomIConstant(nominal); final RuleAtom atom = new IndividualPropertyAtom(p, var, arg); atoms.add(atom);
final AtomIConstant arg = new AtomIConstant(nominal); final RuleAtom atom = new IndividualPropertyAtom(p, var, arg); atoms.add(atom);
private AtomIObject createRuleIObject(final Node node) { if (hasObject(node, RDF.type.asNode(), SWRL.Variable.asNode())) return new AtomIVariable(node.getURI()); else { final ATermAppl term = node2term(node); if (defineIndividual(term)) return new AtomIConstant(node2term(node)); else { addUnsupportedFeature("Cannot create rule _individual object for _node " + node); return null; } } }
private AtomIObject createRuleIObject(final Node node) { if (hasObject(node, RDF.type.asNode(), SWRL.Variable.asNode())) return new AtomIVariable(node.getURI()); else { final ATermAppl term = node2term(node); if (defineIndividual(term)) return new AtomIConstant(node2term(node)); else { addUnsupportedFeature("Cannot create rule _individual object for _node " + node); return null; } } }
private AtomIObject createRuleIObject(final Node node) { if (hasObject(node, RDF.type.asNode(), SWRL.Variable.asNode())) return new AtomIVariable(node.getURI()); else { final ATermAppl term = node2term(node); if (defineIndividual(term)) return new AtomIConstant(node2term(node)); else { addUnsupportedFeature("Cannot create rule _individual object for _node " + node); return null; } } }
@Test public void testLookupIndividuals() { OpenlletOptions.KEEP_ABOX_ASSERTIONS = true; final KnowledgeBase kb = new KnowledgeBaseImpl(); final ATermAppl C = term("C"); final ATermAppl D = term("D"); final ATermAppl i = term("i"); final ATermAppl j = term("j"); kb.addClass(C); kb.addClass(D); kb.addIndividual(i); kb.addIndividual(j); kb.addSubClass(C, D); kb.addType(i, C); kb.addType(j, D); final Rule rule = new Rule(Collections.singletonList(new ClassAtom(C, new AtomIConstant(i))), Collections.singletonList(new ClassAtom(D, new AtomIConstant(j)))); kb.addRule(rule); final OntBuilder builder = new OntBuilder(kb); final Set<ATermAppl> rules = new HashSet<>(); rules.add(ATermUtils.makeRule(new ATermAppl[] { ATermUtils.makeTypeAtom(i, C) }, new ATermAppl[] { ATermUtils.makeTypeAtom(j, D) })); final KnowledgeBase copy = builder.build(rules); Assert.assertEquals(1, copy.getRules().size()); }
@Test public void testNoVarTypeAtom() { classes(_A, _B, _C); dataProperties(_q); individuals(_a, _b); _kb.addType(_a, _A); _kb.addType(_b, _B); 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 ClassAtom(_B, new AtomIConstant(_b))); 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 ClassAtom(_A, new AtomIConstant(_b))); head = Arrays.<RuleAtom> asList(new DatavaluedPropertyAtom(_q, x, new AtomDConstant(f))); _kb.addRule(new Rule(head, body)); body = Arrays.<RuleAtom> asList(new ClassAtom(_B, x)); head = Arrays.<RuleAtom> asList(new ClassAtom(_C, x)); _kb.addRule(new Rule(head, body)); assertIteratorValues(_kb.getDataPropertyValues(_q, _a).iterator(), t); assertIteratorValues(_kb.getDataPropertyValues(_q, _b).iterator()); assertIteratorValues(_kb.getInstances(_C).iterator(), _b); }
@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 testNoSharedVar() { classes(_A); dataProperties(_p, _q); objectProperties(_r); individuals(_a, _b, _c); _kb.addType(_a, _A); _kb.addPropertyValue(_p, _b, TermFactory.literal(true)); _kb.addPropertyValue(_r, _b, _c); final ATermAppl t = TermFactory.literal("t"); final ATermAppl f = TermFactory.literal("f"); final AtomIVariable x = new AtomIVariable("x"); final AtomDVariable y = new AtomDVariable("y"); List<RuleAtom> body = Arrays.<RuleAtom> asList(new ClassAtom(_A, x), new DatavaluedPropertyAtom(_p, new AtomIConstant(_b), y), new BuiltInAtom(SWRLB + "equal", 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 DatavaluedPropertyAtom(_p, new AtomIConstant(_b), y), new BuiltInAtom(SWRLB + "equal", 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 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 propertyAtomWithAConstant() { final ATermAppl A = term("A"); final ATermAppl p = term("p"); final ATermAppl a = term("a"); final ATermAppl b = term("b"); final ATermAppl c = term("c"); _kb.addClass(A); _kb.addObjectProperty(p); _kb.addIndividual(a); _kb.addIndividual(b); _kb.addIndividual(c); _kb.addPropertyValue(p, a, b); _kb.addPropertyValue(p, b, c); _kb.addPropertyValue(p, c, c); final AtomIVariable x = new AtomIVariable("x"); final List<RuleAtom> body = Arrays.<RuleAtom> asList(new IndividualPropertyAtom(p, x, new AtomIConstant(c))); final List<RuleAtom> head = Arrays.<RuleAtom> asList(new ClassAtom(A, x)); _kb.addRule(new Rule(head, body)); assertTrue(_kb.isConsistent()); assertFalse(_kb.isType(a, A)); assertTrue(_kb.isType(b, A)); assertTrue(_kb.isType(c, A)); }