Search code examples
sparqlxquerymarklogicsemantics

SPARQL using xqueries


I am new to sparql. Hence tried to hands on with the code.

I tried to write the below code but not getting the result, when i tried to pass the "sub" parameter I am not getting any result.

xquery version "1.0-ml";
import module namespace sem = "http://marklogic.com/semantics" at "/MarkLogic/semantics.xqy";

declare namespace s = "http://www.w3.org/2005/sparql-results#";

let $map := map:map()
let $_ := map:put($map, "sub", "res:Porsche_912")

let $result := 
    sem:query-results-serialize(
      sem:sparql(
       "PREFIX pre: <http://dbpedia.org/ontology/Automobile/>
        PREFIX res: <http://dbpedia.org/resource/>
        SELECT  ?p ?o 
        WHERE {
            ?sub ?p ?o .
        }",$map
      )
    )

return $result

THE BELOW CODE IS WORKING

xquery version "1.0-ml";
import module namespace sem = "http://marklogic.com/semantics" at "/MarkLogic/semantics.xqy";

declare namespace s = "http://www.w3.org/2005/sparql-results#";

let $map := map:map()
let $_ := map:put($map, "sub", "res:Porsche_912")

let $result := 
    sem:query-results-serialize(
      sem:sparql(
       "PREFIX pre: <http://dbpedia.org/ontology/Automobile/>
        PREFIX res: <http://dbpedia.org/resource/>
        SELECT  ?p ?o 
        WHERE {
            <http://dbpedia.org/resource/Porsche_912> ?p ?o .
        }",$map
      )
    )

return $result

My question is:

  1. In the 2nd code, I have hardcoded the subject "sub" and getting the result. But I want to make it dynamic by passing a parameter inside a map as I tried in 1st code. Can you please tell me why the 1st code is not working?

  2. I have

param1 = http://dbpedia.org/resource/ param2 = Porsche_912

Is there any function available in SPARQL , that return the complete IRI with this two params. like

Param1 + Param2 = http://dbpedia.org/resource/Porsche_912

Expected a result


Solution

  • The value of sub needs to be a sem:iri.

    Your query should work if instead of "res:Porsche_912" you use sem:iri("http://dbpedia.org/resource/Porsche_912")