Loading TOC...

MarkLogic 12 EA 2 Product Documentation
sem:rdf-parse

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 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/"))
    

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