0

I have written a SPARQL query on my own ontology which gives duplication of records, for this I also used group_concat, my query is

SELECT ?Movie (str(?y) as ?Rating) (group_concat (?z;separator=",") as ?Director) 
{ ?Movie :rating ?y;
         :directedBy ?z
 FILTER regex(str(?Movie),'Fantastic_Four') }
  GROUP BY ?y ?Movie

This query gives me the desired result but the output for Director comes in following way:

http://www.semanticweb.org/administrator/ontologies/2017/2/Ontology-Schema_Movie#Josh_Trank,http://www.semanticweb.org/administrator/ontologies/2017/2/Ontology-Schema_Movie#Joshua_Trank

I wonder why this whole URI comes, how to remove this and only print Josh_Trank, Joshua_Trank in my result?

UninformedUser
  • 8,397
  • 1
  • 14
  • 23
  • 1. By the way, `group_concat(distinct ?z; …)` is quite a legal construction. 2. Although variant 2 from AKSW answer is of course preferable, you might be interested in `afn:localname` [alternative definition](https://jena.apache.org/documentation/query/library-function.html#addtional-functions-provided-by-arq) (or in `afn:localname` itself). – Stanislav Kralin Apr 19 '17 at 08:57

1 Answers1

1

RDF resources are identified by URIs, that's why a list of URIs is concatenated. If you need some human readable name

  1. You could use some string functions resp. REGEX on the URI (see a similar question)
    PREFIX : <http://www.semanticweb.org/administrator/ontologies/2017/2/Ontology-Schema_Movie#>                
    SELECT ?Movie (str(?y) as ?Rating) 
           (group_concat (?director_name;separator=",") as ?Director) {
      ?Movie :rating ?y;
             :directedBy ?z
      FILTER regex(str(?Movie),'Fantastic_Four')
      BIND(strafter(str(?z),str(:)) as ?director_name)
    }
    GROUP BY ?y ?Movie
  1. I really suggest to use the rdfs:label (or something similar) if exists for the human readable name of a URI
Community
  • 1
  • 1
UninformedUser
  • 8,397
  • 1
  • 14
  • 23