public static PropFuncArg substitute(PropFuncArg propFuncArg, Binding binding) {
    if (isNotNeeded(binding)) return propFuncArg;

    if (propFuncArg.isNode()) return new PropFuncArg(substitute(propFuncArg.getArg(), binding));

    List<Node> newArgList = new ArrayList<Node>();
    for (Node n : propFuncArg.getArgList()) newArgList.add(substitute(n, binding));
    return new PropFuncArg(newArgList);
  }
Esempio n. 2
0
  @Override
  public void build(
      PropFuncArg argSubject, Node predicate, PropFuncArg argObject, ExecutionContext execCxt) {
    super.build(argSubject, predicate, argObject, execCxt);

    if (!argSubject.isNode())
      throw new QueryBuildException("Subject is not a single node: " + argSubject);

    if (argObject.isList()) {
      List<Node> list = argObject.getArgList();
      if (list.size() < 4) throw new QueryBuildException("Not enough arguments in list");

      if (list.size() > 5) throw new QueryBuildException("Too many arguments in list : " + list);
    }
  }
Esempio n. 3
0
  /** Deconstruct the node or list object argument and make a SpatialMatch */
  @Override
  protected SpatialMatch objectToStruct(PropFuncArg argObject) {

    if (argObject.isNode()) {
      log.warn("Object not a List: " + argObject);
      return null;
    }

    List<Node> list = argObject.getArgList();

    if (list.size() < 4 || list.size() > 5)
      throw new SpatialIndexException("Change in object list size");

    int idx = 0;

    Node x = list.get(idx);
    if (!x.isLiteral()) {
      log.warn("Latitude 1 is not a literal " + list);
      return null;
    }
    if (!SpatialValueUtil.isDecimal(x.getLiteral())) {
      log.warn("Latitude 1 is not a decimal " + list);
      return null;
    }
    Double latitude1 = Double.parseDouble(x.getLiteralLexicalForm());

    idx++;

    x = list.get(idx);
    if (!x.isLiteral()) {
      log.warn("Longitude 1 is not a literal " + list);
      return null;
    }
    if (!SpatialValueUtil.isDecimal(x.getLiteral())) {
      log.warn("Longitude 1 is not a decimal " + list);
      return null;
    }
    Double longtitude1 = Double.parseDouble(x.getLiteralLexicalForm());

    idx++;

    x = list.get(idx);
    if (!x.isLiteral()) {
      log.warn("Latitude 2 is not a literal " + list);
      return null;
    }
    if (!SpatialValueUtil.isDecimal(x.getLiteral())) {
      log.warn("Latitude 2 is not a decimal " + list);
      return null;
    }
    Double latitude2 = Double.parseDouble(x.getLiteralLexicalForm());

    idx++;

    x = list.get(idx);
    if (!x.isLiteral()) {
      log.warn("Longitude 2 is not a literal " + list);
      return null;
    }
    if (!SpatialValueUtil.isDecimal(x.getLiteral())) {
      log.warn("Longitude 2 is not a decimal " + list);
      return null;
    }
    Double longtitude2 = Double.parseDouble(x.getLiteralLexicalForm());

    idx++;
    int limit = -1;

    if (idx < list.size()) {
      x = list.get(idx);

      if (!x.isLiteral()) {
        log.warn("Limit is not a literal " + list);
        return null;
      }

      LiteralLabel lit = x.getLiteral();

      if (!XSDDatatype.XSDinteger.isValidLiteral(lit)) {
        log.warn("Limit is not an integer " + list);
        return null;
      }

      int v = NodeFactoryExtra.nodeToInt(x);
      limit = (v < 0) ? -1 : v;

      idx++;
      if (idx < list.size()) {
        log.warn("Limit is not the last parameter " + list);
        return null;
      }
    }

    SpatialMatch match =
        new SpatialMatch(
            latitude1, longtitude1, latitude2, longtitude2, limit, getSpatialOperation());

    if (log.isDebugEnabled()) log.debug("Trying SpatialMatch: " + match.toString());
    return match;
  }