use of fr.lirmm.graphik.graal.api.core.Rule in project graal by graphik-team.
the class OWLAxiomParser method disjointPropertiesAxiom.
private Iterable<? extends Object> disjointPropertiesAxiom(Iterable<? extends OWLPropertyExpression> properties) {
Collection<Rule> rules = GraalUtils.<Rule>createCollection();
InMemoryAtomSet a, a1, a2;
Iterator<? extends OWLPropertyExpression> it1, it2;
it1 = properties.iterator();
while (it1.hasNext()) {
OWLPropertyExpression propExpr = (OWLPropertyExpression) it1.next();
a1 = propExpr.accept(propertyVisitorXY);
it1.remove();
it2 = properties.iterator();
while (it2.hasNext()) {
OWLPropertyExpression next = (OWLPropertyExpression) it2.next();
a2 = next.accept(propertyVisitorXY);
a = GraalUtils.createAtomSet();
a.addAll(a1);
a.addAll(a2);
rules.add(new DefaultNegativeConstraint(a));
}
}
return rules;
}
use of fr.lirmm.graphik.graal.api.core.Rule in project graal by graphik-team.
the class DlgpParserTest method parseRuleWithPrefix.
@Test
public void parseRuleWithPrefix() throws ParseException {
Rule r = DlgpParser.parseRule("@prefix ex: <http://example.com/> ex:p(X,Y) :- ex:q(X,Z).");
Atom body = r.getBody().iterator().next();
Assert.assertTrue(body.getTerm(0).isVariable());
Assert.assertTrue(body.getTerm(1).isVariable());
Atom head = r.getHead().iterator().next();
Assert.assertTrue(head.getTerm(0).isVariable());
Assert.assertTrue(head.getTerm(1).isVariable());
}
use of fr.lirmm.graphik.graal.api.core.Rule in project graal by graphik-team.
the class OWLAxiomParser method visit.
@Override
public Iterable<? extends Object> visit(OWLInverseFunctionalObjectPropertyAxiom arg) {
InMemoryAtomSet body = arg.getProperty().accept(propertyVisitorXZ);
body.addAll(arg.getProperty().accept(propertyVisitorYZ));
InMemoryAtomSet head = GraalUtils.createAtomSet(new DefaultAtom(equalityPredicate, glueVarX, glueVarY));
return Collections.<Rule>singleton(DefaultRuleFactory.instance().create(body, head));
}
use of fr.lirmm.graphik.graal.api.core.Rule in project graal by graphik-team.
the class OWL2ParserTest method dataExactCardinality0.
@Test
public void dataExactCardinality0() throws OWL2ParserException {
OWL2Parser parser = new OWL2Parser(PREFIXES + ":A rdf:type owl:Class . " + ":B rdf:type owl:Datatype . " + ":p rdf:type owl:DatatypeProperty . " + " :A rdfs:subClassOf [ rdf:type owl:Restriction ; " + " owl:onProperty :p ; " + " owl:onDataRange :B ; " + " owl:qualifiedCardinality 0 ] . ");
int nbRules = 0;
while (parser.hasNext()) {
Object o = parser.next();
if (o instanceof Rule) {
++nbRules;
}
}
parser.close();
Assert.assertEquals("Number of assertions found:", 1, nbRules);
}
use of fr.lirmm.graphik.graal.api.core.Rule in project graal by graphik-team.
the class OWL2ParserTest method disjointProperty.
@Test
public void disjointProperty() {
// ! :- q(X, Y), p(X, Y).
try {
OWL2Parser parser = new OWL2Parser(PREFIXES + ":p rdf:type owl:ObjectProperty . " + ":q rdf:type owl:ObjectProperty . " + ":p owl:propertyDisjointWith :q .");
int nbRules = 0;
while (parser.hasNext()) {
Object o = parser.next();
if (o instanceof Rule) {
++nbRules;
Rule r = (Rule) o;
CloseableIteratorWithoutException<Atom> it = r.getBody().iterator();
Atom a1 = (Atom) it.next();
Atom a2 = (Atom) it.next();
Assert.assertFalse(it.hasNext());
Assert.assertTrue(P.equals(a1.getPredicate()) || Q.equals(a1.getPredicate()));
Assert.assertTrue(P.equals(a2.getPredicate()) || Q.equals(a2.getPredicate()));
Assert.assertTrue(P.equals(a2.getPredicate()) || P.equals(a1.getPredicate()));
Assert.assertTrue(Q.equals(a2.getPredicate()) || Q.equals(a1.getPredicate()));
Assert.assertEquals(a1.getTerm(0), a2.getTerm(0));
Assert.assertEquals(a1.getTerm(1), a2.getTerm(1));
}
}
parser.close();
Assert.assertEquals("Number of assertions found:", 1, nbRules);
} catch (Exception e) {
Assert.assertFalse(e.getMessage(), true);
}
}
Aggregations