Search in sources :

Example 61 with OWL2Parser

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

the class OWL2ParserTest method complexDataMinCardinality0InRightHandSide.

@Test
public void complexDataMinCardinality0InRightHandSide() throws OWL2ParserException {
    OWL2Parser parser = new OWL2Parser(PREFIXES + ":D rdf:type rdfs:Datatype . " + ":B rdf:type owl:Class . " + ":p rdf:type owl:DatatypeProperty . " + " :B rdfs:subClassOf [a owl:Restriction; owl:onProperty :p; owl:someValuesFrom [ rdf:type owl:Restriction ; " + " owl:onProperty :p ; " + " owl:onDataRange :D ; " + " owl:minCardinality 0 ] ]. ");
    int nbAssertions = 0;
    while (parser.hasNext()) {
        Object o = parser.next();
        if (!(o instanceof Prefix)) {
            ++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) DefaultNegativeConstraint(fr.lirmm.graphik.graal.core.DefaultNegativeConstraint) Test(org.junit.Test)

Example 62 with OWL2Parser

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

the class OWL2ParserTest method complexSubClassExpression.

@Test
public void complexSubClassExpression() 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 . " + ":E rdf:type owl:Class . " + ":p rdf:type owl:ObjectProperty . " + "[ owl:intersectionOf ( " + "		:B [ owl:unionOf ( " + "				:E [rdf:type owl:Restriction ;	" + "					owl:onProperty :p ;" + "					owl:someValuesFrom [" + "							owl:unionOf ( :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());
            bodyIt.next();
            Assert.assertTrue(bodyIt.hasNext());
            Assert.assertTrue(headIt.hasNext());
            Atom head = headIt.next();
            Assert.assertEquals(A, head.getPredicate());
            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 63 with OWL2Parser

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

the class OWL2ParserTest method dataPropertyRangeAxiom.

@Test
public void dataPropertyRangeAxiom() throws OWL2ParserException {
    // D(Y) :- p(X, Y).
    OWL2Parser parser = new OWL2Parser(PREFIXES + ":p rdf:type owl:DatatypeProperty . " + ":D rdf:type rdfs:Datatype ." + ":p rdfs:range :D .");
    boolean found = false;
    while (parser.hasNext()) {
        Object o = parser.next();
        if (!(o instanceof Prefix)) {
            Assert.assertTrue(o instanceof Rule);
            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(D, classs.getPredicate());
            Assert.assertEquals(property.getTerm(1), classs.getTerm(0));
            found = true;
        }
    }
    parser.close();
    Assert.assertTrue("Number of assertions found:", found);
}
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) Test(org.junit.Test)

Example 64 with OWL2Parser

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

the class OWL2ParserTest method intersectionOfUnion.

// /////////////////////////////////////////////////////////////////////////
// DISJUNCTIVE NORMAL FORM TEST
// /////////////////////////////////////////////////////////////////////////
@Test
public void intersectionOfUnion() 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:intersectionOf ( :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:", 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)

Example 65 with OWL2Parser

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

the class OWL2ParserTest method complexObjectMaxCardinality1.

@Test
public void complexObjectMaxCardinality1() throws OWL2ParserException {
    OWL2Parser parser = new OWL2Parser(PREFIXES + ":A rdf:type owl:Class . " + ":B rdf:type owl:Class . " + ":C rdf:type owl:Class . " + ":p rdf:type owl:ObjectProperty . " + ":q rdf:type owl:ObjectProperty . " + ":r rdf:type owl:ObjectProperty . " + " [a owl:Restriction; owl:onProperty :r; owl:someValuesFrom :A ] rdfs:subClassOf [ rdf:type owl:Restriction ; " + " owl:onProperty :p ; " + " owl:onClass [ owl:unionOf ( [a owl:Restriction; owl:onProperty :q; owl:someValuesFrom :B ] :C ) ] ; " + " owl:maxCardinality 1 ] . ");
    int nbRules = 0;
    while (parser.hasNext()) {
        if (parser.next() 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)

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