Search in sources :

Example 1 with TreeMapSubstitution

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

the class Utils method getSafeCopy.

public static InMemoryAtomSet getSafeCopy(InMemoryAtomSet atomSet) {
    Substitution substitution = new TreeMapSubstitution();
    for (Variable t : atomSet.getVariables()) {
        substitution.put(t, varGen.getFreshSymbol());
    }
    InMemoryAtomSet safe = new LinkedListAtomSet();
    substitution.apply(atomSet, safe);
    return safe;
}
Also used : Variable(fr.lirmm.graphik.graal.api.core.Variable) Substitution(fr.lirmm.graphik.graal.api.core.Substitution) TreeMapSubstitution(fr.lirmm.graphik.graal.core.TreeMapSubstitution) InMemoryAtomSet(fr.lirmm.graphik.graal.api.core.InMemoryAtomSet) LinkedListAtomSet(fr.lirmm.graphik.graal.core.atomset.LinkedListAtomSet) TreeMapSubstitution(fr.lirmm.graphik.graal.core.TreeMapSubstitution)

Example 2 with TreeMapSubstitution

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

the class IDCompilation method homomorphism.

@Override
public LinkedList<Substitution> homomorphism(Atom father, Atom son) {
    LinkedList<Substitution> res = new LinkedList<Substitution>();
    Predicate predB = son.getPredicate();
    Predicate predH = father.getPredicate();
    List<IDCondition> conds = getConditions(predB, predH);
    for (IDCondition cond : conds) {
        if (cond.checkBody(son.getTerms())) {
            Substitution homo = cond.homomorphism(father.getTerms(), son.getTerms());
            if (homo != null) {
                res.add(new TreeMapSubstitution(homo));
            }
        }
    }
    return res;
}
Also used : Substitution(fr.lirmm.graphik.graal.api.core.Substitution) TreeMapSubstitution(fr.lirmm.graphik.graal.core.TreeMapSubstitution) LinkedList(java.util.LinkedList) Predicate(fr.lirmm.graphik.graal.api.core.Predicate) TreeMapSubstitution(fr.lirmm.graphik.graal.core.TreeMapSubstitution)

Example 3 with TreeMapSubstitution

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

the class Utils method getSafeCopy.

public static Rule getSafeCopy(Rule rule) {
    Substitution substitution = new TreeMapSubstitution();
    for (Variable t : rule.getVariables()) {
        substitution.put(t, varGen.getFreshSymbol());
    }
    InMemoryAtomSet body = rule.getBody();
    InMemoryAtomSet head = rule.getHead();
    InMemoryAtomSet safeBody = new LinkedListAtomSet();
    InMemoryAtomSet safeHead = new LinkedListAtomSet();
    substitution.apply(body, safeBody);
    substitution.apply(head, safeHead);
    return DefaultRuleFactory.instance().create(safeBody, safeHead);
}
Also used : Variable(fr.lirmm.graphik.graal.api.core.Variable) Substitution(fr.lirmm.graphik.graal.api.core.Substitution) TreeMapSubstitution(fr.lirmm.graphik.graal.core.TreeMapSubstitution) InMemoryAtomSet(fr.lirmm.graphik.graal.api.core.InMemoryAtomSet) LinkedListAtomSet(fr.lirmm.graphik.graal.core.atomset.LinkedListAtomSet) TreeMapSubstitution(fr.lirmm.graphik.graal.core.TreeMapSubstitution)

Example 4 with TreeMapSubstitution

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

the class ResultSet2SubstitutionConverter method convert.

// /////////////////////////////////////////////////////////////////////////
// PUBLIC METHODS
// /////////////////////////////////////////////////////////////////////////
@Override
public Substitution convert(ResultSet result) throws ConversionException {
    try {
        Substitution substitution = new TreeMapSubstitution();
        if (!ans.isEmpty()) {
            for (Term t : ans) {
                if (t.isVariable()) {
                    int i = result.findColumn(t.getLabel());
                    int type = result.getMetaData().getColumnType(i);
                    String value = result.getString(i);
                    Term substitut = this.queryTranslator.createTermFromColumnType(type, value);
                    substitution.put((Variable) t, substitut);
                }
            }
        }
        return substitution;
    } catch (SQLException e) {
        throw new ConversionException(e);
    } catch (AtomSetException e) {
        throw new ConversionException(e);
    }
}
Also used : ConversionException(fr.lirmm.graphik.util.stream.converter.ConversionException) TreeMapSubstitution(fr.lirmm.graphik.graal.core.TreeMapSubstitution) Substitution(fr.lirmm.graphik.graal.api.core.Substitution) SQLException(java.sql.SQLException) AtomSetException(fr.lirmm.graphik.graal.api.core.AtomSetException) Term(fr.lirmm.graphik.graal.api.core.Term) TreeMapSubstitution(fr.lirmm.graphik.graal.core.TreeMapSubstitution)

Aggregations

Substitution (fr.lirmm.graphik.graal.api.core.Substitution)4 TreeMapSubstitution (fr.lirmm.graphik.graal.core.TreeMapSubstitution)4 InMemoryAtomSet (fr.lirmm.graphik.graal.api.core.InMemoryAtomSet)2 Variable (fr.lirmm.graphik.graal.api.core.Variable)2 LinkedListAtomSet (fr.lirmm.graphik.graal.core.atomset.LinkedListAtomSet)2 AtomSetException (fr.lirmm.graphik.graal.api.core.AtomSetException)1 Predicate (fr.lirmm.graphik.graal.api.core.Predicate)1 Term (fr.lirmm.graphik.graal.api.core.Term)1 ConversionException (fr.lirmm.graphik.util.stream.converter.ConversionException)1 SQLException (java.sql.SQLException)1 LinkedList (java.util.LinkedList)1