use of it.unibo.arces.wot.sepa.commons.sparql.RDFTermBNode in project SEPA by arces-wot.
the class JSAP method getQueryBindings.
public ForcedBindings getQueryBindings(String id) throws IllegalArgumentException {
if (!jsap.get("queries").getAsJsonObject().has(id))
throw new IllegalArgumentException("Query ID not found: " + id);
ForcedBindings ret = new ForcedBindings();
if (!jsap.getAsJsonObject("queries").getAsJsonObject(id).has("forcedBindings"))
return ret;
try {
for (Entry<String, JsonElement> binding : jsap.getAsJsonObject("queries").getAsJsonObject(id).getAsJsonObject("forcedBindings").entrySet()) {
RDFTerm bindingValue = null;
String value = null;
if (binding.getValue().getAsJsonObject().has("value"))
value = binding.getValue().getAsJsonObject().get("value").getAsString();
switch(binding.getValue().getAsJsonObject().get("type").getAsString()) {
case "literal":
String datatype = null;
if (binding.getValue().getAsJsonObject().has("datatype"))
datatype = binding.getValue().getAsJsonObject().get("datatype").getAsString();
String language = null;
if (binding.getValue().getAsJsonObject().has("language"))
language = binding.getValue().getAsJsonObject().get("language").getAsString();
bindingValue = new RDFTermLiteral(value, datatype, language);
break;
case "uri":
bindingValue = new RDFTermURI(value);
break;
case "bnode":
bindingValue = new RDFTermBNode(value);
break;
default:
logger.error("JSAP unknown type: " + binding);
continue;
}
ret.addBinding(binding.getKey(), bindingValue);
}
} catch (Exception e) {
logger.error("getQueryBindings " + id + " exception: " + e.getMessage());
}
return ret;
}
use of it.unibo.arces.wot.sepa.commons.sparql.RDFTermBNode in project SEPA by arces-wot.
the class JSAP method getUpdateBindings.
/**
* <pre>
* "forcedBindings" : {
* "variable_1" : {
* "type" : "literal",
* "datatype" : "xsd:short"}
* ,
* "variable_2" : {
* "type" : "uri"}
* ,
* "variable_3" : {
* "type": "literal",
* "datatype" : "xsd:string",
* "language" : "it"},
* ...
* "variable_N" : {
* "type" : "literal",
* "datatype" : "xsd:dateTime" ,
* "value" : "1985-08-03T01:02:03Z"}
* }
* </pre>
*/
public ForcedBindings getUpdateBindings(String id) throws IllegalArgumentException {
if (!jsap.get("updates").getAsJsonObject().has(id))
throw new IllegalArgumentException("Update ID not found: " + id);
ForcedBindings ret = new ForcedBindings();
if (!jsap.getAsJsonObject("updates").getAsJsonObject(id).has("forcedBindings"))
return ret;
try {
for (Entry<String, JsonElement> binding : jsap.getAsJsonObject("updates").getAsJsonObject(id).getAsJsonObject("forcedBindings").entrySet()) {
if (!binding.getValue().getAsJsonObject().has("type")) {
logger.error("JSAP missing binding type: " + binding);
continue;
}
RDFTerm bindingValue = null;
String value = null;
if (binding.getValue().getAsJsonObject().has("value"))
value = binding.getValue().getAsJsonObject().get("value").getAsString();
switch(binding.getValue().getAsJsonObject().get("type").getAsString()) {
case "literal":
String datatype = null;
if (binding.getValue().getAsJsonObject().has("datatype"))
datatype = binding.getValue().getAsJsonObject().get("datatype").getAsString();
String language = null;
if (binding.getValue().getAsJsonObject().has("language"))
language = binding.getValue().getAsJsonObject().get("language").getAsString();
bindingValue = new RDFTermLiteral(value, datatype, language);
break;
case "uri":
bindingValue = new RDFTermURI(value);
break;
case "bnode":
bindingValue = new RDFTermBNode(value);
break;
default:
logger.error("JSAP unknown type: " + binding);
continue;
}
ret.addBinding(binding.getKey(), bindingValue);
}
} catch (Exception e) {
logger.error("getUpdateBindings " + id + " exception: " + e.getMessage());
}
return ret;
}
Aggregations