On Wed, May 14, 2014 at 7:38 AM, Alejandro Rodríguez González
<[email protected]> wrote:
> My problem is that, if I execute this query manually against the endpoint
> (see: http://goo.gl/RVWuSi ) I can get correctly the desired result (a
> datatype). However, doing this by code, I got the QuerySolution object
> (which contains the variable name (dt) and the datatype (xml:string)), but
> I can't get the datatype from the QuerySolution object.
>
> If I try calling getResource(variable) method, it returns null. If I do the
> same with the getLiteral(variable) or get(variable) to get a RDFNode,
> always it returns a null value. Now, I'm getting the value parsing the
> toString() value of the QuerySolution object, but I'm wondering if it is an
> easier way to do that, or maybe I'm not using the correct classes/methods.
Your endpoint isn't available (at least to me) so I can't reproduce
the problem, but I can produce an example where we can clearly get the
value of a variable bound to the result of datatype(?var), and see
that it's a resource.
import com.hp.hpl.jena.query.QueryExecutionFactory;
import com.hp.hpl.jena.query.ResultSet;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;
public class DatatypeExample {
public static void main(String[] args) {
Model model = ModelFactory.createDefaultModel();
String query = "select (datatype(5) as ?datatype) { }";
ResultSet results = QueryExecutionFactory.create( query, model
).execSelect();
System.out.println( results.next().getResource( "datatype" ));
}
}
datatype(5) returns xsd:integer, which is a resource, so we can
getResource("datatype") to get the resource. The output of the
program is
http://www.w3.org/2001/XMLSchema#integer
//JT
--
Joshua Taylor, http://www.cs.rpi.edu/~tayloj/