public static NodeValue strLang(NodeValue v1, NodeValue v2) {
    if (!v1.isString()) throw new ExprEvalException("Not a string (arg 1): " + v1);
    if (!v2.isString()) throw new ExprEvalException("Not a string (arg 2): " + v2);

    String lex = v1.asString();
    String lang = v2.asString();
    // Check?

    Node n = Node.createLiteral(lex, lang, null);
    return NodeValue.makeNode(n);
  }
    @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);
  }
Example #4
0
  @Override
  public NodeValue exec(NodeValue v) {
    if (!v.isString()) {
      ALog.warn(this, "date: argument not a string: " + v);
      throw new ExprEvalException("date: argument not a string: " + v);
    }

    String lexicalForm = v.getString();

    // Quite picky about format
    if (!lexicalForm.matches("\\d{4}-\\d{2}-\\d{2}")) {
      ALog.warn(this, "date: argument not in date format: " + v);
      throw new ExprEvalException("date: argument not in date format: " + v);
    }

    lexicalForm = lexicalForm + "T00:00:00Z";

    NodeValue nv = NodeValue.makeNode(lexicalForm, XSDDatatype.XSDdateTime);
    return nv;
  }
    private SWRLDataObject makeDataObject(final Expr expr) throws URISyntaxException {
      if (expr.isVariable()) {
        return swrlFactory.createDataVariable(new URI(varNS + expr.getVarName()));
      } else if (expr.isConstant()) {
        final NodeValue nv = (NodeValue) expr;
        OWLDataValue value;
        if (nv.isInteger()) value = owlModel.createDataValue(nv.getInteger());
        else if (nv.isDouble()) value = owlModel.createDataValue(Double.valueOf(nv.getDouble()));
        else if (nv.isFloat()) value = owlModel.createDataValue(Float.valueOf(nv.getFloat()));
        else if (nv.isBoolean()) value = owlModel.createDataValue(Boolean.valueOf(nv.getBoolean()));
        else if (nv.isString()) value = owlModel.createDataValue(nv.getString());
        else if (nv.isDecimal()) value = owlModel.createDataValue(nv.getDecimal());
        else if (nv.hasDateTime()) value = owlModel.createDataValue(nv.getDateTime());
        else /* if (nv.isLiteral()) */ throw new NotImplementedException();

        return swrlFactory.wrapDataValue(value);
      } else {
        throw new IllegalArgumentException(
            "Nested constraint (filter) near " + expr + " can not be transformed to SWRL atom.");
      }
    }