Search in sources :

Example 21 with OWL2Parser

use of fr.lirmm.graphik.graal.io.owl.OWL2Parser in project graal by graphik-team.

the class OWL2ParserTest method reflexiveObjectPropertyOf.

@Test
public void reflexiveObjectPropertyOf() {
    // p(X,X) :- Top(X).
    try {
        OWL2Parser parser = new OWL2Parser(PREFIXES + ":p rdf:type owl:ReflexiveProperty . ");
        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 b = it.next();
                Assert.assertFalse(it.hasNext());
                it = r.getHead().iterator();
                Atom h = it.next();
                Assert.assertFalse(it.hasNext());
                Assert.assertEquals(Predicate.TOP, b.getPredicate());
                Assert.assertEquals(P, h.getPredicate());
                Assert.assertEquals(b.getTerm(0), h.getTerm(0));
                Assert.assertEquals(b.getTerm(0), h.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)

Example 22 with OWL2Parser

use of fr.lirmm.graphik.graal.io.owl.OWL2Parser 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 23 with OWL2Parser

use of fr.lirmm.graphik.graal.io.owl.OWL2Parser in project graal by graphik-team.

the class OWL2ParserTest method hasKey.

// /////////////////////////////////////////////////////////////////////////
// HAS KEY
// /////////////////////////////////////////////////////////////////////////
@Test
public void hasKey() throws OWL2ParserException {
    OWL2Parser parser = new OWL2Parser(PREFIXES + ":A a owl:Class . " + ":p a owl:ObjectProperty . " + ":q a owl:ObjectProperty . " + ":A owl:hasKey (:p :q) .");
    int nbAssertions = 0;
    while (parser.hasNext()) {
        Object o = parser.next();
        if (!(o instanceof Prefix)) {
            Assert.assertTrue(o instanceof Rule);
            ++nbAssertions;
        }
    }
    parser.close();
    Assert.assertEquals("Number of assertions found:", 1, nbAssertions);
}
Also used : OWL2Parser(fr.lirmm.graphik.graal.io.owl.OWL2Parser) Prefix(fr.lirmm.graphik.util.Prefix) Rule(fr.lirmm.graphik.graal.api.core.Rule) DefaultNegativeConstraint(fr.lirmm.graphik.graal.core.DefaultNegativeConstraint) Test(org.junit.Test)

Example 24 with OWL2Parser

use of fr.lirmm.graphik.graal.io.owl.OWL2Parser in project graal by graphik-team.

the class OWL2ParserTest method objectPropertyDomain.

@Test
public void objectPropertyDomain() {
    // C(Y) :- p(X, Y).
    try {
        OWL2Parser parser = new OWL2Parser(PREFIXES + ":p rdf:type owl:ObjectProperty . " + ":A rdf:type owl:Class . " + ":p rdfs:domain :A .");
        boolean found = false;
        while (parser.hasNext()) {
            Object o = parser.next();
            if (!(o instanceof Prefix)) {
                Rule r = (Rule) o;
                Atom property = (Atom) r.getBody().iterator().next();
                Assert.assertEquals(P, property.getPredicate());
                Atom classs = (Atom) r.getHead().iterator().next();
                Assert.assertEquals(A, classs.getPredicate());
                Assert.assertEquals(property.getTerm(0), classs.getTerm(0));
                found = true;
            }
        }
        parser.close();
        Assert.assertTrue("Number of assertions found:", found);
    } catch (Exception e) {
        Assert.assertFalse(e.getMessage(), true);
    }
}
Also used : OWL2Parser(fr.lirmm.graphik.graal.io.owl.OWL2Parser) Prefix(fr.lirmm.graphik.util.Prefix) Rule(fr.lirmm.graphik.graal.api.core.Rule) 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)

Example 25 with OWL2Parser

use of fr.lirmm.graphik.graal.io.owl.OWL2Parser in project graal by graphik-team.

the class OWL2ParserTest method subDataPropertyOfAxiom.

// /////////////////////////////////////////////////////////////////////////
// Data Property
// /////////////////////////////////////////////////////////////////////////
@Test
public void subDataPropertyOfAxiom() throws OWL2ParserException {
    OWL2Parser parser = new OWL2Parser(PREFIXES + ":p rdf:type owl:DatatypeProperty . " + ":q rdf:type owl:DatatypeProperty . " + ":p rdfs:subPropertyOf :q. ");
    int nbRules = 0;
    while (parser.hasNext()) {
        Object o = parser.next();
        if (o instanceof Rule) {
            ++nbRules;
            Rule r = (Rule) o;
            CloseableIteratorWithoutException<Atom> bodyIt = r.getBody().iterator();
            CloseableIteratorWithoutException<Atom> headIt = r.getHead().iterator();
            Assert.assertTrue(bodyIt.hasNext());
            Assert.assertTrue(headIt.hasNext());
            Atom body = bodyIt.next();
            Atom head = headIt.next();
            Assert.assertTrue(!body.getTerm(0).isConstant());
            Assert.assertTrue(body.getTerm(0).equals(head.getTerm(0)));
            Assert.assertTrue(!body.getTerm(1).isConstant());
            Assert.assertTrue(body.getTerm(1).equals(head.getTerm(1)));
            Assert.assertEquals(P, body.getPredicate());
            Assert.assertEquals(Q, head.getPredicate());
            Assert.assertFalse(bodyIt.hasNext());
            Assert.assertFalse(headIt.hasNext());
        }
    }
    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) Atom(fr.lirmm.graphik.graal.api.core.Atom) Test(org.junit.Test)

Aggregations

OWL2Parser (fr.lirmm.graphik.graal.io.owl.OWL2Parser)71 Test (org.junit.Test)71 DefaultNegativeConstraint (fr.lirmm.graphik.graal.core.DefaultNegativeConstraint)65 Rule (fr.lirmm.graphik.graal.api.core.Rule)50 Atom (fr.lirmm.graphik.graal.api.core.Atom)41 Prefix (fr.lirmm.graphik.util.Prefix)21 OWL2ParserException (fr.lirmm.graphik.graal.io.owl.OWL2ParserException)13 CloseableIteratorWithoutException (fr.lirmm.graphik.util.stream.CloseableIteratorWithoutException)13 IteratorException (fr.lirmm.graphik.util.stream.IteratorException)13 InMemoryAtomSet (fr.lirmm.graphik.graal.api.core.InMemoryAtomSet)10 AtomSet (fr.lirmm.graphik.graal.api.core.AtomSet)4 Term (fr.lirmm.graphik.graal.api.core.Term)4