Search in sources :

Example 51 with Atom

use of fr.lirmm.graphik.graal.api.core.Atom in project graal by graphik-team.

the class OWLPropertyExpressionVisitorImpl method visit.

@Override
public InMemoryAtomSet visit(OWLObjectInverseOf property) {
    Predicate p = GraalUtils.createPredicate(property.getInverse());
    Atom a = DefaultAtomFactory.instance().create(p, glueVariable2, glueVariable1);
    return GraalUtils.createAtomSet(a);
}
Also used : Atom(fr.lirmm.graphik.graal.api.core.Atom) Predicate(fr.lirmm.graphik.graal.api.core.Predicate)

Example 52 with Atom

use of fr.lirmm.graphik.graal.api.core.Atom in project graal by graphik-team.

the class OWLPropertyExpressionVisitorImpl method visit.

@Override
public InMemoryAtomSet visit(OWLDataProperty property) {
    Predicate p = GraalUtils.createPredicate(property);
    Atom a = DefaultAtomFactory.instance().create(p, glueVariable1, glueVariable2);
    return GraalUtils.createAtomSet(a);
}
Also used : Atom(fr.lirmm.graphik.graal.api.core.Atom) Predicate(fr.lirmm.graphik.graal.api.core.Predicate)

Example 53 with Atom

use of fr.lirmm.graphik.graal.api.core.Atom 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 54 with Atom

use of fr.lirmm.graphik.graal.api.core.Atom in project graal by graphik-team.

the class OWL2ParserTest method equivalentProperty.

@Test
public void equivalentProperty() {
    // q(X, Y) <-> p(X, Y).
    try {
        OWL2Parser parser = new OWL2Parser(PREFIXES + ":p rdf:type owl:ObjectProperty . " + ":q rdf:type owl:ObjectProperty . " + ":p owl:equivalentProperty :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.assertTrue(Q.equals(property.getPredicate()) || P.equals(property.getPredicate()));
                Assert.assertTrue(Q.equals(subProperty.getPredicate()) || P.equals(subProperty.getPredicate()));
                Assert.assertEquals(property.getTerm(0), subProperty.getTerm(0));
                Assert.assertEquals(property.getTerm(1), subProperty.getTerm(1));
            }
        }
        parser.close();
        Assert.assertEquals("Number of assertions found:", 2, 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 55 with Atom

use of fr.lirmm.graphik.graal.api.core.Atom in project graal by graphik-team.

the class RuleMLWriter method writeAtomSet.

protected void writeAtomSet(CloseableIterator<Atom> it) throws IOException {
    while (it.hasNext()) {
        Atom a = it.next();
        this.writeAtom(a);
    }
    it.close();
}
Also used : Atom(fr.lirmm.graphik.graal.api.core.Atom)

Aggregations

Atom (fr.lirmm.graphik.graal.api.core.Atom)269 Test (org.junit.Test)97 Term (fr.lirmm.graphik.graal.api.core.Term)86 Rule (fr.lirmm.graphik.graal.api.core.Rule)64 Substitution (fr.lirmm.graphik.graal.api.core.Substitution)41 OWL2Parser (fr.lirmm.graphik.graal.io.owl.OWL2Parser)41 InMemoryAtomSet (fr.lirmm.graphik.graal.api.core.InMemoryAtomSet)40 LinkedList (java.util.LinkedList)40 DefaultNegativeConstraint (fr.lirmm.graphik.graal.core.DefaultNegativeConstraint)36 Predicate (fr.lirmm.graphik.graal.api.core.Predicate)35 Theory (org.junit.experimental.theories.Theory)35 ConjunctiveQuery (fr.lirmm.graphik.graal.api.core.ConjunctiveQuery)34 Variable (fr.lirmm.graphik.graal.api.core.Variable)33 DefaultAtom (fr.lirmm.graphik.graal.core.DefaultAtom)31 IteratorException (fr.lirmm.graphik.util.stream.IteratorException)29 LinkedListAtomSet (fr.lirmm.graphik.graal.core.atomset.LinkedListAtomSet)28 AtomSetException (fr.lirmm.graphik.graal.api.core.AtomSetException)27 HomomorphismException (fr.lirmm.graphik.graal.api.homomorphism.HomomorphismException)14 CloseableIteratorWithoutException (fr.lirmm.graphik.util.stream.CloseableIteratorWithoutException)14 OWL2ParserException (fr.lirmm.graphik.graal.io.owl.OWL2ParserException)13