MarkLogic 12 EA 1 Product Documentation
sem:rdf-builder

sem:rdf-builder(
   [$prefixes as map:map?],
   [$graph as sem:iri?]
) as function(item(),item(),item()) as sem:triple

Summary

This function returns a function that builds triples from CURIE and blank node syntax. The resulting function takes three string arguments, representing subject, predicate, and object respectively, which returns a sem:triple object using the graph and prefix mappings passed in to the call to sem:rdf-builder. Blank nodes specified with a leading underscore (_) will be assigned blank node identifiers, and will maintain that identity across multiple invocations; for example, "_:person1" will refer to the same node as a later invocation that also mentions "_:person1". In the predicate position, the special value of "a" will be interpreted as the same as "rdf:type".

Parameters
prefixes An optional set of prefix mappings.
graph The graph value in which to place triples. Defaults to "http://marklogic.com/semantics#default-graph".

Usage Notes

If you pass in a string to sem:rdf-builder, it will be interpreted as a CURIE. If you want it to be interpreted as an IRI, then cast the string to an IRI using sem:iri.

Example

xquery version "1.0-ml"; 
 
import module namespace sem = "http://marklogic.com/semantics" 
      at "/MarkLogic/semantics.xqy";
      
let $fac := sem:rdf-builder()
let $triple := $fac("foaf:person1", "foaf:knows", "foaf:person2")
return <result>{$triple}</result> 
	
=>
<result>
  <sem:triple xmlns:sem="http://marklogic.com/semantics">
     <sem:subject>http://xmlns.com/foaf/0.1/person1</sem:subject>
     <sem:predicate>http://xmlns.com/foaf/0.1/knows</sem:predicate>
     <sem:object>http://xmlns.com/foaf/0.1/person2</sem:object>
  </sem:triple>
</result>
    

Example

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

let $fac := sem:rdf-builder()
let $t1 := $fac("_:person1", "a", "foaf:Person") 
let $t2 := $fac("_:person2", "a", "foaf:Person") 
let $t3 := $fac("_:person1", "foaf:knows", "_:person2") 
return ($t1,$t2,$t3)
 
	
=>
sem:triple(
  sem:blank("http://marklogic.com/semantics/blank/3655782280846814211"),
  sem:iri("http://www.w3.org/1999/02/22-rdf-syntax-ns#type"),
  sem:iri("http://xmlns.com/foaf/0.1/Person"))

sem:triple(
  sem:blank("http://marklogic.com/semantics/blank/1129346327653055324"),
  sem:iri("http://www.w3.org/1999/02/22-rdf-syntax-ns#type"),
  sem:iri("http://xmlns.com/foaf/0.1/Person"))
 
sem:triple(
  sem:blank("http://marklogic.com/semantics/blank/3655782280846814211"),
  sem:iri("http://xmlns.com/foaf/0.1/knows"),
  sem:blank("http://marklogic.com/semantics/blank/1129346327653055324"))
    
Powered by MarkLogic Server | Terms of Use | Privacy Policy