sparql - Are typed literals "tricky" in RDF4J? -


in rdf, can have entity bound single property multiple literal values. values can typed add clarity.

:dumptruck :weight "heavy"^^xsd:string . :dumptruck :weight "36000"^^xsd:integer . 

in sparql, can query type want

select  ?w   { :dumptruck  :weight  ?w     filter ( datatype(?w) = xsd:integer )   } 

is there getstatement in rdf4j can constrained datatype that?

there's no priori constraint possible, can post-process result filter on datatype. example use along these lines (untested drift hopefully):

queryresults.stream(conn.getstatements(dumptruck, weight, null))             .filter(s -> ((literal)s.getobject()).getdatatype().equals(xmlschema.integer))             .collect(collectors.tolist()); 

or alternatively, stick in model first , filter:

model m = queryresults.asmodel(conn.getstatements(dumptruck, weight, null)); list intvalues = models.objectliterals(m).stream().filter(l -> l.getdatatype().equals(xmlschema.integer)).collect(collectors.tolist());  

i'm sure there's couple of other/handier shortcuts available haven't thought of. rdf4j docs have tutorials , examples spare, however.


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -