Loading TOC...

MarkLogic 12 EA 1 Product Documentation
sem:graph-insert

sem:graph-insert(
   $graphname as sem:iri,
   $triples as sem:triple*,
   [$permissions as item()*],
   [$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 the graph if necessary. It also creates the graph metadata for the graph specified by the "graphname" option. 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 Permissions to apply to the inserted documents. When run in an XQuery context, the permissions are a sequence of XML elements (sec:permission). When importing this module into a Server-Side JavaScript context, the permissions are an array of Objects.
collections Additional collections to set on inserted documents. If you use the collections argument when inserting triples, no graph document will be created for these collections. When additional collections are set, inserted triples will exist in multiple collections.
quality The quality setting to use for inserted documents.
forest-ids The forest-ids to use when inserting documents.

Usage Notes

Using additional collections with graph-insert in the context of SPARQL Update can result in undefined behavior.

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>
    

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