use of fr.lirmm.graphik.graal.api.core.Term in project graal by graphik-team.
the class OWL2Parser method removeUselessTopInBody.
private static InMemoryAtomSet removeUselessTopInBody(InMemoryAtomSet atomset) {
InMemoryAtomSet newAtomset = new DefaultInMemoryGraphStore();
CloseableIteratorWithoutException<Atom> it = atomset.iterator();
InMemoryAtomSet toRemove = new LinkedListAtomSet();
Atom a;
while (it.hasNext()) {
a = it.next();
if (!a.getPredicate().equals(Predicate.TOP)) {
newAtomset.add(a);
toRemove.add(a);
} else {
}
}
atomset.removeAll(toRemove);
// for each top predicate
Set<Term> terms = newAtomset.getTerms();
it = atomset.iterator();
while (it.hasNext()) {
a = it.next();
if (!terms.contains(a.getTerm(0))) {
newAtomset.add(a);
}
}
return newAtomset;
}
use of fr.lirmm.graphik.graal.api.core.Term in project graal by graphik-team.
the class TestUtil method addNAtoms.
public static void addNAtoms(InMemoryAtomSet to, int n, Predicate[] predicates, int domainSize, Random rand) {
for (int i = 0; i < n; ++i) {
int p = rand.nextInt(predicates.length);
List<Term> terms = new LinkedList<Term>();
for (int j = 0; j < predicates[p].getArity(); ++j) {
terms.add(DefaultTermFactory.instance().createConstant(rand.nextInt(domainSize)));
}
to.add(new DefaultAtom(predicates[p], terms));
}
}
use of fr.lirmm.graphik.graal.api.core.Term in project graal by graphik-team.
the class OWLAxiomParser method visit.
@Override
public Iterable<? extends Object> visit(OWLNegativeDataPropertyAssertionAxiom arg) {
freeVarGen.setIndex(0);
Term a = GraalUtils.createTerm(arg.getSubject());
Term b = GraalUtils.createLiteral(arg.getObject());
InMemoryAtomSet atomset = arg.getProperty().accept(new OWLPropertyExpressionVisitorImpl(a, b));
return Collections.singleton(new DefaultNegativeConstraint(atomset));
}
use of fr.lirmm.graphik.graal.api.core.Term in project graal by graphik-team.
the class OWLEquivalentClassExpressionVisitorImpl method visit.
@Override
public InMemoryAtomSet visit(OWLObjectSomeValuesFrom arg) {
Term newGlueVariable = varGen.getFreshSymbol();
InMemoryAtomSet atomset = arg.getProperty().accept(new OWLPropertyExpressionVisitorImpl(glueVariable, newGlueVariable));
if (!arg.getFiller().equals(DF.getOWLThing())) {
atomset.addAll(arg.getFiller().accept(new OWLEquivalentClassExpressionVisitorImpl(this.prefixManager, varGen, newGlueVariable)));
}
return atomset;
}
use of fr.lirmm.graphik.graal.api.core.Term in project graal by graphik-team.
the class StatBootstrapper method exec.
// /////////////////////////////////////////////////////////////////////////
//
// /////////////////////////////////////////////////////////////////////////
@Override
public CloseableIterator<Term> exec(final VarSharedData v, Collection<Atom> preAtoms, Collection<Atom> postAtoms, final AtomSet data, RulesCompilation rc) throws BacktrackException {
if (!(data instanceof Store)) {
return fallback.exec(v, preAtoms, postAtoms, data, rc);
}
Store store = (Store) data;
Set<Term> terms = null;
if (this.getProfiler() != null) {
this.getProfiler().start("BootstrapTime");
this.getProfiler().start("BootstrapTimeFirstPart");
}
Iterator<Atom> it;
Collection<Constant> constants = null;
Atom aa = null;
it = postAtoms.iterator();
while (it.hasNext()) {
Atom a = it.next();
if (constants == null || constants.isEmpty()) {
constants = a.getConstants();
aa = a;
}
}
it = preAtoms.iterator();
while (it.hasNext()) {
Atom a = it.next();
if (constants == null || constants.isEmpty()) {
constants = a.getConstants();
aa = a;
}
}
try {
if (constants != null && !constants.isEmpty()) {
terms = new HashSet<Term>();
for (Pair<Atom, Substitution> im : rc.getRewritingOf(aa)) {
int pos = im.getLeft().indexOf(im.getRight().createImageOf(v.value));
CloseableIterator<Atom> match = data.match(im.getLeft());
while (match.hasNext()) {
terms.add(match.next().getTerm(pos));
}
}
}
if (this.getProfiler() != null) {
this.getProfiler().stop("BootstrapTimeFirstPart");
}
if (terms == null) {
Atom a = null, tmp;
double probaA = 1.1;
it = postAtoms.iterator();
while (it.hasNext()) {
tmp = it.next();
double p = ProbaUtils.computeProba(tmp, store, rc);
if (p < probaA) {
a = tmp;
p = probaA;
}
}
it = preAtoms.iterator();
while (it.hasNext()) {
tmp = it.next();
double p = ProbaUtils.computeProba(tmp, store, rc);
if (p < probaA) {
a = tmp;
p = probaA;
}
}
terms = BootstrapperUtils.computeCandidatesOverRewritings(a, v, data, rc);
}
if (this.getProfiler() != null) {
this.getProfiler().stop("BootstrapTime");
}
if (terms == null) {
return data.termsIterator();
} else {
return new CloseableIteratorAdapter<Term>(terms.iterator());
}
} catch (AtomSetException e) {
throw new BacktrackException(e);
} catch (IteratorException e) {
throw new BacktrackException(e);
}
}
Aggregations