Question

I am running a SPARQL Query against an ontology and getting the results. But, the complete URIs are displayed in the results.

For Example:

SPARQL Query

SELECT ?s where { ?s :wasBornIn :Ulm } LIMIT 1

Result -

s={http://yago-knowledge.org/resource/Albert_Einstein}

Instead of the complete URI, I want only "Albert_Einstein" to be printed. Is there any way to accomplish this without using the rdfs:label property and Model.SetNsPrefix(String nsprefix, String URI) method.

Was it helpful?

Solution

You can do it:

  1. If you are using Jena Java code to make the query, ask for the resources "local name"
  2. In SPARQL, there many ways, depending on how general you want to be, using BIND or a SELECT expression (e.g. (STRAFTER(....) AS ?sName))

    STRAFTER(str(?s), "http://yago-knowledge.org/resource/")

    REPLACE(str(?s), "(.*)/", "")

See the spec for details of each function.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top