MarkLogic 12 EA 1 Product Documentation
sem.rdfParse

sem.rdfParse(
   in as Item,
   [options as String[]]
) as Sequence

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

const sem = require("/MarkLogic/semantics.xqy");

sem.rdfParse(fn.head(xdmp.unquote(
'<rdf:Description rdf:about="urn:isbn:006251587X" \n\
	xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" \n\
        xmlns:dc="http://purl.org/dc/elements/1.1/" \n\
        xmlns:v="http://www.w3.org/2006/vcard/">\n\
  <dc:title>Weaving the Web</dc:title>\n\
  <dc:creator rdf:resource="http://www.w3.org/People/Berners-Lee/card#i"/>\n\
</rdf:Description>')).root,
"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

const sem = require("/MarkLogic/semantics.xqy");
      
const turtleDocument = '\n\
    @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .\n\
    @prefix dc: <http://purl.org/dc/elements/1.1/> .\n\
    @prefix ex: <http://example.org/people/1.0/> .\n\
  <http://www.w3.org/TR/rdf-syntax-grammar>\n\
    dc:title "RDF/XML Syntax Specification (Revised)" ;\n\
    ex:editor [\n\
      ex:fullname "Dave Beckett";\n\
      ex:homePage <http://purl.org/net/dajobe/>\n\
    ] .'
sem.rdfParse(turtleDocument, ["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/"))
    
Powered by MarkLogic Server | Terms of Use | Privacy Policy