/** * Wrap a functor as a Literal node * @param f the functor data structure to be wrapped in a node. */ public static Node makeFunctorNode(Functor f) { return NodeFactory.createLiteralByValue(f, FunctorDatatype.theFunctorDatatype); }
public static Node jsonToNode(JsonElement json) { RDFDatatype dtype = RDFDatatypeJson.INSTANCE; Node result = NodeFactory.createLiteralByValue(json, dtype); return result; } }
public static Node jsonToNode(JsonElement json) { RDFDatatype dtype = RDFDatatypeJson.INSTANCE; Node result = NodeFactory.createLiteralByValue(json, dtype); return result; } }
/** * Wrap a functor as a Literal node * @param f the functor data structure to be wrapped in a node. */ public static Node makeFunctorNode(Functor f) { return NodeFactory.createLiteralByValue(f, FunctorDatatype.theFunctorDatatype); }
/** @deprecated To be removed: Use {@link #createLiteralByValue(Object, String, RDFDatatype)} */ @Deprecated public static Node createUncachedLiteral(Object value, String lang, RDFDatatype dtype) throws DatatypeFormatException { Objects.requireNonNull(value, "Argument 'value' to NodeFactory.createLiteralByValue is null") ; return createLiteralByValue(value, lang, dtype) ; } }
/** @deprecated To be removed: Use {@link #createLiteralByValue(Object, RDFDatatype)} */ @Deprecated public static Node createUncachedLiteral(Object value, RDFDatatype dtype) throws DatatypeFormatException { Objects.requireNonNull(value, "Argument 'value' to NodeFactory.createLiteralByValue is null") ; return createLiteralByValue(value, dtype) ; }
/** @deprecated To be removed: Use {@link #createLiteralByValue(Object, String, RDFDatatype)} */ @Deprecated public static Node createUncachedLiteral(Object value, String lang, RDFDatatype dtype) throws DatatypeFormatException { Objects.requireNonNull(value, "Argument 'value' to NodeFactory.createLiteralByValue is null") ; return createLiteralByValue(value, lang, dtype) ; } }
/** @deprecated To be removed: Use {@link #createLiteralByValue(Object, RDFDatatype)} */ @Deprecated public static Node createUncachedLiteral(Object value, RDFDatatype dtype) throws DatatypeFormatException { Objects.requireNonNull(value, "Argument 'value' to NodeFactory.createLiteralByValue is null") ; return createLiteralByValue(value, dtype) ; }
public static Node jsonToNode(JsonElement e, Gson gson, RDFDatatype jsonDatatype) { Node result; if(e == null) { result = null; } else if(e.isJsonPrimitive()) { //JsonPrimitive p = e.getAsJsonPrimitive(); Object o = gson.fromJson(e, Object.class); //JsonTransformerUtils.toJavaObject(p); if(o != null) { RDFDatatype dtype = TypeMapper.getInstance().getTypeByValue(o); result = NodeFactory.createLiteralByValue(o, dtype); } else { throw new RuntimeException("Datatype not supported " + e); } } else if(e.isJsonObject() || e.isJsonArray()) { // arrays are json objects / array e.isJsonArray() || result = NodeFactory.createLiteralByValue(e, jsonDatatype);//new NodeValueJson(e); } else { throw new RuntimeException("Datatype not supported " + e); } return result; }
@Override public Expr visit(ValueExpression<?> e) { Object value = e.getValue(); RDFDatatype rdfDatatype = typeMapper.getTypeByValue(value); Node node = NodeFactory.createLiteralByValue(value, rdfDatatype); NodeValue result = NodeValue.makeNode(node); return result; }
@Override public NodeValue exec(NodeValue v) { NodeValue result = NodeValue.nvNothing; Node tmp = v.asNode(); if(tmp.isLiteral()) { RDFDatatype dtype = tmp.getLiteralDatatype(); if(dtype.getJavaClass().isAssignableFrom(JsonElement.class)) { JsonElement el = (JsonElement)tmp.getLiteralValue(); if(el.isJsonArray()) { JsonArray arr = el.getAsJsonArray(); JsonArray t = new JsonArray(); for(int i = arr.size() -1; i >= 0; --i) { JsonElement item = arr.get(i); t.add(item); } result = NodeValue.makeNode(NodeFactory.createLiteralByValue(t, dtype)); } } } return result; } }
@Override public NodeValue exec(NodeValue v) { NodeValue result = NodeValue.nvNothing; Node tmp = v.asNode(); if(tmp.isLiteral()) { RDFDatatype dtype = tmp.getLiteralDatatype(); if(dtype.getJavaClass().isAssignableFrom(JsonElement.class)) { JsonElement el = (JsonElement)tmp.getLiteralValue(); if(el.isJsonArray()) { JsonArray arr = el.getAsJsonArray(); JsonArray t = new JsonArray(); for(int i = arr.size() -1; i >= 0; --i) { JsonElement item = arr.get(i); t.add(item); } result = NodeValue.makeNode(NodeFactory.createLiteralByValue(t, dtype)); } } } return result; } }
private Triple sampleFromNum(int i) { return Triple.create(SUBJECT, PREDICATE, createLiteralByValue(i, INTEGER_TYPE)); }
private Triple sampleFromNum(int i) { return Triple.create(SUBJECT, PREDICATE, createLiteralByValue(i, INTEGER_TYPE)); }
@Override public Expr visit(ValueExpression<?> e) { Object value = e.getValue(); RDFDatatype rdfDatatype = typeMapper.getTypeByValue(value); Node node = NodeFactory.createLiteralByValue(value, rdfDatatype); NodeValue result = NodeValue.makeNode(node); return result; }
public static Node jsonToNode(Object o, Gson gson, RDFDatatype jsonDatatype) { boolean isPrimitive = o instanceof Boolean || o instanceof Number || o instanceof String; Node result; if(o == null) { result = null; } else if(isPrimitive) { RDFDatatype dtype = TypeMapper.getInstance().getTypeByValue(o); result = NodeFactory.createLiteralByValue(o, dtype); } else if(o instanceof JsonElement) { JsonElement e = (JsonElement)o; result = jsonToNode(e, gson, jsonDatatype); } else { // Write the object to json and re-read it as a json-element String str = gson.toJson(o); JsonElement e = gson.fromJson(str, JsonElement.class); result = jsonToNode(e, gson, jsonDatatype); } // else { // throw new RuntimeException("Unknown type: " + o); // } return result; }
@Override public NodeValue exec(List<NodeValue> args) { NodeValue result = NodeValue.nvNothing; NodeValue haystack = args.get(0); NodeValue needle = args.get(1); NodeValue limit = args.size() > 2 ? args.get(2) : null; int l = limit == null || limit.isInteger() ? -1 : limit.getInteger().intValue(); if(haystack.isString() && needle.isString()) { RDFDatatype jsonDatatype = TypeMapper.getInstance().getTypeByClass(JsonElement.class); String h = haystack.getString(); String n = needle.getString(); String[] strs = h.split(n, l); JsonArray arr = new JsonArray(); for(String str : strs) { arr.add(str); } Node node = NodeFactory.createLiteralByValue(arr, jsonDatatype); result = NodeValue.makeNode(node); } return result; }
@Override public NodeValue exec(List<NodeValue> args) { NodeValue result = NodeValue.nvNothing; NodeValue haystack = args.get(0); NodeValue needle = args.get(1); NodeValue limit = args.size() > 2 ? args.get(2) : null; int l = limit == null || limit.isInteger() ? -1 : limit.getInteger().intValue(); if(haystack.isString() && needle.isString()) { RDFDatatype jsonDatatype = TypeMapper.getInstance().getTypeByClass(JsonElement.class); String h = haystack.getString(); String n = needle.getString(); String[] strs = h.split(n, l); JsonArray arr = new JsonArray(); for(String str : strs) { arr.add(str); } Node node = NodeFactory.createLiteralByValue(arr, jsonDatatype); result = NodeValue.makeNode(node); } return result; }
private void testValueToLex(Object value, XSDDatatype datatype) { Node node = NodeFactory.createLiteralByValue(value, datatype) ; assertTrue("Not valid lexical form "+value+" -> "+node, datatype.isValid(node.getLiteralLexicalForm())) ; }
private void testValueToLex(Object value, XSDDatatype datatype) { Node node = NodeFactory.createLiteralByValue(value, datatype) ; assertTrue("Not valid lexical form "+value+" -> "+node, datatype.isValid(node.getLiteralLexicalForm())) ; }