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;
}
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));
}
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;
}
}
}
}
}
}
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;
}
}
}
}
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);
}
}
Aggregations