Search code examples
sparqlsemantic-webontologyprotege

SPARQL How to print the data without data scheme


I have this ontology model:

SensorOntology:MedicalCabinet-01 rdf:type owl:NamedIndividual ,
                               SensorOntology:MedicalCabinetSensor ;
                      SensorOntology:hasId "57"^^xsd:int ;
                      SensorOntology:hasValue "0"^^xsd:int .

I wrote this query

SELECT ?sensor ?value
WHERE { ?sensor:hasId "51"^^xsd:int.
        ?sensor :hasValue ?value}

The result is this

    sensor            |  value
-------------------------------------------------------------------------
    MedicalCabinet-01 | "0"^^<http://www.w3.org/2001/XMLSchema#int>

Is it any way to print this:

    sensor            |  value
-------------------------------------------------------------------------
    MedicalCabinet-01 | 0

I don't want to print ^^<http://www.w3.org/2001/XMLSchema#int>


Solution

  • What you mean and want to omit is the datatype IRI of the RDF literal:

    A literal in an RDF graph consists of two or three elements:

    • a lexical form, being a Unicode [UNICODE] string, which should be in Normal Form C [NFC],
    • a datatype IRI, being an IRI identifying a datatype that determines how the lexical form maps to a literal value, and
    • ...

    The lexical form of a literal can be returned by the function STR(note, it will be a string then):

    SELECT ?sensor (STR(?val) as ?value)
    WHERE { ?sensor:hasId "51"^^xsd:int.
            ?sensor :hasValue ?val}