This page was generated
January  28,  2016
4:04  AM
XQuery & XSLT Built-In & Modules Function Reference

Built-In: Semantics

The rdf functions are built-in functions to construct and use rdf:langString types. The rdf namespace prefix is built into the server.

The semantic functions include functions that are built into MarkLogic Server as well as functions that are implemented in an XQuery library.

To use the semantics XQuery library module as part of your own XQuery module, include the following line in your XQuery prolog:

import module namespace sem = "http://marklogic.com/semantics"
       at "/MarkLogic/semantics.xqy";

The library namespace prefix sem is predefined in the server.

Function Summary
rdf:langString Returns an rdf:langString value with the given value and language tag.
rdf:langString-language Returns the language of an rdf:langString value.
sem:binding Creates a sem:binding object, which is a sub-type of json:object (and map:map).
sem:bnode This function returns an identifier for a blank node, allowing the construction of a triple that refers to a blank node.
sem:coalesce Returns the value of the first argument that evaluates without error.
sem:curie-expand This function expands a CURIE (Compact URI) into a sem:iri object.
sem:curie-shorten This function shortens an IRI into a CURIE (Compact URI) into a sem:iri object.
sem:database-nodes This function returns database nodes backing given triples.
sem:datatype Returns the name of the simple type of the atomic value argument as a SPARQL style IRI.
sem:describe This function implements the Concise Bounded Definition (CBD) specification to describe one or more nodes in the graph.
sem:graph This function returns all triples from a named graph in the database.
sem:graph-delete This function deletes a named graph from the database.
sem:graph-insert This function inserts triples into a named graph, creating it if necessary.
sem:if The IF function form evaluates the first argument, interprets it as a effective boolean value, then returns the value of expression2 if the EBV is true, otherwise it returns the value of expression3.
sem:invalid Returns a sem:invalid value with the given literal value and datatype IRI.
sem:invalid-datatype Returns the datatype IRI of a sem:invalid value.
sem:iri This is a constructor function that takes a string and constructs an item of type sem:iri from it.
sem:isBlank Returns true if the argument is an RDF blank node - that is, derived from type sem:blank.
sem:isIRI Returns true if the argument is an RDF IRI - that is, derived from type sem:iri, but not derived from type sem:blank.
sem:isLiteral Returns true if the argument is an RDF literal - that is, derived from type xs:anyAtomicType, but not derived from type sem:iri.
sem:lang Returns the language of the value passed in, or the empty string if the value has no language.
sem:langMatches Returns true if $lang-tag matches $lang-range according to the basic filtering scheme defined in RFC4647.
sem:prefixes This function returns a set of prefix mappings for use with CURIE processing.
sem:query-results-serialize This function implements the W3C SPARQL Query Results format.
sem:random Returns a random double between 0 and 1.
sem:rdf-builder This function returns a function that builds triples from CURIE and blank node syntax.
sem:rdf-get This function returns sem:triples from a specified location.
sem:rdf-insert This function inserts triples into a specified database as one or more sem:triples documents.
sem:rdf-load This function inserts an RDF document from a specified location into the designated database.
sem:rdf-parse This function returns parsed sem:triple objects from a text format or XML.
sem:rdf-serialize This function returns a string or json or XML serialization of the provided triples.
sem:sameTerm Returns true if the arguments are the same RDF term as defined by the RDF concepts specification.
sem:sparql Executes a SPARQL query against the database.
sem:sparql-triples Executes a SPARQL query against the in-memory triple/quad data provided.
sem:sparql-values This function executes a SPARQL SELECT query using passed-in bindings participating as a starting point for the query.
sem:timezone-string Returns the timezone of an xs:dateTime value as a string.
sem:transitive-closure From a starting set of seeds, follow a given set of predicates, to a given depth, and return all unique node IRIs.
sem:triple Creates a triple object, which represents an RDF triple containing atomic values representing the subject, predicate, object, and optionally graph identifier (graph IRI).
sem:triple-graph Returns the graph identifier (graph IRI) from a sem:triple value.
sem:triple-object Returns the object from a sem:triple value.
sem:triple-predicate Returns the predicate from a sem:triple value.
sem:triple-subject Returns the subject from a sem:triple value.
sem:typed-literal Returns a value to represent the RDF-typed literal with lexical value $value and datatype IRI $datatype.
sem:unknown Returns a sem:unknown value with the given literal value and datatype IRI.
sem:unknown-datatype Returns the datatype IRI of a sem:unknown value.
sem:uuid Return a UUID URN (RFC4122) as a sem:iri value.
sem:uuid-string Return a string that is the scheme specific part of random UUID URN (RFC4122).
Function Detail
rdf:langString(
$string as xs:string,
$lang as xs:string
)  as   rdf:langString
Summary:

Returns an rdf:langString value with the given value and language tag. The rdf:langString type extends xs:string, and represents a language-tagged string in RDF.

Parameters:
$string : The lexical value.
$lang : The language.

Example:
rdf:langString("http://foo/bar", "en")
=> an rdf:langString representing "http://foo/bar" in english


rdf:langString-language(
$val as sem:unknown
)  as   xs:string
Summary:

Returns the language of an rdf:langString value.

Parameters:
$val : The rdf:langString value.

Example:
rdf:langString-language(rdf:langString("http://foo/bar", "en"))
=> en

sem:binding(
[$map as element(json:object)]
)  as   sem:binding
Summary:

Creates a sem:binding object, which is a sub-type of json:object (and map:map).

Parameters:
$map (optional): A serialized sem:binding object.

Example:
  <a>{ sem:binding() }</a>
  => <a>
  <json:object xmlns:json="http://marklogic.com/xdmp/json" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema"/>
</a>

sem:bnode(  ) as  sem:blank
Summary:

This function returns an identifier for a blank node, allowing the construction of a triple that refers to a blank node.

Example:
xquery version "1.0-ml"; 
 
import module namespace sem = "http://marklogic.com/semantics" 
      at "/MarkLogic/semantics.xqy";
    let $person1 := sem:bnode()
let $person2 := sem:bnode()
let $t1 := sem:triple($person1, 
         sem:iri("http://www.w3.org/1999/02/22-rdf-syntax-ns#type"),
	       sem:iri("http://xmlns.com/foaf/0.1/Person"))
