Loading TOC...

MarkLogic 10 Product Documentation
op:from-sparql

op:from-sparql(
   $select as xs:string,
   [$qualifier as xs:string?],
   [$options as map:map?]
) as map:map

Summary

This function dynamically constructs a row set based on a SPARQL SELECT query from triples.

Parameters
$select A SPARQL SELECT query expressed as a string.
$qualifier Specifies a name for qualifying the column names. An "@" in front of the name specifies a parameter placeholder. A parameter placeholder in the SPARQL string must be bound to a parameter value in the result() call.
$options Options consisting of key-value pairs that set options. At present, the options consist of dedup and base. Option dedup can take an on|off value to enable or disable deduplication. Deduplication is on by default but will become off by default in a future release. Option base takes a string as the initial base IRI for the query.

Example

(: List all of the people born in Brooklyn. :)

xquery version "1.0-ml";

import module namespace op="http://marklogic.com/optic"
     at "/MarkLogic/optic.xqy";

  op:from-sparql('PREFIX db: <http://dbpedia.org/resource/>
                  PREFIX foaf: <http://xmlns.com/foaf/0.1/>
                  PREFIX onto: <http://dbpedia.org/ontology/>
                  SELECT ?person ?name
                    WHERE { ?person onto:birthPlace db:Brooklyn;
                    foaf:name @name .}')
  => op:result((), map:entry("name", "Mae West"))

  

Example

(: List the firstname of the people with id <http://marklogicsparql.com/id#5555> :)

xquery version "1.0-ml";

import module namespace op="http://marklogic.com/optic"
     at "/MarkLogic/optic.xqy";

  op:from-sparql(
      concat('PREFIX ad: <http://marklogicsparql.com/addressbook#> ',
             'SELECT ?firstName ',
             'WHERE {<#5555> ad:firstName ?firstName .}'),
      "sparql", map:map()=>map:with("dedup", "off")=>map:with("base", "http://marklogicsparql.com/id#"))
  => op:result()

  

Stack Overflow iconStack Overflow: Get the most useful answers to questions from the MarkLogic community, or ask your own question.