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

org.aksw.sparqlify.database.GetVarsMentioned Maven / Gradle / Ivy

The newest version!
package org.aksw.sparqlify.database;

import java.util.HashSet;
import java.util.Set;

import org.aksw.commons.collections.SetUtils;
import org.aksw.commons.util.reflect.MultiMethod;
import org.aksw.jena_sparql_api.views.IViewDef;
import org.aksw.jena_sparql_api.views.OpViewInstanceJoin;
import org.aksw.jena_sparql_api.views.VarsMentioned;
import org.aksw.jena_sparql_api.views.ViewInstance;
import org.apache.jena.sparql.algebra.Op;
import org.apache.jena.sparql.algebra.OpVars;
import org.apache.jena.sparql.algebra.op.Op1;
import org.apache.jena.sparql.algebra.op.Op2;
import org.apache.jena.sparql.algebra.op.OpExtend;
import org.apache.jena.sparql.algebra.op.OpN;
import org.apache.jena.sparql.algebra.op.OpQuadBlock;
import org.apache.jena.sparql.algebra.op.OpQuadPattern;
import org.apache.jena.sparql.core.Var;

public class GetVarsMentioned {
    @SuppressWarnings("unchecked")
    public static Set getVarsMentioned(Op op) {
        return (Set)MultiMethod.invokeStatic(GetVarsMentioned.class, "_getVarsMentioned", op);
    }

//    @Deprecated
//    public static Set _getVarsMentioned(RdfViewInstance op) {
//        return new HashSet(op.getQueryToParentBinding().keySet());
//    }


//    public static Set _getVarsMentioned(OpMapping op) {
//        Set result = new HashSet(op.getMapping().getVarDefinition().getMap().keySet());
//
//        return result;
//    }


    public static  Set _getVarsMentioned(OpViewInstanceJoin op) {
        Set result = new HashSet();
        for(ViewInstance vi : op.getJoin().getViewInstances()) {
            result.addAll(vi.getBinding().getQueryVars());
        }

        return result;
    }

    public static Set _getVarsMentioned(OpQuadPattern op) {
        return SetUtils.asSet(OpVars.mentionedVars(op));//QuadPatternUtils.getVarsMentioned((op.getPattern());
    }

    public static Set _getVarsMentioned(OpQuadBlock op) {
        //return QuadUtils.getVarsMentioned(op.getPattern());
        return SetUtils.asSet(OpVars.mentionedVars(op));
    }

    public static Set _getVarsMentioned(OpExtend op) {
        Set result = new HashSet();

        result.addAll(op.getVarExprList().getVars());
        result.addAll(getVarsMentioned(op.getSubOp()));

        return result;
    }

    public static Set _getVarsMentioned(OpExtFilterIndexed op) {
        return getVarsMentioned(op.effectiveOp());
    }

    public static Set _getVarsMentioned(VarsMentioned op) {
        Set result = op.varsMentioned();
        return result;
    }

    /*
    public static Set getVarsMentioned(OpUnion op) {
        Set tmp = getVarsMentioned(op.getLeft());
        tmp.addAll(getVarsMentioned(op.getRight()));

        return tmp;
    }*/

//    public static Set _getVarsMentioned(OpRdfViewPattern op) {
//        Set result = new HashSet();
//
//        for(RdfViewInstance item : op.getConjunction().getViewBindings()) {
//            EquiMap equiMap = item.getBinding().getEquiMap();
//
//            result.addAll(equiMap.getEquivalences().asMap().keySet());
//            result.addAll(equiMap.getKeyToValue().keySet());
//
//            //result.addAll(item.getQueryToParentBinding().keySet());
//        }
//
//        return result;
//    }

    public static Set _getVarsMentioned(Op1 op) {
        return getVarsMentioned(op.getSubOp());
    }

    public static Set _getVarsMentioned(Op2 op) {
        Set tmp = getVarsMentioned(op.getLeft());
        tmp.addAll(getVarsMentioned(op.getRight()));

        return tmp;
    }

    public static Set _getVarsMentioned(OpN op) {
        Set result = new HashSet();
        for(Op item : op.getElements()) {
            result.addAll(getVarsMentioned(item));
        }

        return result;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy