Package lupos.sparql1_1

Examples of lupos.sparql1_1.Token


      }

      StringMultiset tagAttributes = tag.getAttributes();

      while (index < size) {
        Token token = tokens.get(index);
        index++;
        TokenType tokenType = token.getType();
        if (ATTRIBUTE == tokenType) {
          String attribute = token.getValue();
          attribute = ignoreCase ? attribute.toLowerCase() : attribute;
          attributes.add(attribute);
          tagAttributes.add(attribute);
        } else if (TAG == tokenType) {
          // Tag closing token
          tag.setDirty(false);
          inTag = false;
          break;
        }
      }
      if (newAttributes && attributes.size() != 0) {
        line.putTag(TAG_ATTRIBUTES, attributes);
      } else if (!newAttributes && attributes.size() == 0) {
        line.putTag(TAG_ATTRIBUTES, null);
      }
    } else {
      line.putTag(TAG_ATTRIBUTES, null);
    }

    while (index < size) {
      Token token = tokens.get(index);
      index++;
      TokenType tokenType = token.getType();
      if (TAG == tokenType) {
        if (inTag) {
          if (">".equals(token.getValue()) || "/>".equals(token.getValue())) {
            // If type is "tag" and content is ">", this is HTML token.
            inTag = false;
          }
        } else {
          // Check that we are in html mode.
          if (CodeMirror2.HTML.equals(token.getMode())) {
            lastTagTokenIndex = index - 1;
            inTag = true;
          }
        }
      }
    }

    if (inTag) {
      if (lastTagTokenIndex != -1) {
        index = lastTagTokenIndex;
        Token token = tokens.get(index);
        index++;
        String tagName = token.getValue().substring(1).trim();
        tag = new HtmlTagWithAttributes(tagName);
        StringMultiset tagAttributes = tag.getAttributes();
        while (index < size) {
          token = tokens.get(index);
          index++;
          TokenType tokenType = token.getType();
          if (ATTRIBUTE == tokenType) {
            String attribute = token.getValue();
            tagAttributes.add(ignoreCase ? attribute.toLowerCase() : attribute);
          }
        }
      }
View Full Code Here


   */
  static boolean buildInvocationSequenceContext(
      JsonArray<Token> tokens, boolean expectingPeriod, JsonArray<String> contextParts) {
    // right-to-left tokens processing loop.
    while (!tokens.isEmpty()) {
      Token lastToken = tokens.pop();
      TokenType lastTokenType = lastToken.getType();
      String lastTokenValue = lastToken.getValue();

      // Omit whitespaces.
      if (lastTokenType == WHITESPACE) {
        continue;
      }
View Full Code Here

    if (result == null) {
      return new ExtendedParseResult<T>(null, Context.NOT_PARSED);
    }

    JsonArray<Token> tokens = result.getTokens();
    Token lastToken = tokens.peek();
    Preconditions.checkNotNull(lastToken,
        "Last token expected to be non-null; text='%s', position=%s", text, position);
    TokenType lastTokenType = lastToken.getType();
    String lastTokenValue = lastToken.getValue();
    if (!addSpace) {
      if (lastTokenType == STRING || lastTokenType == REGEXP) {
        return new ExtendedParseResult<T>(result, Context.IN_STRING);
      } else if (lastTokenType == TokenType.COMMENT) {
        return new ExtendedParseResult<T>(result, Context.IN_COMMENT);
      }

      // Python parser, for a purpose of simplicity, parses period and variable
      // name as a single token. If period is not followed by identifier, parser
      // states that this is and error, which is, generally, not truth.
      if ((lastTokenType == TokenType.ERROR) && LITERAL_PERIOD.equals(lastTokenValue)) {
        tokens.pop();
        tokens.add(new Token(lastToken.getMode(), TokenType.NULL, LITERAL_PERIOD));
      }

      return new ExtendedParseResult<T>(result, Context.IN_CODE);
    }

    // Remove / shorten last token to omit added whitespace.
    tokens.pop();
    if (lastTokenType == STRING || lastTokenType == REGEXP || lastTokenType == TokenType.COMMENT) {
      // Whitespace stuck to token - strip it.
      lastTokenValue = lastTokenValue.substring(0, lastTokenValue.length() - 1);
      tokens.add(new Token(lastToken.getMode(), lastTokenType, lastTokenValue));
      if (lastTokenType == STRING || lastTokenType == REGEXP) {
        return new ExtendedParseResult<T>(result, Context.IN_STRING);
      } else {
        return new ExtendedParseResult<T>(result, Context.IN_COMMENT);
      }
View Full Code Here

      }
      JsonArray<Token> tokens = parseResult.getTokens();
      if (tokens.isEmpty()) {
        return null;
      }
      Token lastToken = tokens.peek();
      return lastToken.getValue();
    }
View Full Code Here

    int indent = 0;
    if (TokenType.WHITESPACE == tokens.get(0).getType()) {
      indent = tokens.get(0).getValue().length();
    }

    Token lastToken = tokens.pop();
    TokenType lastTokenType = lastToken.getType();

    if (lastTokenType == WHITESPACE) {
      return new CompletionContext<T>("", "", false, CompletionType.GLOBAL, parseResult, indent);
    }

    String lastTokenValue = lastToken.getValue();

    if (lastTokenType == KEYWORD) {
      return new CompletionContext<T>(
          "", lastTokenValue, false, CompletionType.GLOBAL, parseResult, indent);
    }
View Full Code Here

    }

    private Token buildTokenModel(TokenInfo token) throws CloudException {
        Preconditions.checkNotNull(token);

        Token response = new Token();

        response.expires = TokenAuth.getExpiration(token);

        UserData user = authRepository.getUsers().find(token.getUserId());
        if (user == null) {
View Full Code Here

  }

  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

    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

          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

      // walk through first level children of AST...
      for (int i = 0; i < ast.jjtGetNumChildren(); ++i) {
        final Node child = ast.jjtGetChild(i); // get current child

        if (child instanceof ASTSelectQuery) {
          final ASTSelectQuery selectChild = (ASTSelectQuery) child;

          // SELECT is not the wildcard *...
          if (!selectChild.isSelectAll()) {
            // walk through select children...
            for (int j = 0; j < selectChild.jjtGetNumChildren(); ++j) {
              final Node selectChildChild = selectChild
              .jjtGetChild(j);

              // child of select is variable...
              if (selectChildChild instanceof ASTVar) {
                final ASTVar var = (ASTVar) selectChildChild;
View Full Code Here

TOP

Related Classes of lupos.sparql1_1.Token

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.