Package lupos.engine.operators.tripleoperator

Examples of lupos.engine.operators.tripleoperator.TriplePattern


      final Bindings bind) {
    final Collection<TriplePattern> pattern = new ArrayList<TriplePattern>(
        index.getTriplePattern());
    final Collection<TriplePattern> bindPattern = new ArrayList<TriplePattern>();
    for (final TriplePattern tp : pattern) {
      final TriplePattern newPat = new TriplePattern();
      int i = 0;
      for (final Item item : tp.getItems()) {
        Item toSet = null;
        if (item.isVariable() && bind.getVariableSet().contains(item))
          toSet = item.getLiteral(bind);
        else
          toSet = item;
        newPat.setPos(toSet, i++);
      }
      bindPattern.add(newPat);
    }
    index.getTriplePattern().clear();
    index.getTriplePattern().addAll(bindPattern);
View Full Code Here


    for(final Generate generate: listOfConstructedTripel){
      generate.getSucceedingOperators().clear();
      final Item[] generateItems = generate.getValueOrVariable();
      for(final BasicOperator tpOrIndexScan: new LinkedList<BasicOperator>(toBeConnectedTo)){
        if(tpOrIndexScan instanceof TriplePattern){
          final TriplePattern tpi = (TriplePattern) tpOrIndexScan;
          if(BasicIndexRuleEvaluator.isMatching(tpi, generateItems)){
            generate.addSucceedingOperator(tpOrIndexScan);
          }
        } else {
          final BasicIndexScan bi = (BasicIndexScan) tpOrIndexScan;
          if(bi.getTriplePattern()!=null && bi.getTriplePattern().size()>0){
            final LinkedList<TriplePattern> matchingTPs = new LinkedList<TriplePattern>();
            for(final TriplePattern inIndexScan: bi.getTriplePattern()){
              if(BasicIndexRuleEvaluator.isMatching(inIndexScan, generateItems)){
                matchingTPs.add(inIndexScan);
                break;
              }
            }
            if(matchingTPs.size()>0){
              // modify BasicIndex in toBeConnectedTo! (delete tp in current bi, add new BasicIndex with tp, join both operators and additionally add tp for generate operator!)
              for(final TriplePattern tp: matchingTPs){
                final TriplePattern newTP = new TriplePattern(tp.getPos(0), tp.getPos(1), tp.getPos(2));
                newTP.recomputeVariables();
                generate.addSucceedingOperator(newTP);
                newTP.addPrecedingOperator(generate);

                if(bi.getTriplePattern().size()==1){
                  newTP.addSucceedingOperators(new LinkedList<OperatorIDTuple>(bi.getSucceedingOperators()));
                  for(final OperatorIDTuple opID: bi.getSucceedingOperators()){
                    opID.getOperator().addPrecedingOperator(newTP);
                  }
                } else {
                  bi.getTriplePattern().remove(tp);
                  final Join join = new Join();
                  join.setUnionVariables(bi.getUnionVariables());
                  bi.recomputeVariables();
                  tp.recomputeVariables();
                  final HashSet<Variable> joinVars = new HashSet<Variable>(tp.getUnionVariables());
                  joinVars.retainAll(bi.getUnionVariables());
                  join.setIntersectionVariables(joinVars);
                  for(final OperatorIDTuple opID: bi.getSucceedingOperators()){
                    final BasicOperator suc = opID.getOperator();
                    suc.removePrecedingOperator(bi);
                    suc.addPrecedingOperator(join);
                  }
                  join.setSucceedingOperators(bi.getSucceedingOperators());
                  bi.setSucceedingOperator(new OperatorIDTuple(join, 0));
                  join.addPrecedingOperator(bi);

                  final LinkedList<TriplePattern> tpList = new LinkedList<TriplePattern>();
                  tpList.add(tp);
                  final BasicIndexScan newIndex = ((Root)rootQuery).newIndexScan(new OperatorIDTuple(join, 1), tpList, bi.getGraphConstraint());
                  newIndex.recomputeVariables();
                  join.addPrecedingOperator(newIndex);
                  rootQuery.addSucceedingOperator(newIndex);
                  newIndex.addPrecedingOperator(rootQuery);
                  newTP.addSucceedingOperator(new OperatorIDTuple(join, 1));
                  join.addPrecedingOperator(newTP);

                  toBeConnectedTo.add(newIndex);
                }
              }
View Full Code Here

   * @throws JSONException
   */
  public static Map<Variable, VarBucket> getHistograms(final String histogramRequestSerializedAsJSONString, final Dataset dataset, final IOperatorCreator operatorCreator) throws JSONException {
    final JSONObject json = new JSONObject(histogramRequestSerializedAsJSONString);
    final Collection<Variable> vars = Helper.createVariablesFromJSON(json);
    final TriplePattern tp = Helper.createTriplePatternFromJSON(json);
    final Map<Variable, Literal> minima = Helper.createMapFromJSON(json.getJSONObject("minima"));
    final Map<Variable, Literal> maxima = Helper.createMapFromJSON(json.getJSONObject("maxima"));
    final Collection<TriplePattern> tps = new LinkedList<TriplePattern>();
    tps.add(tp);
    final BasicIndexScan indexScan = operatorCreator.createIndexScan(operatorCreator.createRoot(dataset), tps);
    final BindingsFactory bindingsFactory = BindingsFactory.createBindingsFactory(tp.getVariables());
    indexScan.setBindingsFactory(bindingsFactory);
    tp.setBindingsFactory(bindingsFactory);

    return indexScan.getVarBuckets(tp, Bindings.instanceClass, vars, minima, maxima);
  }
View Full Code Here

public class RuleEliminateUnnecessaryGenerate extends Rule {

  @Override
  protected void init() {
    final TriplePattern tp = new TriplePattern();
    final Generate generate = new Generate();

    tp.setSucceedingOperator(new OperatorIDTuple(generate, 0));
    generate.setPrecedingOperator(tp);

    subGraphMap = new HashMap<BasicOperator, String>();
    subGraphMap.put(tp, "triplepattern");
    subGraphMap.put(generate, "generate");
View Full Code Here

  }

  @Override
  protected boolean checkPrecondition(final Map<String, BasicOperator> mso) {
    final Generate generate = (Generate) mso.get("generate");
    final TriplePattern tp = (TriplePattern) mso.get("triplepattern");

    final Item[] itemsGenerate = generate.getValueOrVariable();
    final Item[] itemsTriplePattern = tp.getItems();

    for (int i = 0; i < 3; i++) {
      if (!itemsGenerate[i].equals(itemsTriplePattern[i]))
        return false;
    }
View Full Code Here

      final Map<String, BasicOperator> mso,
      final BasicOperator rootOperator) {
    final Collection<BasicOperator> deleted = new LinkedList<BasicOperator>();
    final Collection<BasicOperator> added = new LinkedList<BasicOperator>();
    final Generate generate = (Generate) mso.get("generate");
    final TriplePattern tp = (TriplePattern) mso.get("triplepattern");
    // remove the generate operator...
    for (final OperatorIDTuple oit : generate.getSucceedingOperators()) {
      oit.getOperator().removePrecedingOperator(generate);
    }
    for (final BasicOperator bo : generate.getPrecedingOperators()) {
      bo.removeSucceedingOperator(generate);
    }
    deleted.add(generate);
    // generate.setPrecedingOperators(null);
    // generate.setSucceedingOperators(null);

    // are there no other operators than generate???
    if (tp.getSucceedingOperators().size() == 0) {
      for (final BasicOperator bo : tp.getPrecedingOperators()) {
        bo.removeSucceedingOperator(tp);
      }
      // tp.setPrecedingOperators(null);
      // tp.setSucceedingOperators(null);
      deleted.add(tp);
View Full Code Here

TOP

Related Classes of lupos.engine.operators.tripleoperator.TriplePattern

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.