@Override
    public NodeValue exec(NodeValue v) {
      // http://www.w3.org/TR/xpath-functions/#casting
      String s = null;
      Node n = v.asNode();

      if (n.isBlank()) throw new ExprEvalException("CastXSD: Can't cast blank nodes: " + v);

      if (n.isURI()) {
        if (castType.equals(XSDDatatype.XSDstring)) s = n.getURI();
        else
          throw new ExprEvalException(
              "CastXSD: Can't cast node: " + v + " to " + castType.getURI());
      } else if (n.isLiteral())
        // What if there is a lang tag?
        s = n.getLiteralLexicalForm();
      else
        throw new ExprEvalException(
            "CastXSD: Can't cast node: " + v + "(not a literal, not URI to string)");

      if (s == null && v.isString()) s = v.getString();

      if (s == null)
        throw new ExprEvalException("CastXSD: Can't cast: " + v + "(has no string appearance)");

      //        // Special case - non-normalised xsd:booleans use 0 and 1.
      //        if ( v.isBoolean() )
      //        {
      //            if ( s.equals("0") ) s = "false" ;
      //            if ( s.equals("1") ) s = "true" ;
      //        }

      NodeValue r = cast(s, v, castType);
      return r;
    }
  public static NodeValue strDatatype(NodeValue v1, NodeValue v2) {
    if (!v1.isString()) throw new ExprEvalException("Not a string (arg 1): " + v1);
    if (!v2.isIRI()) throw new ExprEvalException("Not an IRI (arg 2): " + v2);

    String lex = v1.asString();
    Node dt = v2.asNode();
    // Check?

    Node n = Node.createLiteral(lex, null, Node.getType(dt.getURI()));
    return NodeValue.makeNode(n);
  }
示例#3
0
 /* (non-Javadoc)
  * @see com.hp.hpl.jena.sparql.function.FunctionBase2#exec(com.hp.hpl.jena.sparql.expr.NodeValue, com.hp.hpl.jena.sparql.expr.NodeValue)
  */
 @Override
 public NodeValue exec(NodeValue uri, NodeValue pattern) {
   if (uri.asNode().isVariable()) {
     return uri;
   }
   // Simulate the identity
   Node nuri = uri.asNode();
   String result = null;
   String regexPattern = pattern.asUnquotedString();
   try {
     result = getSameAs(nuri.getURI(), regexPattern);
     if (result == null) {
       Logger.getAnonymousLogger().log(Level.INFO, "No results found for uri:" + nuri);
       return NodeValue.makeNode(nuri);
     } else {
       return NodeValue.makeNode(Node.createURI(result));
     }
   } catch (Exception e) {
     return uri;
   }
 }
  public void visit(NodeValue value) {
    logger.debug("visit NodeValue " + value);

    if (!convertable) {
      expression.push(Expression.FALSE); // prevent stack empty exceptions when conversion
      return; // fails in the middle of a multi-arg operator conversion
    }

    if (value.isDecimal()
        || value.isDouble()
        || value.isFloat()
        || value.isInteger()
        || value.isNumber()) {
      expression.push(new ConstantEx(value.asString(), value.asNode()));
    } else if (value.isDateTime()) {
      // Convert xsd:dateTime: CCYY-MM-DDThh:mm:ss
      // to SQL-92 TIMESTAMP: CCYY-MM-DD hh:mm:ss[.fraction]
      // TODO support time zones (WITH TIME ZONE columns)
      expression.push(new ConstantEx(value.asString().replace("T", " "), value.asNode()));
    } else {
      expression.push(new ConstantEx(value.asString(), value.asNode()));
    }
  }
 // -------- datatype
 public static NodeValue datatype(NodeValue nv) {
   return NodeValue.makeNode(datatype(nv.asNode()));
 }
 // -------- str
 public static NodeValue str(NodeValue nv) {
   return NodeValue.makeString(str(nv.asNode()));
 }
 public static NodeValue rdfTermEquals(NodeValue nv1, NodeValue nv2) {
   return NodeValue.booleanReturn(rdfTermEquals(nv1.asNode(), nv2.asNode()));
 }
 public static NodeValue sameTerm(NodeValue nv1, NodeValue nv2) {
   return NodeValue.booleanReturn(sameTerm(nv1.asNode(), nv2.asNode()));
 }
  @Override
  public NodeValue exec(NodeValue objectv1, NodeValue leftv2, NodeValue rightv3, NodeValue boolv4) {

    String object = objectv1.asUnquotedString();
    if (DateUtil.determineDateFormat(object) == null) return NodeValue.FALSE;
    String left = leftv2.asUnquotedString();
    String right = rightv3.asUnquotedString();

    boolean ismax = Boolean.parseBoolean(boolv4.asNode().getLiteralValue().toString());

    HelperFunctions helper = HelperFunctions.getInstance();

    try {

      // SimpleDateFormat parsedate = new SimpleDateFormat("yyyy-MM");
      Date objectdate = DateUtil.parse(object);
      Date newobjectdate = helper.parse(helper.format(objectdate));

      long objecttime = newobjectdate.getTime(); // +  1 * 24 * 60 * 60 * 1000;
      Date leftdate = DateUtil.parse(left);
      long lefttime = leftdate.getTime();
      Date rightdate = DateUtil.parse(right);
      long righttime = rightdate.getTime();

      if (ismax) {

        if (objecttime >= lefttime && objecttime <= righttime) {
          return NodeValue.TRUE;
        }

      } else {

        if (objecttime >= lefttime && objecttime <= righttime) {
          return NodeValue.TRUE;
        }
      }

      //			if (!ismax) {
      //                //TODO: // conditions were >= , <
      //				if ((objecttime >= lefttime) && (objecttime <= righttime)) {
      //
      //					return NodeValue.TRUE;
      //				} else {
      //					// check what happens with the date type? will empty string
      //					// work?
      //					return NodeValue.FALSE;
      //
      //				}
      //			} else {
      //
      //				if ((objecttime >= lefttime) && (objecttime <= righttime)) {
      //
      //					return NodeValue.TRUE;
      //				} else {
      //
      //					return NodeValue.FALSE;
      //
      //				}
      //
      //			}

    } catch (ParseException pe) {

      System.out.println("IN REGEX FUNCTION UNKNOWN DATE FORMAT:" + object);
      pe.printStackTrace();
    }

    return NodeValue.FALSE;
  }
