Search code examples
rdfsparql

How to get the suffix of a URI (after #)?


I typed this query:

SELECT ?p  FROM a.owl WHERE {<http:/edamontology.org/operation_0311> ?p ?o } 

The result is the full URI of each property. E.g.:

http:/www.geneontology.org/formats/oboInOwl#inSubset
http:/www.w3.org/2000/01/rdf-schema#subClassOf
http:/www.w3.org/2002/07/owl#Class

I don't want the URI, I just want to have the part after #. That is, I want

inSubset
subClassOf
Class

How can I get that?


Solution

  • You want the part of the string of the URI after an occurrence of #. That's easy enoug with strafter.

    select (strafter(str(?p),'#') as ?plabel) {
      values ?p { <http:/www.geneontology.org/formats/oboInOwl#inSubset>
                  <http:/www.w3.org/2000/01/rdf-schema#subClassOf>
                  <http:/www.w3.org/2002/07/owl#Class> }
    }
    

    SPARQL results

    plabel
    ----------
    inSubset
    subClassOf
    Class