Search in sources :

Example 66 with Atom

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

the class StickyProperty method check.

public boolean check(MarkedVariableSet markedVariableSet) {
    int nbOccurence;
    for (MarkedRule mrule : markedVariableSet.getMarkedRuleCollection()) {
        for (Term mvar : mrule.markedVars) {
            nbOccurence = 0;
            CloseableIteratorWithoutException<Atom> it = mrule.rule.getBody().iterator();
            while (it.hasNext()) {
                Atom a = it.next();
                for (Term t : a) {
                    if (mvar.equals(t)) {
                        ++nbOccurence;
                        if (nbOccurence > 1) {
                            return false;
                        }
                    }
                }
            }
        }
    }
    return true;
}
Also used : Term(fr.lirmm.graphik.graal.api.core.Term) Atom(fr.lirmm.graphik.graal.api.core.Atom) MarkedRule(fr.lirmm.graphik.graal.rulesetanalyser.graph.MarkedVariableSet.MarkedRule)

Example 67 with Atom

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

the class KBBuilderTest method testAddAtom.

/**
 * Test method for {@link fr.lirmm.graphik.graal.kb.KBBuilder#add(fr.lirmm.graphik.graal.api.core.Atom)}.
 * @throws ParseException
 * @throws KBBuilderException
 * @throws AtomSetException
 */
@Test
public void testAddAtom() throws ParseException, KBBuilderException, AtomSetException {
    // Given
    KBBuilder kbb = new KBBuilder();
    Atom a = DlgpParser.parseAtom("p(a).");
    // When
    kbb.add(a);
    KnowledgeBase kb = kbb.build();
    // Then
    Assert.assertTrue(kb.getFacts().contains(a));
}
Also used : KnowledgeBase(fr.lirmm.graphik.graal.api.kb.KnowledgeBase) Atom(fr.lirmm.graphik.graal.api.core.Atom) Test(org.junit.Test)

Example 68 with Atom

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

the class JointlyAffectedPositionSet method step2.

/**
 * for each rule and for each variable x that occurs only at affected
 * positions in its body, all positions q[j] in its head where occurs x are
 * affected.
 */
protected void step2() {
    InMemoryAtomSet body;
    boolean isAffected;
    int i;
    CloseableIteratorWithoutException<Atom> atomIt;
    Iterator<Term> termIt;
    Atom a;
    Term t;
    boolean fixPoint = false;
    while (!fixPoint) {
        fixPoint = true;
        for (Rule rule : ruleSet) {
            body = rule.getBody();
            for (Variable term : rule.getBody().getVariables()) {
                isAffected = true;
                atomIt = body.iterator();
                while (atomIt.hasNext() && isAffected) {
                    i = -1;
                    a = atomIt.next();
                    termIt = a.iterator();
                    while (termIt.hasNext() && isAffected) {
                        ++i;
                        t = termIt.next();
                        if (term.equals(t)) {
                            if (!isAffected(a.getPredicate(), i)) {
                                isAffected = false;
                            }
                        }
                    }
                }
                if (isAffected) {
                    if (this.affectInHead(rule, term)) {
                        fixPoint = false;
                    }
                }
            }
        }
    }
}
Also used : Variable(fr.lirmm.graphik.graal.api.core.Variable) InMemoryAtomSet(fr.lirmm.graphik.graal.api.core.InMemoryAtomSet) Term(fr.lirmm.graphik.graal.api.core.Term) Rule(fr.lirmm.graphik.graal.api.core.Rule) Atom(fr.lirmm.graphik.graal.api.core.Atom)

Example 69 with Atom

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

the class MarkedVariableSet method mark.

private void mark(Term v, MarkedRule mrule) {
    if (!mrule.markedVars.contains(v)) {
        mrule.markedVars.add(v);
        CloseableIteratorWithoutException<Atom> it = mrule.rule.getBody().iterator();
        while (it.hasNext()) {
            Atom a = it.next();
            int i = 0;
            for (Term t : a) {
                if (v.equals(t)) {
                    this.markedPosition.add(new PredicatePosition(a.getPredicate(), i));
                }
                ++i;
            }
        }
    }
}
Also used : PredicatePosition(fr.lirmm.graphik.graal.rulesetanalyser.util.PredicatePosition) Term(fr.lirmm.graphik.graal.api.core.Term) Atom(fr.lirmm.graphik.graal.api.core.Atom)

Example 70 with Atom

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

the class MarkedVariableSet method firstStep.

/**
 * for each rule Ri and for each variable v occuring in its body, if v does
 * not occur in all atoms of its head, mark (each occurrence of) v in its
 * body;
 */
private void firstStep() {
    for (MarkedRule markedRule : this.markedRuleSet) {
        // put rule in the map
        CloseableIteratorWithoutException<Atom> it = markedRule.rule.getHead().iterator();
        while (it.hasNext()) {
            Atom atom = it.next();
            Predicate p = atom.getPredicate();
            LinkedList<MarkedRule> set = map.get(p);
            if (set == null) {
                set = new LinkedList<MarkedRule>();
                map.put(p, set);
            }
            set.add(markedRule);
        }
        // mark the rule
        testRule(markedRule);
    }
}
Also used : Atom(fr.lirmm.graphik.graal.api.core.Atom) Predicate(fr.lirmm.graphik.graal.api.core.Predicate)

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