Search code examples
sparqlbindmarklogic

BIND values from Documents to a SPARQL Variable (MarkLogic)


I am currently trying to see if it's possible to extract a certain value from a document and bind it to a variable in SPARQL

For example if i have such a document in MarkLogic.

/person/John

<person_data>
   <name>John</name>
   <age>25</age>
</person_data>

using this data I attempted various ways to bind it such as using XPath in sem:sparql as shown below

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

sem:sparql('
PREFIX fn : <http://www.w3.org/2005/xpath-functions>
SELECT *
WHERE {
?s ?p ?o .
BIND (fn:doc("/person/John")//name/text() AS ?name)
}
',
(),
(),
()
)

However, this resulted in an error. Hence, I greatly appreciate any advise given on accomplishing this.


Solution

  • The SPARQL engine has no access to documents, but there is a better solution anyhow. You can use Template Driven Extraction for this. It can expose an SQL view on documents, but also 'Identify Triples in Documents'. It effectively means that particular values can be projected into the triple index, and will become accessible as RDF data like any other RDF data in your database.

    HTH!