Search in sources :

Example 56 with OWL2Parser

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

the class OWL2ParserTest method unionOfUnion.

@Test
public void unionOfUnion() throws OWL2ParserException {
    OWL2Parser parser = new OWL2Parser(PREFIXES + ":ClassA rdf:type owl:Class . " + ":ClassB rdf:type owl:Class . " + ":ClassC rdf:type owl:Class . " + ":ClassD rdf:type owl:Class . " + "[ owl:unionOf ( :ClassA [ owl:unionOf ( :ClassB :ClassC ) ] ) ] rdfs:subClassOf :ClassD. ");
    int nbRules = 0;
    while (parser.hasNext()) {
        Object o = parser.next();
        if (o instanceof Rule) {
            ++nbRules;
        }
    }
    parser.close();
    Assert.assertEquals("Number of assertions found:", 3, 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 57 with OWL2Parser

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

the class OWL2ParserTest method asymetricObjectPropertyOf.

@Test
public void asymetricObjectPropertyOf() {
    // ! :- q(X, Y), q(X, Y).
    try {
        OWL2Parser parser = new OWL2Parser(PREFIXES + ":p rdf:type owl:AsymmetricProperty . ");
        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.assertEquals(P, a1.getPredicate());
                Assert.assertEquals(P, a2.getPredicate());
                Assert.assertEquals(a1.getTerm(0), a2.getTerm(1));
                Assert.assertEquals(a1.getTerm(1), a2.getTerm(0));
            }
        }
        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 58 with OWL2Parser

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

the class OWL2ParserTest method objectUnionOf.

// /////////////////////////////////////////////////////////////////////////
// SUB CLASS EXPRESSION
// /////////////////////////////////////////////////////////////////////////
@Test
public void objectUnionOf() throws OWL2ParserException {
    OWL2Parser parser = new OWL2Parser(PREFIXES + ":A rdf:type owl:Class . " + ":B rdf:type owl:Class . " + ":C rdf:type owl:Class . " + ":D rdf:type owl:Class . " + "[ owl:unionOf ( :B :C :D ) ] rdfs:subClassOf :A . ");
    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.assertEquals(A, head.getPredicate());
            Assert.assertTrue(B.equals(body.getPredicate()) || C.equals(body.getPredicate()) || D.equals(body.getPredicate()));
            Assert.assertFalse(bodyIt.hasNext());
            Assert.assertFalse(headIt.hasNext());
        }
    }
    parser.close();
    Assert.assertEquals("Number of assertions found:", 3, 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)

Example 59 with OWL2Parser

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

the class OWL2ParserTest method illegalAllValuesFromMaskedInUnion.

@Test
public void illegalAllValuesFromMaskedInUnion() throws OWL2ParserException {
    OWL2Parser parser = new OWL2Parser(PREFIXES + " :A a owl:Class. " + ":B a owl:Class. :C a owl:Class. " + ":p a owl:ObjectProperty. " + "[owl:unionOf ( :A [rdf:type owl:Restriction; " + "        owl:onProperty :p ; " + "        owl:allValuesFrom :B] ) ] rdfs:subClassOf :C .");
    int nbAssertion = 0;
    while (parser.hasNext()) {
        Object o = parser.next();
        if (!(o instanceof Prefix)) {
            ++nbAssertion;
        }
    }
    parser.close();
    Assert.assertEquals("Number of assertions found:", 1, nbAssertion);
}
Also used : OWL2Parser(fr.lirmm.graphik.graal.io.owl.OWL2Parser) Prefix(fr.lirmm.graphik.util.Prefix) DefaultNegativeConstraint(fr.lirmm.graphik.graal.core.DefaultNegativeConstraint) Test(org.junit.Test)

Example 60 with OWL2Parser

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

the class OWL2ParserTest method dataSomeValuesFrom.

@Test
public void dataSomeValuesFrom() throws OWL2ParserException {
    // p(X,Y) D(Y) :- A(X).
    OWL2Parser parser = new OWL2Parser(PREFIXES + ":A a owl:Class. " + ":D a rdfs:Datatype. " + ":p rdf:type owl:DatatypeProperty . " + ":A rdfs:subClassOf [a owl:Restriction; owl:onProperty :p; owl:someValuesFrom :D].");
    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)

Aggregations

OWL2Parser (fr.lirmm.graphik.graal.io.owl.OWL2Parser)73 Test (org.junit.Test)73 DefaultNegativeConstraint (fr.lirmm.graphik.graal.core.DefaultNegativeConstraint)67 Rule (fr.lirmm.graphik.graal.api.core.Rule)52 Atom (fr.lirmm.graphik.graal.api.core.Atom)41 Prefix (fr.lirmm.graphik.util.Prefix)23 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