let $t2 := sem:triple($person2, 
	       sem:iri("http://www.w3.org/1999/02/22-rdf-syntax-ns#type"),
	       sem:iri("http://xmlns.com/foaf/0.1/Person"))
let $t3 := sem:triple($person1, 
	       sem:iri("http://xmlns.com/foaf/0.1/knows"), $person2) return ($t1,$t2,$t3)
 
 => (: returns identifiers for blank nodes :)
sem:triple(
  sem:blank("http://marklogic.com/semantics/blank/3098376212503391907"),
  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/3280643260770921296"),
  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/3098376212503391907"),
  sem:iri("http://xmlns.com/foaf/0.1/knows"),
  sem:blank("http://marklogic.com/semantics/blank/3280643260770921296"))
    

sem:coalesce(
$parameter1 as item()*,
[$parameterN as item()*,...]
)  as   item()*
Summary:

Returns the value of the first argument that evaluates without error. This XQuery function backs up the SPARQL COALESCE() functional form.

Parameters:
$parameter1 : A value.
$parameterN (optional): A value.

Example:

            

sem:curie-expand(
$curie as xs:string,
[$mapping as map:map]
)  as   sem:iri
Summary:

This function expands a CURIE (Compact URI) into a sem:iri object. This raises SEM-UNKNOWNPREFIX if no mapping is available. For more information about the default prefixes, see sem:prefixes.

Parameters:
$curie : A CURIE string.
$mapping (optional): An optional set of prefix mappings. If not specified, a default set of prefixes is used.

Example:
xquery version "1.0-ml"; 
 
import module namespace sem = "http://marklogic.com/semantics" 
      at "/MarkLogic/semantics.xqy";
    
sem:curie-expand("foaf:person2")
	
=> (: expands and returns the sem:iri object :)
    http://xmlns.com/foaf/0.1/person2
    

sem:curie-shorten(
$iri as sem:iri,
[$mapping as map:map]
)  as   xs:string
Summary:

This function shortens an IRI into a CURIE (Compact URI) into a sem:iri object. Returns the IRI string unchanged if no mapping is available.

Parameters:
$iri : An IRI.
$mapping (optional): An optional set of prefix mappings. If not specified, a default set of prefixes is used.

Example:
xquery version "1.0-ml"; 
 
import module namespace sem = "http://marklogic.com/semantics" 
      at "/MarkLogic/semantics.xqy";
      
sem:curie-shorten(sem:iri("http://xmlns.com/foaf/0.1/person2"))

=>  (: shortens and returns the CURIE (Compact URI) as a string :)
	foaf:person2
    

sem:database-nodes(
$triples as sem:triple*,
[$options as xs:string*],
[$query as cts:query?]
)  as   node()*
Summary:

This function returns database nodes backing given triples. Any given cts:triple may be backed by zero, one, or multiple database nodes.

Parameters:
$triples : The triples to locate.
$options (optional): Matching options. Valid options include:
=
Specify equality matching (following the rules of the $operator argument to cts:triples).
sameTerm
Specify sameTerm matching (following the rules of the $operator argument to cts:triples) (if neither '=' nor 'sameTerm' are specified, this option gets used by default).
all
Specify to return all triple-backing nodes, no matter where or in what format they occur in MarkLogic 7, only sem:triple elements are recognized as triples). If this option is not specified, only sem:triple elements found in documents that have the root element of sem:triples will be returned.
quads
Specify to examine the graph component in the passed in sem:triples and use it to match.
$query (optional): A cts:query to limit the scope of nodes returned.

Example:
xquery version "1.0-ml"; 
 
import module namespace sem = "http://marklogic.com/semantics" 
      at "/MarkLogic/semantics.xqy";
 
(: this function deletes data--use with care :)
sem:database-nodes($triple-list) ! xdmp:node-delete(.)
    

sem:datatype(
$value as xs:anyAtomicType
)  as   sem:iri
Summary:

Returns the name of the simple type of the atomic value argument as a SPARQL style IRI. If the value is derived from sem:unknown or sem:invalid, the datatype IRI part of those values is returned. This XQuery function backs up the SPARQL datatype() function.

Parameters:
$value : The value for which to return the type.

Example:


sem:describe(
$iris as sem:iri*
)  as   sem:triple*
Summary:

This function implements the Concise Bounded Definition (CBD) specification to describe one or more nodes in the graph.

Parameters:
$iris : A set of IRIs representing graph nodes.

Example:
xquery version "1.0-ml"; 
 
import module namespace sem = "http://marklogic.com/semantics" 
      at "/MarkLogic/semantics.xqy";
sem:describe(sem:iri("urn:isbn:9780080540160"))
	
=>
   	sem:triple(sem:iri("urn:isbn:9780080540160"),
	sem:iri("http://purl.org/dc/elements/1.1/title"),
	"Query XML,&#10;XQuery, XPath, and SQL/XML in context")
    

sem:graph(
$graphname as sem:iri
)  as   sem:triple*
Summary:

This function returns all triples from a named graph in the database.

Parameters:
$graphname : The name of the graph to retrieve.

Example:
xquery version "1.0-ml"; 
 
import module namespace sem = "http://marklogic.com/semantics" 
      at "/MarkLogic/semantics.xqy";
 
sem:graph(sem:iri("http://marklogic.com/semantics#default-graph"))
 
 => (: returns all triples from the default graph :)
    
Example:
xquery version "1.0-ml"; 
 
import module namespace sem = "http://marklogic.com/semantics" 
      at "/MarkLogic/semantics.xqy";
    sem:graph(sem:iri("bookgraph"))

 => (: returns all triples from a named graph as triples :)
 
    sem:triple(sem:iri("urn:isbn:006251587X"), 
	sem:iri("http://purl.org/dc/elements/1.1/title"),
	"Weaving the Web", sem:iri("bookgraph"))
 
    sem:triple(sem:iri("urn:isbn:9780080540160"),
    sem:iri("http://purl.org/dc/elements/1.1/title"),
	"Query XML,&#10;XQuery, XPath, and SQL/XML in context", 
	sem:iri("bookgraph"))
    

