I inserted a test document using the Node.js API:
db.documents.write(
{
uri: "/test/doc1.json",
contentType: "application/json",
collections: "test",
content: {
name : "Peter",
"triple": {
"subject": {
"datatype": "http://example.com/name/",
"value": "Peter"
},
"predicate": {
"datatype": "http://example.com/relation/",
"value": "livesin"
},
"object": {
"datatype": "http://example.com/location/",
"value": "Paris"
}
}
}
}
).
result(function(response){
console.log("Done loading");
});
Then I tried querying it via SPARQL on the Marklogic console webapp:
SELECT ?s ?p ?o
WHERE { ?s ?p ?o }
The query above works fine, it retrieves the test triple I inserted above
However, if I want to filter by the literal value “Paris”, I tried the following:
PREFIX loc: <http://example.com/location/>
SELECT ?s ?p
WHERE { ?s ?p loc:Paris }
But in this case I got zero results. Is this syntax incorrect? I was just following how the queries looked in https://docs.marklogic.com/guide/semantics/semantic-searches
What is the proper way to do it?
You referred to this blog article: http://developer.marklogic.com/blog/managed-vs-unmanaged-triples
Unfortunately it is not showing the best example. A better way of writing a triple would be something like:
By using a
value
property inside subject, predicate and/or object, you tell MarkLogic to read it as a value, not as an iri. So, with your example you should either use:Or change your JSON to:
HTH!