Package lupos.sparql1_1.operatorgraph

Examples of lupos.sparql1_1.operatorgraph.SPARQLCoreParserVisitorImplementation


  }

  private static void processAggregationFunction(final QueryResult queryResult, final lupos.sparql1_1.Node n, final HashMap<lupos.sparql1_1.Node, Object> resultsOfAggregationFunctions, final EvaluationVisitor<Map<Node, Object>, Object> evaluationVisitor) {
    final boolean childAdded = false;
    if (isAggregationFunction(n)) {
      final ASTAggregation aggregation = (ASTAggregation) n;
      Object result = null;

      if (n.jjtGetNumChildren()>0 && isConstant(n.jjtGetChild(0))) {
        try {
          final lupos.sparql1_1.Node node=n.jjtGetChild(0);
          final Object operand = Filter.staticEvalTree(null, node,
              resultsOfAggregationFunctions, evaluationVisitor);
          if (childAdded) {
            n.clearChildren();
          }
          final Iterator<Object> values = new ImmutableIterator<Object>() {
            Object next = operand;

            @Override
            public boolean hasNext() {
              return this.next != null;
            }

            @Override
            public Object next() {
              final Object znext = this.next;
              this.next = null;
              return znext;
            }
          };
          result = aggregation.applyAggregation(
              evaluationVisitor, values);
        } catch (final NotBoundException e) {
          System.err.println(e);
          e.printStackTrace();
        } catch (final TypeErrorException e) {
          System.err.println(e);
          e.printStackTrace();
        }
      } else {

        Iterator<? extends Object> values = (n.jjtGetNumChildren()==0)?queryResult.iterator():new ImmutableIterator<Object>() {
          final lupos.sparql1_1.Node node=n.jjtGetChild(0);
          Iterator<Bindings> iterator = queryResult.iterator();
          Object next = null;

          @Override
          public boolean hasNext() {
            if (this.next != null) {
              return true;
            }
            this.next = this.next();
            return (this.next != null);
          }

          @Override
          public Object next() {
            if (this.next != null) {
              final Object znext = this.next;
              this.next = null;
              return znext;
            }
            while (this.iterator.hasNext()) {
              final Bindings b = this.iterator.next();
              try {
                return Filter.staticEvalTree(b, this.node,
                    resultsOfAggregationFunctions, evaluationVisitor);

              } catch (final Exception e) {
                // just ignore bindings with error!
              }
            }
            return null;
          }
        };
        if (aggregation.isDistinct()) {
          // first just implement an in-memory distinct
          // TODO implement also disk-based duplicate elimination
          // (just like physical operators for DISTINCT)
          final Iterator<? extends Object> oldIterator = values;
          values = new ImmutableIterator<Object>() {

            HashSet<Object> alreadyUsedObjects = new HashSet<Object>();
            Object next = null;

            @Override
            public boolean hasNext() {
              if (this.next != null) {
                return true;
              }
              this.next = this.next();
              return (this.next != null);
            }

            @Override
            public Object next() {
              if (this.next != null) {
                final Object znext = this.next;
                this.next = null;
                return znext;
              }
              while (oldIterator.hasNext()) {
                final Object o = oldIterator.next();
                if (!this.alreadyUsedObjects.contains(o)) {
                  this.alreadyUsedObjects.add(o);
                  return o;
                }
              }
              return null;
            }
          };
        }
        result = aggregation.applyAggregation(evaluationVisitor,
            values);
      }

      if (result != null) {
        resultsOfAggregationFunctions.put(n, result);
View Full Code Here


    }
    return -1;
  }

  private boolean filter_and(final ASTFilterConstraint n) {
    final ASTAndNode and = (ASTAndNode) n.jjtGetChild(0);
    final ASTFilterConstraint a = (ASTFilterConstraint) n
        .cloneStillChild(true);
    final ASTFilterConstraint b = (ASTFilterConstraint) n
        .cloneStillChild(true);
    n.jjtGetParent().removeChild(n);
    a.addChild(and.jjtGetChild(0));
    b.addChild(and.jjtGetChild(0));
    return true;
  }
View Full Code Here

      final Node parent = node.jjtGetParent();
      final Node or = node.jjtGetChild(ind).clone(false);
      node.removeChild(ind);
      parent.addChild(or);
      or.addChild(node);
      final ASTAndNode addAnd = (ASTAndNode) node.cloneStillChild(false);
      node.addChild(or.jjtGetChild(0));
      addAnd.addChild(or.jjtGetChild(0));
    }
    return ind >= 0;
  }
