Search in sources :

Example 6 with Rule

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;
}
Also used : OWLPropertyExpression(org.semanticweb.owlapi.model.OWLPropertyExpression) DefaultNegativeConstraint(fr.lirmm.graphik.graal.core.DefaultNegativeConstraint) InMemoryAtomSet(fr.lirmm.graphik.graal.api.core.InMemoryAtomSet) Rule(fr.lirmm.graphik.graal.api.core.Rule) SWRLRule(org.semanticweb.owlapi.model.SWRLRule)

Example 7 with Rule

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());
}
Also used : Rule(fr.lirmm.graphik.graal.api.core.Rule) Atom(fr.lirmm.graphik.graal.api.core.Atom) Test(org.junit.Test)

Example 8 with Rule

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));
}
Also used : DefaultAtom(fr.lirmm.graphik.graal.core.DefaultAtom) InMemoryAtomSet(fr.lirmm.graphik.graal.api.core.InMemoryAtomSet) Rule(fr.lirmm.graphik.graal.api.core.Rule) SWRLRule(org.semanticweb.owlapi.model.SWRLRule)

Example 9 with Rule

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);
}
Also used : OWL2Parser(fr.lirmm.graphik.graal.io.owl.OWL2Parser) Rule(fr.lirmm.graphik.graal.api.core.Rule) DefaultNegativeConstraint(fr.lirmm.graphik.graal.core.DefaultNegativeConstraint) Test(org.junit.Test)

Example 10 with Rule

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);
    }
}
Also used : OWL2Parser(fr.lirmm.graphik.graal.io.owl.OWL2Parser) Rule(fr.lirmm.graphik.graal.api.core.Rule) DefaultNegativeConstraint(fr.lirmm.graphik.graal.core.DefaultNegativeConstraint) Atom(fr.lirmm.graphik.graal.api.core.Atom) OWL2ParserException(fr.lirmm.graphik.graal.io.owl.OWL2ParserException) CloseableIteratorWithoutException(fr.lirmm.graphik.util.stream.CloseableIteratorWithoutException) IteratorException(fr.lirmm.graphik.util.stream.IteratorException) Test(org.junit.Test)

Aggregations

Rule (fr.lirmm.graphik.graal.api.core.Rule)141 Test (org.junit.Test)87 Atom (fr.lirmm.graphik.graal.api.core.Atom)64 OWL2Parser (fr.lirmm.graphik.graal.io.owl.OWL2Parser)52 DefaultNegativeConstraint (fr.lirmm.graphik.graal.core.DefaultNegativeConstraint)49 InMemoryAtomSet (fr.lirmm.graphik.graal.api.core.InMemoryAtomSet)26 Substitution (fr.lirmm.graphik.graal.api.core.Substitution)23 LinkedList (java.util.LinkedList)19 IteratorException (fr.lirmm.graphik.util.stream.IteratorException)16 Term (fr.lirmm.graphik.graal.api.core.Term)15 Prefix (fr.lirmm.graphik.util.Prefix)14 CloseableIteratorWithoutException (fr.lirmm.graphik.util.stream.CloseableIteratorWithoutException)14 OWL2ParserException (fr.lirmm.graphik.graal.io.owl.OWL2ParserException)13 Predicate (fr.lirmm.graphik.graal.api.core.Predicate)9 DefaultAtom (fr.lirmm.graphik.graal.core.DefaultAtom)9 AtomSet (fr.lirmm.graphik.graal.api.core.AtomSet)7 KnowledgeBase (fr.lirmm.graphik.graal.api.kb.KnowledgeBase)7 DefaultRule (fr.lirmm.graphik.graal.core.DefaultRule)7 ConjunctiveQuery (fr.lirmm.graphik.graal.api.core.ConjunctiveQuery)6 Variable (fr.lirmm.graphik.graal.api.core.Variable)6