All Downloads are FREE. Search and download functionalities are using the official Maven repository.

fr.inria.edelweiss.kgraph.approximate.ext.TripleWrapper Maven / Gradle / Ivy

The newest version!
package fr.inria.edelweiss.kgraph.approximate.ext;

import fr.inria.acacia.corese.triple.parser.Atom;
import fr.inria.acacia.corese.triple.parser.Triple;
import fr.inria.acacia.corese.triple.parser.Variable;
import static fr.inria.edelweiss.kgraph.approximate.ext.ASTRewriter.O;
import static fr.inria.edelweiss.kgraph.approximate.ext.ASTRewriter.P;
import static fr.inria.edelweiss.kgraph.approximate.ext.ASTRewriter.S;
import fr.inria.edelweiss.kgraph.approximate.strategy.StrategyType;
import java.util.ArrayList;
import java.util.List;

/**
 * TripleWrapper.java
 *
 * @author Fuqi Song, Wimmics Inria I3S
 * @date 30 nov. 2015
 */
class TripleWrapper {

    private final Triple triple;
    private final int position;
    private final List strategy;

    public TripleWrapper(Triple triple, int position, List strategy) {
        this.triple = triple;
        this.position = position;
        this.strategy = strategy;
    }

    public TripleWrapper(Triple triple, int position) {
        this(triple, position, new ArrayList());
    }

    public Atom getAtom() {
        switch (position) {
            case S:
                return this.triple.getSubject();
            case P:
                return this.triple.getPredicate();
            case O:
                return this.triple.getObject();
            default:
                return null;
        }
    }

    public void setAtom(Variable var) {
        switch (position) {
            case S:
                triple.setSubject(var);
                break;
            case P:
                triple.setPredicate(var);
                break;
            case O:
                triple.setObject(var);
                break;
            default:
        }
    }

    public void addStrategy(StrategyType strategy) {
        this.strategy.add(strategy);
    }

    public int getPosition() {
        return position;
    }

    public Triple getTriple() {
        return triple;
    }

    public List getStrategies() {
        return strategy;
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();

        sb.append(this.triple).append("\t");
        sb.append(this.getAtom()).append(",\t");
        sb.append(this.getPosition()).append(",\t");
        sb.append("[");
        for (StrategyType st : strategy) {
            sb.append(st.name()).append(", ");
        }
        sb.append("]");
        return sb.toString();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy