Search in sources :

Example 26 with Term

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;
}
Also used : InMemoryAtomSet(fr.lirmm.graphik.graal.api.core.InMemoryAtomSet) LinkedListAtomSet(fr.lirmm.graphik.graal.core.atomset.LinkedListAtomSet) DefaultInMemoryGraphStore(fr.lirmm.graphik.graal.core.atomset.graph.DefaultInMemoryGraphStore) Term(fr.lirmm.graphik.graal.api.core.Term) Atom(fr.lirmm.graphik.graal.api.core.Atom)

Example 27 with Term

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));
    }
}
Also used : DefaultAtom(fr.lirmm.graphik.graal.core.DefaultAtom) Term(fr.lirmm.graphik.graal.api.core.Term) LinkedList(java.util.LinkedList)

Example 28 with Term

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));
}
Also used : DefaultNegativeConstraint(fr.lirmm.graphik.graal.core.DefaultNegativeConstraint) InMemoryAtomSet(fr.lirmm.graphik.graal.api.core.InMemoryAtomSet) Term(fr.lirmm.graphik.graal.api.core.Term)

Example 29 with Term

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;
}
Also used : InMemoryAtomSet(fr.lirmm.graphik.graal.api.core.InMemoryAtomSet) Term(fr.lirmm.graphik.graal.api.core.Term)

Example 30 with Term

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);
    }
}
Also used : IteratorException(fr.lirmm.graphik.util.stream.IteratorException) Constant(fr.lirmm.graphik.graal.api.core.Constant) Store(fr.lirmm.graphik.graal.api.store.Store) Term(fr.lirmm.graphik.graal.api.core.Term) CloseableIteratorAdapter(fr.lirmm.graphik.util.stream.CloseableIteratorAdapter) Atom(fr.lirmm.graphik.graal.api.core.Atom) BacktrackException(fr.lirmm.graphik.graal.homomorphism.BacktrackException) Substitution(fr.lirmm.graphik.graal.api.core.Substitution) AtomSetException(fr.lirmm.graphik.graal.api.core.AtomSetException)

Aggregations

Term (fr.lirmm.graphik.graal.api.core.Term)173 Atom (fr.lirmm.graphik.graal.api.core.Atom)86 LinkedList (java.util.LinkedList)41 Substitution (fr.lirmm.graphik.graal.api.core.Substitution)36 Test (org.junit.Test)35 InMemoryAtomSet (fr.lirmm.graphik.graal.api.core.InMemoryAtomSet)34 Variable (fr.lirmm.graphik.graal.api.core.Variable)32 Predicate (fr.lirmm.graphik.graal.api.core.Predicate)27 DefaultAtom (fr.lirmm.graphik.graal.core.DefaultAtom)26 AtomSetException (fr.lirmm.graphik.graal.api.core.AtomSetException)23 LinkedListAtomSet (fr.lirmm.graphik.graal.core.atomset.LinkedListAtomSet)18 ConjunctiveQuery (fr.lirmm.graphik.graal.api.core.ConjunctiveQuery)15 Rule (fr.lirmm.graphik.graal.api.core.Rule)15 IteratorException (fr.lirmm.graphik.util.stream.IteratorException)14 TreeSet (java.util.TreeSet)12 Constant (fr.lirmm.graphik.graal.api.core.Constant)9 DBTable (fr.lirmm.graphik.graal.store.rdbms.util.DBTable)9 ArrayList (java.util.ArrayList)9 HashSet (java.util.HashSet)9 TreeMap (java.util.TreeMap)8