Search in sources :

Example 51 with OWL2Parser

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

the class OWL2ParserTest method example6.

@Test
public void example6() 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 . " + ":p rdf:type owl:ObjectProperty . " + ":q rdf:type owl:ObjectProperty . " + ":r rdf:type owl:ObjectProperty . " + "[owl:unionOf (" + "		[owl:oneOf ( :i )] " + "		[rdf:type owl:Restriction ;" + "			owl:onProperty :p ;" + "			owl:someValuesFrom :A]" + "	)] " + "	rdfs:subClassOf " + "[owl:intersectionOf ( " + "		[rdf:type owl:Restriction ;" + "			owl:onProperty :q ;" + "			owl:someValuesFrom :B]" + "		[owl:complementOf :C ] " + "		[rdf:type owl:Restriction ;" + "			owl:onProperty :r ;" + "			owl:allValuesFrom :D]" + "	)] . ");
    int nbRules = 0;
    while (parser.hasNext()) {
        Object o = parser.next();
        if (o instanceof Rule || o instanceof AtomSet) {
            ++nbRules;
        }
    }
    parser.close();
    Assert.assertEquals("Number of assertions found:", 6, nbRules);
}
Also used : OWL2Parser(fr.lirmm.graphik.graal.io.owl.OWL2Parser) AtomSet(fr.lirmm.graphik.graal.api.core.AtomSet) InMemoryAtomSet(fr.lirmm.graphik.graal.api.core.InMemoryAtomSet) Rule(fr.lirmm.graphik.graal.api.core.Rule) DefaultNegativeConstraint(fr.lirmm.graphik.graal.core.DefaultNegativeConstraint) Test(org.junit.Test)

Example 52 with OWL2Parser

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

the class OWL2ParserTest method dataRangeIntersection.

@Test
public void dataRangeIntersection() throws OWL2ParserException {
    // D(Y) :- p(X, Y).
    OWL2Parser parser = new OWL2Parser(PREFIXES + ":p rdf:type owl:DatatypeProperty . " + ":D rdf:type rdfs:Datatype ." + ":E rdf:type rdfs:Datatype." + ":p rdfs:range [owl:intersectionOf ( :D :E ) ] .");
    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:", 2, 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 53 with OWL2Parser

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

the class OWL2ParserTest method objectComplementOf.

// /////////////////////////////////////////////////////////////////////////
// SUPER CLASS EXPRESSION
// /////////////////////////////////////////////////////////////////////////
@Test
public void objectComplementOf() throws OWL2ParserException {
    OWL2Parser parser = new OWL2Parser(PREFIXES + ":A rdf:type owl:Class . " + ":B rdf:type owl:Class . " + ":A rdfs:subClassOf [ owl:complementOf :B ]. ");
    int nbRules = 0;
    while (parser.hasNext()) {
        Object o = parser.next();
        if (o instanceof DefaultNegativeConstraint) {
            ++nbRules;
            DefaultNegativeConstraint r = (DefaultNegativeConstraint) o;
            CloseableIteratorWithoutException<Atom> bodyIt = r.getBody().iterator();
            Assert.assertTrue(bodyIt.hasNext());
            Atom body1 = bodyIt.next();
            Assert.assertTrue(bodyIt.hasNext());
            Atom body2 = bodyIt.next();
            Assert.assertFalse(bodyIt.hasNext());
            Assert.assertTrue(!body1.getTerm(0).isConstant());
            Assert.assertTrue(body1.getTerm(0).equals(body2.getTerm(0)));
            Assert.assertTrue(A.equals(body1.getPredicate()) || B.equals(body1.getPredicate()));
            Assert.assertTrue(A.equals(body2.getPredicate()) || B.equals(body2.getPredicate()));
        }
    }
    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) Atom(fr.lirmm.graphik.graal.api.core.Atom) Test(org.junit.Test)

Example 54 with OWL2Parser

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

the class OWL2ParserTest method dataMaxCardinality1.

@Test
public void dataMaxCardinality1() 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:maxCardinality 1 ] . ");
    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 55 with OWL2Parser

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

the class OWL2ParserTest method dataAllValuesFrom.

@Test
public void dataAllValuesFrom() throws OWL2ParserException {
    // D(Y) :- p(X,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:allValuesFrom :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