sparqlblazegraph

How can I select the literal value and the IRI type on Blazegraph workbench?


I have a SPARQL query that selects the position given a source. Below is an example of a triple out of the millions in the file.

Triple:

<origin://123@12> <http://example.org/example#position> "16977"^^<http://www.w3.org/2001/XMLSchema#integer> .

The query I have written:

select  ?origin ?pos where {
  ?origin <http://example.org/example#position> ?pos . } limit 10

This gives me the output:

origin            | pos

<origin://123@12> | 16977

But the output I want is:

origin            | pos

<origin://123@12> | "16977"^^<http://www.w3.org/2001/XMLSchema#integer>

Is there a way to do this? I am using Blazegraph and the primary reason for this is, I want the literal type to be able to identify integers and floats for further processing.


Solution

  • With datatype(), you can output a value’s datatype IRI:

    SELECT ?origin ?pos ?pos_datatype
    WHERE {
      ?origin <http://example.org/example#position> ?pos . 
      BIND( datatype(?pos) AS ?pos_datatype ) .
    } LIMIT 10
    
    SELECT ?origin ?pos ( datatype(?pos) AS ?pos_datatype )
    WHERE {
      ?origin <http://example.org/example#position> ?pos . 
    } LIMIT 10