sem:graph-delete(
$graphname as sem:iri
)  as   empty-sequence()
Summary:

This function deletes a named graph from the database. This is an update function that deletes documents with a root element of sem:triples. All other documents are not affected.

Parameters:
$graphname : The name of the graph to delete.

Example:
xquery version "1.0-ml"; 
 
import module namespace sem = "http://marklogic.com/semantics" 
      at "/MarkLogic/semantics.xqy";
  
sem:graph-delete(sem:iri("bookgraph")) 

sem:graph-insert(
$graphname as sem:iri,
$triples as sem:triple*,
[$permissions as element(sec:permission)*],
[$collections as xs:string*],
[$quality as xs:int?],
[$forest-ids as xs:unsignedLong*]
)  as   xs:string*
Summary:

This function inserts triples into a named graph, creating it if necessary. This is an update function that returns document IDs.

Parameters:
$graphname : The name of the graph to insert triples into.
$triples : The set of triples to insert.
$permissions (optional): Permissions to apply to the inserted documents.
$collections (optional): Additional collections to set on inserted documents. When additional collections are set, inserted triples will exist in multiple graphs.
$quality (optional): The quality setting to use for inserted documents.
$forest-ids (optional): The forest-ids to use when inserting documents.

Example:
xquery version "1.0-ml"; 
 
import module namespace sem = "http://marklogic.com/semantics" 
      at "/MarkLogic/semantics.xqy";
     
sem:graph-insert(sem:iri('bookgraph'), 
   sem:triple(sem:iri('urn:isbn:9780080540160'),
              sem:iri('http://purl.org/dc/elements/1.1/title'), 
              "Query XML,XQuery, XPath, and SQL/XML in context"))
			 
=>
    /triplestore/2c78915c5854b0f8.xml
    
Example:
xquery version "1.0-ml"; 
 