示例#10
0
 // -------- isLiteral
 public static NodeValue isLiteral(NodeValue nv) {
   return NodeValue.booleanReturn(isLiteral(nv.asNode()));
 }
示例#11
0
 // -------- isBlank
 public static NodeValue isBlank(NodeValue nv) {
   return NodeValue.booleanReturn(isBlank(nv.asNode()));
 }
示例#12
0
 public static NodeValue isURI(NodeValue nv) {
   return NodeValue.booleanReturn(isIRI(nv.asNode()));
 }
示例#13
0
  public static NodeValue langMatches(NodeValue nv, String langPattern) {
    Node node = nv.asNode();
    if (!node.isLiteral()) {
      NodeValue.raise(new ExprTypeException("langMatches: not a literal: " + node));
      return null;
    }

    String nodeLang = node.getLiteralLexicalForm();

    if (langPattern.equals("*")) {
      if (nodeLang == null || nodeLang.equals("")) return NodeValue.FALSE;
      return NodeValue.TRUE;
    }

    // See RFC 3066 (it's "tag (-tag)*)"

    String[] langElts = nodeLang.split("-");
    String[] langRangeElts = langPattern.split("-");

    /*
     * Here is the logic to compare language code.
     * There is a match if the language matches the
     * parts of the pattern - the language may be longer than
     * the pattern.
     */

    /* RFC 4647 basic filtering.
     *
     * To do extended:
     * 1. Remove any -*- (but not *-)
     * 2. Compare primary tags.
     * 3. Is the remaining range a subsequence of the remaining language tag?
     */

    //        // Step one: remove "-*-" (but not "*-")
    //        int j = 1 ;
    //        for ( int i = 1 ; i < langRangeElts.length ; i++ )
    //        {
    //            String range = langRangeElts[i] ;
    //            if ( range.equals("*") )
    //                continue ;
    //            langRangeElts[j] = range ;
    //            j++ ;
    //        }
    //
    //        // Null fill any free space.
    //        for ( int i = j ; i < langRangeElts.length ; i++ )
    //            langRangeElts[i] = null ;

    // This is basic specific.

    if (langRangeElts.length > langElts.length)
      // Lang tag longer than pattern tag => can't match
      return NodeValue.FALSE;
    for (int i = 0; i < langRangeElts.length; i++) {
      String range = langRangeElts[i];
      if (range == null) break;
      // Language longer than range
      if (i >= langElts.length) break;
      String lang = langElts[i];
      if (range.equals("*")) continue;
      if (!range.equalsIgnoreCase(lang)) return NodeValue.FALSE;
    }
    return NodeValue.TRUE;
  }
示例#14
0
 public static NodeValue lang(NodeValue nv) {
   return NodeValue.makeString(lang(nv.asNode()));
 }
 @Override
 public void visit(NodeValue nv) {
   tms.push(tmf.createTermMap(nv.asNode()));
 }
示例#16
0
 // -------- IRI
 public static NodeValue iri(NodeValue nv, String baseIRI) {
   if (isIRI(nv.asNode())) return nv;
   Node n2 = iri(nv.asNode(), baseIRI);
   return NodeValue.makeNode(n2);
 }
示例#17
0
 @Override
 protected Node makeNode() {
   return nodeValue.asNode();
 }