View Full Code Here

          try {
            this.checkFilterConstraint(node.jjtGetChild(i)
                .jjtGetChild(0), variablesNew);
          } catch (final NotBoundException e) {
            node.jjtGetChild(i).clearChildren();
            final ASTBooleanLiteral bl = new ASTBooleanLiteral(0);
            bl.setState(false);
            bl.jjtSetParent(node.jjtGetChild(i));
            node.jjtGetChild(i).jjtAddChild(bl, 0);
          }
        } else {
          this.checkFilterOfGroupConstraint(node.jjtGetChild(i),
              variablesNew);
View Full Code Here

    this.np = null;
  }

  public Filter(final String filter) throws ParseException {
    this.evaluationVisitor = getEvaluationVisitor();
    ASTFilterConstraint ASTfilter;
    ASTfilter = (ASTFilterConstraint) SPARQL1_1Parser.parseFilter(filter);
    this.setNodePointer(ASTfilter);
  }
View Full Code Here

    return -1;
  }

  private boolean filter_and(final ASTFilterConstraint n) {
    final ASTAndNode and = (ASTAndNode) n.jjtGetChild(0);
    final ASTFilterConstraint a = (ASTFilterConstraint) n
        .cloneStillChild(true);
    final ASTFilterConstraint b = (ASTFilterConstraint) n
        .cloneStillChild(true);
    n.jjtGetParent().removeChild(n);
    a.addChild(and.jjtGetChild(0));
    b.addChild(and.jjtGetChild(0));
    return true;
  }
View Full Code Here

      filterConstraint = filterConstraint.substring(0,
          filterConstraint.length() - 3)
          + ") ";

      try {
        final ASTFilterConstraint ASTfilter = (ASTFilterConstraint) SPARQL1_1Parser
            .parseFilter(filterConstraint);
        filter = new Filter(ASTfilter);
      } catch (final Exception e) {
        System.err
            .println("This should never happen in RuleReplaceGenPat!");
View Full Code Here

        // TODO if insertion into data editor or into an existing
        // TripleContainer, then all existing items (of the
        // TripleContainer
        // or from the whole DataEditor) must be first inserted!

        final ASTGroupConstraint node = SPARQL1_1Parser.parseGroupGraphPatternsAndRDFTerms(content);

        for (int i = 0; i < node.jjtGetNumChildren(); i++) {
          final Node child = node.jjtGetChild(i);

          if (child instanceof ASTGroupConstraint) {
            final VisualQueryGenerator vqg = new VisualQueryGenerator(
                ((VisualGraphOperatorWithPrefix) this.visualGraphs
                    .get(0)).prefix);
View Full Code Here

    }
    catch(final Exception e) {
      System.out.println("Pasted string does not contain N3-data. Trying { (triple pattern)* } (RDF Term)* format!");

      try {
        final ASTGroupConstraint node = SPARQL1_1Parser.parseN3GroupGraphPatternsAndRDFTerms(content);

        for(int i = 0; i < node.jjtGetNumChildren(); i++) {
          final Node child = node.jjtGetChild(i);

          if(child instanceof ASTGroupConstraint) {
            final VisualDataGenerator vdg = new VisualDataGenerator(((VisualGraphOperatorWithPrefix) this.visualGraphs.get(0)).prefix);
            rdfTermToJoin.addAll((Collection<Operator>) child.jjtAccept((SPARQL1_1ParserVisitor) vdg, rdfHash));
          }
View Full Code Here

          operator.addProjectionElement(var.toQueryString());
        } catch (final ModificationException e) {
          e.printStackTrace();
        }
      } else if (node.jjtGetChild(i) instanceof ASTQuotedURIRef) {
        final ASTQuotedURIRef var = (ASTQuotedURIRef) node
        .jjtGetChild(i);

        try {
          operator.addProjectionElement(var.toQueryString());
        } catch (final ModificationException e) {
          e.printStackTrace();
        }
      }
    }
View Full Code Here

TOP

Related Classes of lupos.sparql1_1.operatorgraph.SPARQLCoreParserVisitorImplementation

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.