import module namespace sem = "http://marklogic.com/semantics" 
   at "/MarkLogic/semantics.xqy";

 let $string := '
    <urn:isbn:006251587X> <http://purl.org/dc/elements/1.1/creator>
    <http://www.w3.org/People/Berners-Lee/card#i> .
    <urn:isbn:006251587X> <http://purl.org/dc/elements/1.1/title> 
	"Weaving the Web" .
    <http://www.w3.org/People/Berners-Lee/card#i> 
    <http://www.w3.org/2006/vcard/title>"Director" .'

 let $triples := sem:rdf-parse($string, "ntriple")
 let $i := sem:graph-insert(sem:iri("bookgraph"), $triples, (), "smGraph")
 return(fn:collection("smGraph")//sem:triple);
			 
=> (: returns triples as nodes :)
 <sem:triple xmlns:sem="http://marklogic.com/semantics">
   <sem:subject>urn:isbn:006251587X</sem:subject>
   <sem:predicate>http://purl.org/dc/elements/1.1/creator</sem:predicate>
   <sem:object>http://www.w3.org/People/Berners-Lee/card#i</sem:object>
 </sem:triple>
 <sem:triple xmlns:sem="http://marklogic.com/semantics">
   <sem:subject>urn:isbn:006251587X</sem:subject>
   <sem:predicate>http://purl.org/dc/elements/1.1/title</sem:predicate>
   <sem:object datatype="http://www.w3.org/2001/XMLSchema#string">
    Weaving the Web</sem:object>
 </sem:triple>
 <sem:triple xmlns:sem="http://marklogic.com/semantics">
   <sem:subject>http://www.w3.org/People/Berners-Lee/card#i</sem:subject>
   <sem:predicate>http://www.w3.org/2006/vcard/title</sem:predicate>
   <sem:object datatype="http://www.w3.org/2001/XMLSchema#string">
   Director</sem:object>
 </sem:triple>
 <sem:triple xmlns:sem="http://marklogic.com/semantics">
   <sem:subject>urn:isbn:9780080540160</sem:subject>
   <sem:predicate>http://purl.org/dc/elements/1.1/title</sem:predicate>
   <sem:object datatype="http://www.w3.org/2001/XMLSchema#string">
   Query XML,XQuery, XPath, and SQL/XML in context</sem:object>
 </sem:triple>
    

sem:if(
$condition as xs:boolean,
$then as item()*,
$else as item()*
)  as   item()*
Summary:

The IF function form evaluates the first argument, interprets it as a effective boolean value, then returns the value of expression2 if the EBV is true, otherwise it returns the value of expression3. Only one of expression2 and expression3 is evaluated. If evaluating the first argument raises an error, then an error is raised for the evaluation of the IF expression. This XQuery function backs up the SPARQL IF() functional form.

Parameters:
$condition : The condition
$then : The "then" expression.
$else : The "else" expression.

Example:

            

sem:invalid(
$string as xs:string,
$datatype as sem:iri
)  as   sem:invalid
Summary:

Returns a sem:invalid value with the given literal value and datatype IRI. The sem:invalid type extends xs:untypedAtomic, and represents an RDF value whose literal string is invalid according to the schema for its datatype.

Parameters:
$string : The lexical value.
$datatype : The datatype IRI.

Example:

            

sem:invalid-datatype(
$val as sem:invalid
)  as   sem:iri
Summary:

Returns the datatype IRI of a sem:invalid value.

Parameters:
$val : The sem:invalid value.

Example:

            

sem:iri(
$string-iri as xs:string
)  as   sem:iri
Summary:

This is a constructor function that takes a string and constructs an item of type sem:iri from it.

Parameters:
$string-iri : The string with which to construct the sem:iri.

Example:

xquery version "1.0-ml"; 
 
sem:iri("/my/iri")
 
    

sem:isBlank(
$value as xs:anyAtomicType
)  as   xs:boolean
Summary:

Returns true if the argument is an RDF blank node - that is, derived from type sem:blank. This XQuery function backs up the SPARQL isBlank() function.

Parameters:
$value : The value to test.

Example:

            

sem:isIRI(
$value as xs:anyAtomicType
)  as   xs:boolean
Summary:

Returns true if the argument is an RDF IRI - that is, derived from type sem:iri, but not derived from type sem:blank. This XQuery function backs up the SPARQL isIRI() and isURI() functions.

Parameters:
$value : The value to test.

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

let $triple := sem:triple(sem:iri("subject"), sem:iri("predicate"), "object", sem:iri("foo"))

return
  sem:isIRI(sem:triple-subject($triple))

  (: Returns fn:true. :)

sem:isLiteral(
$value as xs:anyAtomicType
)  as   xs:boolean
Summary:

Returns true if the argument is an RDF literal - that is, derived from type xs:anyAtomicType, but not derived from type sem:iri. This XQuery function backs up the SPARQL isLiteral() function.

Parameters:
$value : The value to test.

Example:

            

sem:lang(
$value as xs:anyAtomicType
)  as   xs:string
Summary:

Returns the language of the value passed in, or the empty string if the value has no language. Only values derived from rdf:langString have a language. This XQuery function backs up the SPARQL lang() function.

Parameters:
$value : The value for which to return the language.

Example:

            

sem:langMatches(
$lang-tag as xs:string,
$lang-range as xs:string
)  as   xs:boolean
Summary:

Returns true if $lang-tag matches $lang-range according to the basic filtering scheme defined in RFC4647. This XQuery function backs up the SPARQL langMatches() function.

Parameters:
$lang-tag : The language tag.
$lang-range : The language range.

Example:

            

sem:prefixes(
$prefixdef as xs:string?,
[$include-common as xs:boolean?]
)  as   map:map
Summary:

This function returns a set of prefix mappings for use with CURIE processing. Calling this function returns the internal set of default prefixes. The default mappings include prefixes that are widely used and agreed upon, including "cc" (Creative Commons), "dc" (Dublin Core), "dcterms" (Dublin Core Terms), "foaf" (FOAF), "media" (MediaRSS), "owl" (OWL), "rdf" (RDF), "rdfs" (RDF Schema), "skos" (SKOS), "vcard" (VCard vocab), "void" (Vocabulary of Interlinked Datasets), "xhtml" (XHTML), and "xs" (XML Schema).

Parameters:
$prefixdef : A string specifying prefixes in RDFa @prefix format ("prefix: http://base1 prefix2: http://base2").
$include-common (optional): Whether to include the default set of mappings. Default is true

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

let $prefixes := sem:prefixes("dc: http://purl.org/dc/elements/1.1/ 
	schema: http://schema.org/")
return sem:curie-expand("dc:title")
	
=>  (: returns an IRI :)
    http://purl.org/dc/elements/1.1/title	
    

sem:query-results-serialize(
$results as item()*,
[$options as xs:string*]
)  as   item()*
Summary:

This function implements the W3C SPARQL Query Results format. Any value sequence returned by sem:sparql can be passed into this function. The result will be the W3C SPARQL Results format, in either XML or JSON format.

Parameters:
$results : The results of calling a SPARQL query.
$options (optional): One of 'xml' (default) or 'json'.

Example:
xquery version "1.0-ml"; 
 
import module namespace sem = "http://marklogic.com/semantics" 
      at "/MarkLogic/semantics.xqy";
    
sem:query-results-serialize(sem:sparql('
    PREFIX foaf: <http://xmlns.com/foaf/0.1/>
    SELECT ?name WHERE { ?alum foaf:schoolHomepage <http://www.ucsb.edu/> .
                         ?alum foaf:knows ?person .
                         ?person foaf:name ?name }
'))

=>
  <sparql xmlns="http://www.w3.org/2005/sparql-results#">
    <head>
      <variable name="name">
      </variable>
    </head>
    <results>
      <result>
        <binding name="name">
           <literal datatype="http://www.w3.org/2001/XMLSchema#string">
            Karen Schouten
           </literal>
        </binding>
      </result>
      <result>
        <binding name="name">
           <literal datatype="http://www.w3.org/2001/XMLSchema#string">
           Nick Aster
           </literal>
        </binding>
      </result>
    </results>
  </sparql>
    

sem:random(  ) as  xs:double
Summary:

Returns a random double between 0 and 1. This XQuery function backs up the SPARQL RAND() function.

Example:

            

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 (optional): An optional set of prefix mappings.
$graph (optional): 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"))
    

sem:rdf-get(
$location as xs:string,
[$options as xs:string*],
[$http-opts as element()?]
)  as   sem:triple*
Summary:

This function returns sem:triples from a specified location.

Parameters:
$location : The location of the document.
$options (optional): Parsing options. Valid options include:
base=URI
A base URI to use during parsing.
graph=URI
The graph/context value to give to quads with no explicit graph specified in the data. Cannot be used with override-graph=URI (or an exception is thrown).
override-graph=URI
The graph/context value to give to every quad, whether specified in the data or not. Cannot be used with graph-URI (or an exception is thrown).
ntriple
Specify N-Triples format for input.
nquad
Specify N-Quads format for input (default).
turtle
Specify Turtle format for input.
rdfxml
Specify RDF/XML format for input.
rdfjson
Specify RDF/JSON format for input.
n3
Specify N3 format for input.
trig
Specify TriG format for input.
repair
Specify to repair if possible, or discard individual triples that do not parse correctly. Otherwise any malformed input results in an exception.
triplexml
Specify sem:triple XML format for input, either a single sem:triple element or multiple elements under a root element. If you use the triplexml option, you cannot specify a graph.
$http-opts (optional): An options node as described for the function xdmp:http-get.

Required Privilege:

http://marklogic.com/xdmp/privileges/xdmp-document-get


Example:
xquery version "1.0-ml"; 
 
import module namespace sem = "http://marklogic.com/semantics" 
      at "/MarkLogic/semantics.xqy";
 
sem:rdf-get('C:/Data/Semantics/example.ttl', "turtle")
	
=> 
    sem:triple(sem:iri("http://example.com/ns/data#item342"),
	sem:iri("http://example.com/ns/details#shipped"), xs:date("2013-05-20"))
    
    sem:triple(sem:iri("http://example.com/ns/data#item342"),
	sem:iri("http://example.com/ns/details#quantity"), 4)
    
    sem:triple(sem:iri("http://example.com/ns/data#item342"),
	sem:iri("http://example.com/ns/details#invoiced"), fn:false())
     
    sem:triple(sem:iri("http://example.com/ns/data#item342"),
	sem:iri("http://example.com/ns/details#costPerItem"), 10.5)
    

sem:rdf-insert(
$triples as sem:triple*,
[$options as xs:string*],
[$permissions as element(sec:permission)*],
[$collections as xs:string*],
[$quality as xs:int?],
[$forest-ids as xs:unsignedLong*]
)  as   xs:string*
Summary:

This function inserts triples into a specified database as one or more sem:triples documents. This is an update function that returns the document URIs of inserted documents.

Parameters:
$triples : The triples to insert.
$options (optional): Insertion options. Valid options values include:
override-graph=URI
The graph/context value to give to every quad, whether specified in the data or not.
directory=URI
The database directory path.
$permissions (optional): The set of permissions to use for inserted documents.
$collections (optional): Additional collections to set on inserted documents. When additional collections are set, inserted triples will exist in multiple graphs.
$quality (optional): The quality setting for inserted documents.
$forest-ids (optional): The forest IDs to use for inserted documents.

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

sem:rdf-insert(sem:triple(sem:iri("http://example.com/ns/directory#m"),
	sem:iri("http://example.com/ns/person#firstName"), "Michael"))
 
 =>
   /triplestore/74521a908ece2074.xml
 
    

sem:rdf-load(
$location as xs:string,
[$options as xs:string*],
[$http-opts as element()?],
[$permissions as element(sec:permission)*],
[$collections as xs:string*],
[$quality as xs:int?],
[$forest-ids as xs:unsignedLong*]
)  as   xs:string*
Summary:

This function inserts an RDF document from a specified location into the designated database. This is an update function that returns the document URIs of inserted documents.

Parameters:
$location : The location of the input file. If the file is not a recognized format, an exception is thrown.
$options (optional): Parsing options: Only one base, or graph, or override-graph option along with one format option (ntriple, nquad, turtle, trig, n3, rdfxml, or rdfjson) is allowed. The graph and override-graph options cannot be used together. Valid options include:
base=URI
A base URI to use during parsing.
graph=URI
The graph/context value to give to quads with no explicit graph specified in the data. Cannot be used with override-graph=URI (or an exception is thrown).
override-graph=URI
The graph/context value to give to every quad, whether specified in the data or not. Cannot be used with graph=URI (or an exception is thrown).
directory=URI
The database directory path.
ntriple
Specify N-Triples format for input.
nquad
Specify N-Quads format for input (default).
turtle
Specify Turtle format for input.
rdfxml
Specify RDF/XML format for input.
rdfjson
Specify RDF/JSON format for input.
n3
Specify N3 format for input.
trig
Specify TriG format for input.
repair
Specify to repair if possible, or discard individual triples that do not parse correctly. Otherwise any malformed input results in an exception.
$http-opts (optional): An options node as described for the function xdmp:http-get.
$permissions (optional): Permissions to apply to the inserted documents.
$collections (optional): Additional collections to set on inserted documents. When additional collections are set, inserted triples will exist in multiple graphs.
$quality (optional): The quality setting for inserted documents.
$forest-ids (optional): The forest-ids to use for inserted documents.

Required Privilege:

http://marklogic.com/xdmp/privileges/xdmp-document-get


Example:
xquery version "1.0-ml"; 
 
import module namespace sem = "http://marklogic.com/semantics" 
      at "/MarkLogic/semantics.xqy";
 
sem:rdf-load('C:/data/example.rdf', "rdfxml")
 
 => 
    /triplestore/fbd28af1471b39e9.xml
    
Example:
xquery version "1.0-ml"; 
 
import module namespace sem = "http://marklogic.com/semantics" 
      at "/MarkLogic/semantics.xqy";
	  
sem:rdf-load(
    'C:/data/books.ttl',
    ("turtle", "graph=http://marklogic.com/semantics/sb/books1/"),
    (),
    xdmp:permission("demo-reader", "read")
    )
	
	=>
	  (: permissions on graph for demo-reader now set to "read" :)
	

sem:rdf-parse(
$in as item(),
[$options as xs:string*]
)  as   sem:triple*
Summary:

This function returns parsed sem:triple objects from a text format or XML.

Parameters:
$in : The source to parse. This must either be a string or a node.
$options (optional): Parsing options. Only one each of the base, graph, override-graph, and format (ntriple, nquad, turtle, rdfxml, rdfjson, triplexml) options is allowed. Valid options include:
base=URI
A base URI to use during parsing.
graph=URI
The graph/context value to give to quads with no explicit graph specified in the data. Cannot be used with override-graph=URI (or an exception is thrown).
override-graph=URI
The graph/context value to give to every quad, whether specified in the data or not. Cannot be used with graph=URI (or an exception is thrown).
ntriple
Specify N-Triples format for input.
nquad
Specify N-Quads format for input (default if the $in paramater is a string).
turtle
Specify Turtle format for input.
rdfxml
Specify RDF/XML format for input (default if the $in parameter is an element).
n3
Specify N3 format for input.
trig
Specify TriG format for input.
rdfjson
Specify RDF/JSON format for input.
triplexml
Specify sem:triple XML format for input, either a single sem:triple element or multiple elements under a root element. If you use the triplexml option, you cannot specify a graph.
repair
Specify to repair if possible, or discard individual triples that do not parse correctly. Otherwise any malformed input results in an exception.

Example:
xquery version "1.0-ml"; 
 
import module namespace sem = "http://marklogic.com/semantics" 
      at "/MarkLogic/semantics.xqy";
declare namespace rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#";
declare namespace dc = "http://purl.org/dc/elements/1.1/";
declare namespace v="http://www.w3.org/2006/vcard/";

sem:rdf-parse(
<rdf:Description rdf:about="urn:isbn:006251587X">
  <dc:title>Weaving the Web</dc:title>
  <dc:creator rdf:resource="http://www.w3.org/People/Berners-Lee/card#i"/>
</rdf:Description>,
"rdfxml")	  
 
 => 
sem:triple(
  sem:iri("urn:isbn:006251587X"), 
  sem:iri("http://purl.org/dc/elements/1.1/title"), 
  "Weaving the Web")
	
sem:triple(
  sem:iri("urn:isbn:006251587X"), 
  sem:iri("http://purl.org/dc/elements/1.1/creator"), 
  sem:iri("http://www.w3.org/People/Berners-Lee/card#i"))
    
Example:
xquery version "1.0-ml"; 
 
import module namespace sem = "http://marklogic.com/semantics" 
      at "/MarkLogic/semantics.xqy";
      
let $turtle-document := '
    @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
    @prefix dc: <http://purl.org/dc/elements/1.1/> .
    @prefix ex: <http://example.org/people/1.0/> .
  <http://www.w3.org/TR/rdf-syntax-grammar>
    dc:title "RDF/XML Syntax Specification (Revised)" ;
    ex:editor [
      ex:fullname "Dave Beckett";
      ex:homePage <http://purl.org/net/dajobe/>
    ] .'
return sem:rdf-parse($turtle-document, ("turtle", "repair" )

=>  
sem:triple(
  sem:iri("http://www.w3.org/TR/rdf-syntax-grammar"), 
  sem:iri("http://purl.org/dc/elements/1.1/title"), 
  "RDF/XML Syntax Specification (Revised)")
	
sem:triple(
  sem:iri("http://www.w3.org/TR/rdf-syntax-grammar"), 
  sem:iri("http://example.org/people/1.0/editor"),
  sem:blank("http://marklogic.com/semantics/blank/15118066541381804840"))
	
sem:triple(
  sem:blank("http://marklogic.com/semantics/blank/15118066541381804840"),
  sem:iri("http://example.org/people/1.0/fullname"), 
  "Dave Beckett")

sem:triple(
  sem:blank("http://marklogic.com/semantics/blank/15118066541381804840"),
  sem:iri("http://example.org/people/1.0/homePage"),
  sem:iri("http://purl.org/net/dajobe/"))
    

sem:rdf-serialize(
$triples as sem:triple*,
[$options as xs:string*]
)  as   item()
Summary:

This function returns a string or json or XML serialization of the provided triples.

Parameters:
$triples : The triples to serialize.
$options (optional): Parsing options. Only one of the format options is allowed. Valid option values include:
ntriple
Specify N-Triples format for output as an xs:string.
nquad
Specify N-Quads format for output as an xs:string (default).
turtle
Specify Turtle format for output as an xs:string.
rdfxml
Specify RDF/XML format for output as an element.
rdfjson
Specify JSON format for output as a json:object. Note: To serialize a JSON string, manually call xdmp:to-json on this object.
n3
Specify N3 format for output as an xs:string.
trig
Specify TriG format for output as an xs:string.
triplexml
Specify sem:triple XML format for output, either a single sem:triple element or multiple elements under a root element. If you use the triplexml option, you cannot specify a graph.

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

sem:rdf-serialize(
  (sem:triple(
     sem:iri("http://example.com/ns/directory#m"),
     sem:iri("http://example.com/ns/person#firstName"), "Michelle")))

=> 
    <http://example.com/ns/directory#m> 
	<http://example.com/ns/person#firstName> "Michelle" .
    
Example:
xquery version "1.0-ml"; 
 
import module namespace sem = "http://marklogic.com/semantics" 
      at "/MarkLogic/semantics.xqy";
    sem:rdf-serialize(
    sem:triple(sem:iri("http://example.com/ns/directory#m"),
	sem:iri("http://example.com/ns/person#firstName"),
	"Michelle")), "rdfxml")

=>
    <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
      <rdf:Description rdf:about="http://example.com/ns/directory#m">
        <firstName rdf:datatype="http://www.w3.org/2001/XMLSchema#string" 
        xmlns="http://example.com/ns/person#">Michelle
        </firstName>
      </rdf:Description>
</rdf:RDF>
    

sem:sameTerm(
$a as xs:anyAtomicType,
$b as xs:anyAtomicType
)  as   xs:boolean
Summary:

Returns true if the arguments are the same RDF term as defined by the RDF concepts specification. This XQuery function backs up the SPARQL sameTerm() function.

Parameters:
$a : The first value to test.
$b : The second value to test.

Example:

            

sem:sparql(
$sparql as xs:string,
[$bindings as map:map?],
[$options as xs:string*],
[$query as cts:query?],
[$forest-ids as xs:unsignedLong*]
)  as   item()*
Summary:

Executes a SPARQL query against the database.

SPARQL "SELECT" queries return a sequence of map objects, where each map represents a set of bindings that satisfies the query.

SPARQL "CONSTRUCT" queries return a sequence of sem:triple values.

SPARQL "ASK" queries return a single xs:boolean value.


Parameters:
$sparql : The SPARQL query to be executed.
$bindings (optional): A map containing initial values for variables from the query, or the empty sequence if no query variables are to be initially bound. This is a way to parameterize the query.
$options (optional): Options as a sequence of string values. Available options are:
"base=IRI"
The initial base IRI for the query.
"default-graph=IRI"
Add the named graph specified by the IRI to the default graph for the query.
"named-graph=IRI"
Add the named graph specified by the IRI to the list of named graphs available in the query.
"any"
Values from any fragment should be included.
"document"
Values from document fragments should be included.
"properties"
Values from properties fragments should be included.
"locks"
Values from locks fragments should be included.
"checked"
Word positions should be checked when resolving the query.
"unchecked"
Word positions should not be checked when resolving the query.
"parse-check"
Parse the query, but don't perform static checks or execute it.
"prepare"
Parse and optimize the query, caching the result. No execution is performed.
"optimize=N"
Sets the optimization level to use. Levels of 0 (off), 1, and 2 are recognized, with 1 as the default.
$query (optional): Only include triples in fragments selected by the cts:query. The triples do not need to match the query, but they must occur in fragments selected by the query. The fragments are not filtered to ensure they match the query, but instead selected in the same manner as "unfiltered" cts:search operations. If a string is entered, the string is treated as a cts:word-query of the specified string.
$forest-ids (optional): A sequence of IDs of forests to which the SPARQL query will be constrained. An empty sequence means to search all forests in the database. The default is ().

Required Privilege:

http://marklogic.com/xdmp/privileges/sem-sparql


Usage Notes:

The options parse-check and prepare cannot be used at the same time.


Example:
xquery version "1.0-ml";

import module namespace sem = "http://marklogic.com/semantics" 
  at "/MarkLogic/semantics.xqy";

(: load an rdf triple that will match the SPARQL query :)
  
sem:rdf-insert(
  sem:triple(sem:iri("http://www.example.org/dept/108/invoices/20963"),
	           sem:iri("http://www.example.org/dept/108/invoices/paid"), 
             "true")) ;
(: returns the URI of the document that contains the triple :)

sem:sparql('
PREFIX inv: <http://www.example.org/dept/108/invoices/>

SELECT ?predicate ?object
WHERE 
{ inv:20963 ?predicate ?object }
')
(: returns the matching triple(s) :)
Example:
xquery version "1.0-ml";

(: 
   this query uses the data from the previous query and shows how to
   pass bindings in a parameter to sem:sparql 
:) 
let $params := 
  map:new(map:entry("subject", 
		sem:iri("http://www.example.org/dept/108/invoices/20963")))
return 
sem:sparql("
  SELECT ?predicate ?object
  WHERE
  { ?subject ?predicate ?object } ", 
  $params)
(:  Returns:
 [{"predicate":"<http://www.example.org/dept/108/invoices/paid>",
   "object":"\"true\""}]
:)

sem:sparql-triples(
$sparql as xs:string,
$dataset as sem:triple*,
[$bindings as map:map?],
[$options as xs:string*]
)  as   item()*
Summary:

Executes a SPARQL query against the in-memory triple/quad data provided.

SPARQL "SELECT" queries return a sequence of map objects, where each map represents a set of bindings that satisfies the query.

SPARQL "CONSTRUCT" queries return a sequence of sem:triple values.

SPARQL "ASK" queries return a single xs:boolean value.


Parameters:
$sparql : The SPARQL query to be executed.
$dataset : A set of triple values representing the dataset for the SPARQL query.

The results from a SPARQL construct query or call to sem:rdf-parse() can be used directly as the value for this argument.

$bindings (optional): A map containing initial values for variables from the query, or the empty sequence if no query variables are to be initially bound. This is a way to parameterize the query.
$options (optional): Options as a sequence of string values. Available options are:
"base=IRI"
The initial base IRI for the query.
"default-graph=IRI"
Add the named graph specified by the IRI to the default graph for the query.
"named-graph=IRI"
Add the named graph specified by the IRI to the list of named graphs available in the query.
"parse-check"
Parse the query, but don't perform static checks or execute it.
"prepare"
Parse and optimize the query, but don't actually execute it.
"optimize=N"
Sets the optimization level to use. Levels of 0 (off), 1, and 2 are recognized, with 0 as the default.

Required Privilege:

http://marklogic.com/xdmp/privileges/sem-sparql


Usage Notes:

The options parse-check and prepare cannot be used at the same time.


Example:
xquery version "1.0-ml"; 

import module namespace sem = "http://marklogic.com/semantics" 
  at "/MarkLogic/semantics.xqy";

(:find a match in the SPARQL query in the provided triples:)
sem:sparql-triples('
   PREFIX foaf: <http://xmlns.com/foaf/0.1/>
   SELECT * 
   WHERE { ?p foaf:knows <http://dbpedia.org/resource/person1> .}', 
   (sem:triple(
      sem:iri ("http://dbpedia.org/resource/person3"), 
        sem:iri("http://xmlns.com/foaf/0.1/knows"), 
         sem:iri("http://dbpedia.org/resource/person2")),
     sem:triple(
       sem:iri ("http://dbpedia.org/resource/person2"), 
        sem:iri("http://xmlns.com/foaf/0.1/knows"), 
         sem:iri("http://dbpedia.org/resource/person1")),
     sem:triple(
      sem:iri ("http://dbpedia.org/resource/person4"), 
        sem:iri("http://xmlns.com/foaf/0.1/knows"), 
         sem:iri("http://dbpedia.org/resource/person1"))))
		 
	=> (: returns any matching results as a solution :)
	    <http://dbpedia.org/resource/person2>
        <http://dbpedia.org/resource/person4>

sem:sparql-values(
$sparql as xs:string,
$values as map:map*,
[$options as xs:string*],
[$query as cts:query?],
[$forest-ids as xs:unsignedLong*]
)  as   map:map*
Summary:

This function executes a SPARQL SELECT query using passed-in bindings participating as a starting point for the query.

Parameters:
$sparql : The SPARQL query to be executed. Must be a SELECT query form.
$values : A map containing initial bindings for variables used in the query. Unlike sem:sparql, a sequence of bindings is acceptable and will be processed as the equivalent of an outermost VALUES block in the query.
$options (optional): Query options. Valid options values include:
"base=IRI"
The initial base IRI for the query.
"default-graph=IRI"
Add the named graph specified by the IRI to the default graph for the query.
"named-graph=IRI"
Add the named graph specified by the IRI to the list of named graphs available in the query.
"any"
Values from any fragment should be included.
"document"
Values from document fragments should be included.
"properties"
Values from properties fragments should be included.
"locks"
Values from locks fragments should be included.
"checked"
Word positions should be checked when resolving the query. Default is false.
"unchecked"
Word positions should not be checked when resolving the query. This is the default.
"optimize=N"
Sets the optimization level to use. Levels of 0 (off), 1, and 2 are recognized. Default is 1.
$query (optional): Only include triples in fragments selected by the cts:query. The triples do not need to match the query, but they must occur in fragments selected by the query. The fragments are not filtered to ensure they match the query, but instead selected in the same manner as "unfiltered" cts:search operations.
$forest-ids (optional): A sequence of IDs of forests to which the SPARQL query will be constrained. An empty sequence means to search all forests in the database. The default is ().

Usage Notes:

Only one of "any", "document", "properties", or "locks" may specified in the options parameter. If none of "any", "document", "properties", or "locks" are specified and there is a $query parameter, then the default is "document". If there is no $query then the default is "any".

If $values is an empty sequence, nothing is returned.

A variable can be in both bindings and the VALUES clause.

The binding variable must occur in either the SELECT clause or the triple patterns, otherwise an "Undefined variable" exception is thrown.

The sem:sparql-values function performs a join (SPARQL style, natural join) between the bindings returned from the SELECT expression and the bindings passed in as an argument, therefore the results reflect this join.


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

let $bindings := (
    map:entry("s",
        sem:iri("http://example.net/foaf.rdf#Lenovo_T61")),
    map:entry("s",
        sem:iri("http://example.net/foaf.rdf#Nokia_N80"))
    )
return sem:sparql-values("select * where { ?s ?p ?o }", $bindings)
    

sem:timezone-string(
$value as xs:dateTime
)  as   xs:string
Summary:

Returns the timezone of an xs:dateTime value as a string. This XQuery function backs up the SPARQL TZ() function.

Parameters:
$value : The dateTime value

Example:

            

sem:transitive-closure(
$seeds as sem:iri*,
$predicates as sem:iri*,
$limit as xs:integer
)  as   sem:iri*
Summary:

From a starting set of seeds, follow a given set of predicates, to a given depth, and return all unique node IRIs.

Parameters:
$seeds : A set of seed IRIs.
$predicates : A set of predicates to follow.
$limit : A limit of how many predicates to follow.

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

sem:transitive-closure(
    sem:iri("http://www.w3.org/People/Berners-Lee/card#i"),
    sem:iri("http://xmlns.com/foaf/0.1/knows"),
    9)
    

sem:triple(
$subject_or_node as item(),
[$predicate as xs:anyAtomicType],
[$object as xs:anyAtomicType],
[$graph as sem:iri?]
)  as   sem:triple
Summary:

Creates a triple object, which represents an RDF triple containing atomic values representing the subject, predicate, object, and optionally graph identifier (graph IRI).

Parameters:
$subject_or_node : The triple's subject as an atomic value, or the whole triple as an element. If specifying an element as a triple, this function must be used as a single-parameter version (that is, you cannot specify a triple in this parameter and also use the other parameters).
$predicate (optional): The triple's predicate.
$object (optional): The triple's object.
$graph (optional): The triple's graph IRI. This parameter is only available if you have specified a subject, predicate, and object, and is not available if you have specified an element as a triple in the first parameter.

Usage Notes:

It is possible to create triples with sem:triple that might not be valid RDF triples. For example, you can create a triple with a blank node (sem:bnode()) as a predicate, even though that is not allowed in RDF. This is because the triples you can create with sem:triple are more general that what is allowed in RDF.

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

sem:triple(sem:iri("subject"), sem:iri("predicate"), "object")

(: Returns the specified triple. :)
Example:
xquery version "1.0-ml";
import module namespace sem = "http://marklogic.com/semantics" 
   at "MarkLogic/semantics.xqy";

sem:triple(
<sem:triple xmlns:sem="http://marklogic.com/semantics">
  <sem:subject>subject</sem:subject>
  <sem:predicate>predicate</sem:predicate>
  <sem:object 
   datatype="http://www.w3.org/2001/XMLSchema#string">object</sem:object>
</sem:triple>)    

(: Returns the specified triple. :)
Example:
xquery version "1.0-ml";
import module namespace sem = "http://marklogic.com/semantics" 
   at "MarkLogic/semantics.xqy";

sem:triple(
<foo>{sem:triple(sem:iri("subject"), sem:iri("predicate"), 
      "object")}
</foo>/element())

(: Returns the specified triple. :)

sem:triple-graph(
$triple as sem:triple
)  as   sem:iri?
Summary:

Returns the graph identifier (graph IRI) from a sem:triple value.

Parameters:
$triple : The triple.

Example:

            

sem:triple-object(
$triple as sem:triple
)  as   xs:anyAtomicType
Summary:

Returns the object from a sem:triple value.

Parameters:
$triple : The triple.

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

let $triple := sem:triple(sem:iri("subject"), sem:iri("predicate"), "object")

return
    sem:triple-object($triple)

(: Returns 'object'. :)    

sem:triple-predicate(
$triple as sem:triple
)  as   xs:anyAtomicType
Summary:

Returns the predicate from a sem:triple value.

Parameters:
$triple : The triple.

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

let $triple := sem:triple(sem:iri("subject"), sem:iri("predicate"), "object")

return
    sem:triple-predicate($triple)

(: Returns 'predicate'. :)    

sem:triple-subject(
$triple as sem:triple
)  as   xs:anyAtomicType
Summary:

Returns the subject from a sem:triple value.

Parameters:
$triple : The triple.

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

let $triple := sem:triple(sem:iri("subject"), sem:iri("predicate"), "object")

return
    sem:triple-subject($triple)

    (: Returns 'subject'. :)

sem:typed-literal(
$value as xs:string,
$datatype as sem:iri
)  as   xs:anyAtomicType
Summary:

Returns a value to represent the RDF-typed literal with lexical value $value and datatype IRI $datatype. Returns a value of type sem:unknown for datatype IRIs for which there is no schema, and a value of type sem:invalid for lexical values which are invalid according to the schema for the given datatype. This XQuery function backs up the SPARQL STRDT() function.

Parameters:
$value : The lexical value.
$datatype : The datatype IRI.

Example:

            

sem:unknown(
$string as xs:string,
$datatype as sem:iri
)  as   sem:unknown
Summary:

Returns a sem:unknown value with the given literal value and datatype IRI. The sem:unknown type extends xs:untypedAtomic, and represents an RDF value with a datatype IRI for which no schema is available.

Parameters:
$string : The lexical value.
$datatype : The datatype IRI.

Example:

            

sem:unknown-datatype(
$val as sem:unknown
)  as   sem:iri
Summary:

Returns the datatype IRI of a sem:unknown value.

Parameters:
$val : The sem:unknown value.

Example:

            

sem:uuid(  ) as  sem:iri
Summary:

Return a UUID URN (RFC4122) as a sem:iri value. This XQuery function backs up the SPARQL UUID() function.

Example:

            

sem:uuid-string(  ) as  xs:string
Summary:

Return a string that is the scheme specific part of random UUID URN (RFC4122). This XQuery function backs up the SPARQL STRUUID() function.

Example: