Search in sources :

Example 46 with OWL2Parser

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

the class OWL2ParserTest method illegalAllValuesFromMaskedSomeValuesFrom.

// @Test
// public void assertionDataProperty() {
// try {
// OWLParser parser = new OWLParser(
// "@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . "
// + "@prefix owl: <http://www.w3.org/2002/07/owl#> . "
// + "@prefix test: <http://test.org/> . "
// + "test:property rdf:type owl:DatatypeProperty . "
// + "test:a test:property \"test\" ." + "");
// 
// boolean found = false;
// while (parser.hasNext()) {
// Object o = parser.next();
// if (!(o instanceof Prefix)) {
// Atom a = (Atom) o;
// Assert.assertEquals(new Predicate("test:property", 2),
// a.getPredicate());
// CloseableIteratorWithoutException<Term> it = a.iterator();
// Assert.assertEquals(DefaultTermFactory.instance()
// .createConstant("test:a"), it.next());
// Assert.assertEquals(DefaultTermFactory.instance()
// .createLiteral("test"), it.next());
// found = true;
// }
// }
// 
// Assert.assertTrue("Number of assertions found:", found);
// } catch (Exception e) {
// Assert.assertFalse(e.getMessage(), true);
// }
// }
// /////////////////////////////////////////////////////////////////////////
// MORE COMPLEX TEST
// /////////////////////////////////////////////////////////////////////////
@Test
public void illegalAllValuesFromMaskedSomeValuesFrom() throws OWL2ParserException {
    OWL2Parser parser = new OWL2Parser(PREFIXES + " :A a owl:Class. " + ":B a owl:Class. " + ":p a owl:ObjectProperty. " + "[rdf:type owl:Restriction; " + "    owl:onProperty :p; " + "    owl:someValuesFrom [rdf:type owl:Restriction; " + "        owl:onProperty :p ; " + "        owl:allValuesFrom :A] " + "] rdfs:subClassOf :B .");
    int nbAssertion = 0;
    while (parser.hasNext()) {
        Object o = parser.next();
        if (!(o instanceof Prefix)) {
            ++nbAssertion;
        }
    }
    parser.close();
    Assert.assertEquals("Number of assertions found:", 0, 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 47 with OWL2Parser

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

the class OWL2ParserTest method functionalObjectProperty.

@Test
public void functionalObjectProperty() {
    // Y = Z :- p(X, Y), p(X, Z).
    try {
        OWL2Parser parser = new OWL2Parser(PREFIXES + ":p rdf:type owl:ObjectProperty ; rdf:type owl:FunctionalProperty . ");
        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 b1 = it.next();
                Atom b2 = it.next();
                Assert.assertFalse(it.hasNext());
                it = r.getHead().iterator();
                Atom h = it.next();
                Assert.assertFalse(it.hasNext());
                Assert.assertEquals(P, b1.getPredicate());
                Assert.assertEquals(P, b2.getPredicate());
                Assert.assertEquals(Predicate.EQUALITY, h.getPredicate());
                Assert.assertEquals(b1.getTerm(0), b2.getTerm(0));
                Assert.assertTrue(b1.getTerm(1).equals(h.getTerm(0)) || b1.getTerm(1).equals(h.getTerm(1)));
                Assert.assertTrue(b2.getTerm(1).equals(h.getTerm(0)) || b2.getTerm(1).equals(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 48 with OWL2Parser

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

the class OWL2ParserTest method complexAssertionWithExistential.

@Test
public void complexAssertionWithExistential() throws OWL2ParserException {
    try {
        OWL2Parser parser = new OWL2Parser(PREFIXES + ":A a owl:Class . " + ":B a owl:Class . " + ":p a owl:ObjectProperty . " + "_:x1 a :A. " + "_:y1 a :B. " + "_:x1 :p _:y1. " + "_:x2 a :A. " + "_:y2 a :B. " + "_:x2 :p _:y2. ");
        int nbFacts = 0;
        int nbAtoms = 0;
        while (parser.hasNext()) {
            Object o = parser.next();
            if (o instanceof AtomSet) {
                Term a0 = null, b0 = null, p0 = null, p1 = null;
                ++nbFacts;
                CloseableIterator<Atom> it = ((AtomSet) o).iterator();
                while (it.hasNext()) {
                    Atom a = it.next();
                    ++nbAtoms;
                    if (a.getPredicate().equals(P)) {
                        p0 = a.getTerm(0);
                        p1 = a.getTerm(1);
                    } else if (a.getPredicate().equals(A)) {
                        a0 = a.getTerm(0);
                    } else if (a.getPredicate().equals(B)) {
                        b0 = a.getTerm(0);
                    }
                }
                Assert.assertEquals(p0, a0);
                Assert.assertEquals(p1, b0);
            }
        }
        parser.close();
        Assert.assertEquals("Number of facts found:", 2, nbFacts);
        Assert.assertEquals("Number of atoms found:", 6, nbAtoms);
    } catch (Throwable e) {
        Assert.fail("An exception was found: " + e);
    }
}
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) Term(fr.lirmm.graphik.graal.api.core.Term) DefaultNegativeConstraint(fr.lirmm.graphik.graal.core.DefaultNegativeConstraint) Atom(fr.lirmm.graphik.graal.api.core.Atom) Test(org.junit.Test)

Example 49 with OWL2Parser

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

the class OWL2ParserTest method disjointClassAxiom.

@Test
public void disjointClassAxiom() throws OWL2ParserException {
    OWL2Parser parser = new OWL2Parser(PREFIXES + ":A rdf:type owl:Class . " + ":B rdf:type owl:Class . " + ":C rdf:type owl:Class . " + " _:x rdf:type owl:AllDisjointClasses ; " + " owl:members ( :A :B :C ) . ");
    int nbNegativeConstraint = 0;
    while (parser.hasNext()) {
        Object o = parser.next();
        if (o instanceof DefaultNegativeConstraint) {
            ++nbNegativeConstraint;
            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()) || C.equals(body1.getPredicate()));
            Assert.assertTrue(A.equals(body2.getPredicate()) || B.equals(body2.getPredicate()) || C.equals(body2.getPredicate()));
        }
    }
    parser.close();
    Assert.assertEquals("Number of assertions found:", 3, nbNegativeConstraint);
}
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 50 with OWL2Parser

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

the class OWL2ParserTest method objectOneOf1.

@Test
public void objectOneOf1() throws OWL2ParserException {
    OWL2Parser parser = new OWL2Parser(PREFIXES + ":A rdf:type owl:Class . " + " [ owl:oneOf ( :i1 ) ] " + " rdfs:subClassOf :A . ");
    int nbRules = 0;
    while (parser.hasNext()) {
        Object o = parser.next();
        if (o instanceof InMemoryAtomSet) {
            ++nbRules;
            InMemoryAtomSet a = (InMemoryAtomSet) o;
            CloseableIteratorWithoutException<Atom> bodyIt = a.iterator();
            Assert.assertTrue(bodyIt.hasNext());
            Atom body = bodyIt.next();
            Assert.assertFalse(bodyIt.hasNext());
            Assert.assertEquals(A, body.getPredicate());
            Assert.assertTrue(!body.getTerm(0).isConstant() || body.getTerm(0).equals(I1));
        }
    }
    parser.close();
    Assert.assertEquals("Number of assertions found:", 1, nbRules);
}
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)

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