Search in sources :

Example 16 with OWL2Parser

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

the class OWL2ParserTest method classAssertion.

// /////////////////////////////////////////////////////////////////////////
// ASSERTIONS
// /////////////////////////////////////////////////////////////////////////
@Test
public void classAssertion() throws OWL2ParserException {
    OWL2Parser parser = new OWL2Parser(PREFIXES + ":A rdf:type owl:Class . " + ":i1 a :A ." + "");
    int nbFacts = 0;
    while (parser.hasNext()) {
        Object o = parser.next();
        if ((o instanceof InMemoryAtomSet)) {
            ++nbFacts;
            CloseableIteratorWithoutException<Atom> it = ((InMemoryAtomSet) o).iterator();
            Assert.assertTrue(it.hasNext());
            Atom a = it.next();
            Assert.assertEquals(A, a.getPredicate());
            Assert.assertEquals(I1, a.getTerm(0));
        }
    }
    parser.close();
    Assert.assertEquals("Number of assertions found:", 1, nbFacts);
}
Also used : OWL2Parser(fr.lirmm.graphik.graal.io.owl.OWL2Parser) InMemoryAtomSet(fr.lirmm.graphik.graal.api.core.InMemoryAtomSet) DefaultNegativeConstraint(fr.lirmm.graphik.graal.core.DefaultNegativeConstraint) Atom(fr.lirmm.graphik.graal.api.core.Atom) Test(org.junit.Test)

Example 17 with OWL2Parser

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

the class OWL2ParserTest method hasKeyWithUnion.

@Test
public void hasKeyWithUnion() throws OWL2ParserException {
    OWL2Parser parser = new OWL2Parser(PREFIXES + ":A a owl:Class . " + ":B a owl:Class . " + ":p a owl:ObjectProperty . " + ":q a owl:DatatypeProperty . " + "[owl:unionOf( :A :B [owl:oneOf (:i1)] ) ] 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:", 6, 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 18 with OWL2Parser

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

the class OWL2ParserTest method subObjectPropertyOf.

// /////////////////////////////////////////////////////////////////////////
// OBJECT PROPERTY AXIOMS
// /////////////////////////////////////////////////////////////////////////
@Test
public void subObjectPropertyOf() {
    // q(X, Y) :- p(X, Y).
    try {
        OWL2Parser parser = new OWL2Parser(PREFIXES + ":p rdf:type owl:ObjectProperty . " + ":q rdf:type owl:ObjectProperty . " + ":p rdfs:subPropertyOf :q .");
        int nbRules = 0;
        while (parser.hasNext()) {
            Object o = parser.next();
            if (o instanceof Rule) {
                ++nbRules;
                Rule r = (Rule) o;
                Atom subProperty = (Atom) r.getBody().iterator().next();
                Atom property = (Atom) r.getHead().iterator().next();
                Assert.assertEquals(P, subProperty.getPredicate());
                Assert.assertEquals(Q, property.getPredicate());
                Assert.assertEquals(subProperty.getTerm(0), property.getTerm(0));
                Assert.assertEquals(subProperty.getTerm(1), property.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 19 with OWL2Parser

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

the class OWL2ParserTest method objectMaxCardinality0.

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

Example 20 with OWL2Parser

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

the class OWL2ParserTest method dataExactCardinality1.

@Test
public void dataExactCardinality1() 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 1 ] . ");
    int nbRules = 0;
    while (parser.hasNext()) {
        Object o = parser.next();
        if (o instanceof Rule) {
            ++nbRules;
        }
    }
    parser.close();
    Assert.assertEquals("Number of assertions found:", 2, 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)

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