You can do it:
- If you are using Jena Java code to make the query, ask for the resources "local name"
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.