use of fr.lirmm.graphik.graal.core.DefaultAtom in project graal by graphik-team.
the class IDConditionImpl method generateRule.
@Override
public Rule generateRule(Predicate bodyPredicate, Predicate headPredicate) {
List<Term> body = new ArrayList<Term>();
List<Term> head = new LinkedList<Term>();
// initialize body with fresh variable
for (int i = 0; i < condBody.length; i++) body.add(DefaultTermFactory.instance().createVariable("X" + condBody[i]));
// pick frontier variables from the head
for (int i = 0; i < this.condHead.length; i++) {
head.add(DefaultTermFactory.instance().createVariable("X" + condHead[i]));
}
Rule r = DefaultRuleFactory.instance().create();
r.getBody().add(new DefaultAtom(bodyPredicate, body));
r.getHead().add(new DefaultAtom(headPredicate, head));
return r;
}
use of fr.lirmm.graphik.graal.core.DefaultAtom in project graal by graphik-team.
the class HierarchicalCompilation method getRewritingOf.
@Override
public Collection<Pair<Atom, Substitution>> getRewritingOf(Atom father) {
LinkedList<Pair<Atom, Substitution>> res = new LinkedList<Pair<Atom, Substitution>>();
res.add(new ImmutablePair<Atom, Substitution>(father, Substitutions.emptySubstitution()));
Integer index = predicateIndex.get(father.getPredicate());
if (index != null)
for (int i = 0; i < sizeOrder; i++) {
if (order[index][i] == 1) {
Atom a = new DefaultAtom(father);
a.setPredicate(indexPredicate.get(i));
res.add(new ImmutablePair<Atom, Substitution>(a, Substitutions.emptySubstitution()));
}
}
return res;
}
use of fr.lirmm.graphik.graal.core.DefaultAtom in project graal by graphik-team.
the class AtomSetUtils method union.
public static InMemoryAtomSet union(InMemoryAtomSet a1, InMemoryAtomSet a2) {
InMemoryAtomSet atomset = DefaultAtomSetFactory.instance().create();
CloseableIteratorWithoutException<Atom> it = a1.iterator();
while (it.hasNext()) {
Atom a = it.next();
atomset.add(new DefaultAtom(a));
}
it = a2.iterator();
while (it.hasNext()) {
Atom a = it.next();
if (!atomset.contains(a)) {
atomset.add(new DefaultAtom(a));
}
}
return atomset;
}
use of fr.lirmm.graphik.graal.core.DefaultAtom in project graal by graphik-team.
the class AbstractRDFListener method handleStatement.
@Override
public void handleStatement(Statement st) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(st.toString());
}
Predicate predicate = new Predicate(new DefaultURI(st.getPredicate().toString()), 2);
Term subject = DefaultTermFactory.instance().createConstant(new DefaultURI(st.getSubject().toString()));
Term object;
fr.lirmm.graphik.util.URI datatype;
if (st.getObject() instanceof Literal) {
Literal l = (Literal) st.getObject();
if (l.getDatatype() == null) {
datatype = URIUtils.RDF_LANG_STRING;
} else {
datatype = new fr.lirmm.graphik.util.DefaultURI(l.getDatatype().getNamespace(), l.getDatatype().getLocalName());
}
String value = l.getLabel();
if (datatype.equals(URIUtils.RDF_LANG_STRING)) {
value += "@" + l.getLanguage();
}
object = DefaultTermFactory.instance().createLiteral(datatype, value);
} else {
object = DefaultTermFactory.instance().createConstant(new DefaultURI(st.getObject().toString()));
}
DefaultAtom a = new DefaultAtom(predicate, subject, object);
this.createAtom(a);
}
use of fr.lirmm.graphik.graal.core.DefaultAtom in project graal by graphik-team.
the class AtomTest method equalsTest.
@Test
public void equalsTest() {
Predicate predicate = new Predicate("pred", 3);
Term[] terms = new Term[3];
terms[0] = new DefaultVariable("X");
terms[1] = new DefaultConstant("a");
terms[2] = new DefaultConstant("b");
Atom atom = new DefaultAtom(predicate, Arrays.asList(terms));
Assert.assertTrue("Atom not equals itself", atom.equals(atom));
Assert.assertTrue("Atom not equals it clone", atom.equals(new DefaultAtom(atom)));
Predicate otherPred = new Predicate("otherPred", 3);
Term[] otherTerms = new Term[3];
otherTerms[0] = new DefaultVariable("Y");
otherTerms[1] = new DefaultConstant("b");
otherTerms[2] = new DefaultConstant("b");
Atom other = new DefaultAtom(otherPred, Arrays.asList(terms));
Assert.assertFalse("Atom equals an other atom with other predicate", atom.equals(other));
other = new DefaultAtom(predicate, Arrays.asList(otherTerms));
Assert.assertFalse("Atom equals an other atom with other terms", atom.equals(other));
other = new DefaultAtom(atom);
other.setPredicate(otherPred);
Assert.assertFalse("Atom equals a copy with modified predicate", predicate.equals(other));
other = new DefaultAtom(atom);
other.setTerm(2, terms[0]);
Assert.assertFalse("Atom equals a copy with modified terms", atom.equals(other));
}
Aggregations