SPAQRL create exclusion query - sparql

I have this kind of structure
<ontology:Louvre>
<rdf:type ontology:Museum/>
<ontology:preserves rdf:Gioconda/>
<ontology:locatedIn rdf:Paris/>
<ontology:name>Louvre</ontology:name>
<ontology:Gioconda>
<rdf:type ontology:Artwork/>
<ontology:preserved rdf:Louvre/>
<ontology:author rdf:Leonardo/>
<nomeOpera>Gioconda</nomeOpera>
<rdf:Leonardo_Da_Vinci>
<rdf:type ontology:Painter"/>
<ontology:paint ontology:Gioconda"/>
<ontology:paint ontology:Ultima_cena"/>
<name>Leonardo Da Vinci</name>
...(other museum, artist and artwork)
I use "ontology" to indicate my prefix
Is it possible to recover the exclusive artists of a museum?

I found the solution.
This is the query that i'm looking for
SELECT DISTINCT * WHERE {
?museum ontology:preserves ?artwork .
?museum ontology:name "Louvre" .
?artwork ontology:author ?author.
FILTER NOT EXISTS{
?museum2 ontology:preserves ?artwork2 .
?artwork2 ontology:author ?author .
FILTER (?museum2 != ?museum)
}
}

Related

Problems with SPARQL Tutorial - A First SPARQL Query

I'm a starter to the sparql, following the sparql tutorial from https://jena.apache.org/tutorials/sparql_query1.html
I used the sparql query function like this:
caihanzhi#ererererermaodeMacBook-Air bin % sparql --data=/Users/caihanzhi/Desktop/vc-db-1.rdf --query=/Users/caihanzhi/Desktop/q1.rq
and the vc-db-1.rdf is
<rdf:RDF
xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'
xmlns:vCard='http://www.w3.org/2001/vcard-rdf/3.0#'
>
<rdf:Description rdf:about="http://somewhere/JohnSmith">
<vCard:FN>John Smith</vCard:FN>
<vCard:N rdf:parseType="Resource">
<vCard:Family>Smith</vCard:Family>
<vCard:Given>John</vCard:Given>
</vCard:N>
</rdf:Description>
<rdf:Description rdf:about="http://somewhere/RebeccaSmith">
<vCard:FN>Becky Smith</vCard:FN>
<vCard:N rdf:parseType="Resource">
<vCard:Family>Smith</vCard:Family>
<vCard:Given>Rebecca</vCard:Given>
</vCard:N>
</rdf:Description>
<rdf:Description rdf:about="http://somewhere/SarahJones">
<vCard:FN>Sarah Jones</vCard:FN>
<vCard:N rdf:parseType="Resource">
<vCard:Family>Jones</vCard:Family>
<vCard:Given>Sarah</vCard:Given>
</vCard:N>
</rdf:Description>
<rdf:Description rdf:about="http://somewhere/MattJones">
<vCard:FN>Matt Jones</vCard:FN>
<vCard:N
vCard:Family="Jones"
vCard:Given="Matthew"/>
</rdf:Description>
</rdf:RDF>
And the q1.rq is
SELECT ?x
WHERE { ?x <http://www.w3.org/2001/vcard-rdf/3.0#FN> "John Smith" }
But it failed to query. Bash told me that:
Encountered " "{" "{ "" at line 1, column 1.
Was expecting one of:
"\ufeff" ...
"base" ...
"prefix" ...
"select" ...
"describe" ...
"construct" ...
"ask" ...
if anyone knows how to solve it please do not hesitate to provide help!

SPARQL query for three sub-properties does not work

I tried to make a SPARQL query but I failed.
I have three properties which I need to ask for like that:
SELECT DISTINCT ?locality ?museRes ?calendar ?category
FROM <http://opendata.cs.pub.ro/repo/context/TTT>
WHERE {
{
?museRes vCard:locality ?locality FILTER (regex(?museRes, "odaia_bunicii", "i")) .
?museRes vCard:category ?category FILTER (regex(?museRes, "odaia_bunicii", "i")).
?museRes vCard:hasCalendarRequest ?calendar FILTER (regex(?museRes, "odaia_bunicii", "i"))
}
}
in Romanian OpenData SPARQL endpoint
The problem is that three properties are part from another three super-properties (dcterms:spatials, dcterms:description and opendata:MuseumTour) and that approach doesn't work. I tried with OPTION operator but it show me only ?museRes and ?locality values even ?calendar and ?category are not empty.
In the end, I tried to use UNION instead of OPTION, but it works only with one UNION and I need to use two UNION operators.
How may I ask for vCard:locality vCard:category and vCard:hasCalendarRequest in the above RDF?
<rdf:RDF
xmlns:marcrel="http://www.loc.gov/loc.terms/relators/"
xmlns:dcterms="http://purl.org/dc/terms/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:dcmitype="http://purl.org/dc/dcmitype/"
xmlns:opendata="http://opendata.cs.pub.ro/property/"
xmlns:vCard="http://www.w3.org/2006/vcard/ns#"
xmlns:dbPedia="http://dbpedia.org/ontology/"
xmlns:cdtype="http://purl.org/cld/cdtype/"
xmlns:cld="http://purl.org/cld/terms/">
<dbPedia:Museum rdf:about="http://opendata.cs.pub.ro/resource/_Odaia_Bunicii-Centrul_Folcloric_Gradinita_Galicea_Mare_Dolj/">
<dcterms:description>
<rdf:Description rdf:about="http://opendata.cs.pub.ro/resource/_Odaia_Bunicii-Centrul_Folcloric_Gradinita_Galicea_Mare_Dolj/Info/">
<dc:identifier>7172383</dc:identifier>
<opendata:FoundingYear>2016</opendata:FoundingYear>
<dc:title xml:lang="en"></dc:title>
<dcterms:isReferencedBy></dcterms:isReferencedBy>
<marcrel:OWN>
<rdf:Description rdf:about="http://opendata.cs.pub.ro/resource/_Odaia_Bunicii-Centrul_Folcloric_Gradinita_Galicea_Mare_Dolj/Info/Own/">
<dc:identifier></dc:identifier>
<dc:title></dc:title>
</rdf:Description>
</marcrel:OWN>
<opendata:Accreditation></opendata:Accreditation>
<dc:subject>
<rdf:Description rdf:about="http://opendata.cs.pub.ro/resource/_Odaia_Bunicii-Centrul_Folcloric_Gradinita_Galicea_Mare_Dolj/Info/Subject/">
<vCard:value xml:lang="en"></vCard:value>
<vCard:label xml:lang="en">Specific (Principal) profile</vCard:label>
<vCard:label>Profil specific (principal)</vCard:label>
<vCard:value>Etnografie</vCard:value>
<vCard:label>Profil general</vCard:label>
</rdf:Description>
</dc:subject>
<dc:title>"Odaia Bunicii" - Centrul Folcloric Grădiniţa, Galicea Mare</dc:title>
<vCard:hasCategory>
<rdf:Description rdf:about="http://opendata.cs.pub.ro/resource/_Odaia_Bunicii-Centrul_Folcloric_Gradinita_Galicea_Mare_Dolj/Info/Category/">
<opendata:MainCategory xml:lang="en">Museum</opendata:MainCategory>
<opendata:MainCategory>Muzeu</opendata:MainCategory>
<vCard:category xml:lang="en"></vCard:category>
<vCard:category>Muzeu Comunal</vCard:category>
</rdf:Description>
</vCard:hasCategory>
<dcterms:description>
<rdf:Description rdf:about="http://opendata.cs.pub.ro/resource/_Odaia_Bunicii-Centrul_Folcloric_Gradinita_Galicea_Mare_Dolj/Info/Description/">
<opendata:Historic xml:lang="en"></opendata:Historic>
<opendata:Historic></opendata:Historic>
<dcterms:abstract xml:lang="en"></dcterms:abstract>
<dcterms:abstract></dcterms:abstract>
<dcterms:description xml:lang="en"></dcterms:description>
<dcterms:description>Centrul folcloric al grădiniţei Galicea Mare este situat în incinta Grădiniţei nr.1, structură a Şcolii Gimnaziale Galicea Mare, judeţul Dolj, pe drumul european E56. Pentru a readuce la viaţă şi a reînvia atât tradiţiile cât şi portul popular românesc, a luat naştere „Odaia bunicii”, un loc in care obiectele prind viaţă şi creează o atmosferă caldă, plina de dragostea ţaranilor de altadată. Expoziţia permanentă, deschisă în 2016, este concepută într-o manieră tradiţională, fiecare obiect aşteptând să fie folosit pentru a-şi arata maiestria, astfel: patul cu tablii de lemn şi saltea de paie aşteaptă să odihnească omul, măsuţa din lemn şi scaunelele aşteaptă cu nerăbdare să fie servită cina, dar şi războiul ţăranesc unde femeile ţeseau macate ne reamintesc nouă, celor mari, şi îi învaţă pe cei mici despre obiceiurile şi tradiţiile româneşti de altădată.</dcterms:description>
<opendata:Relevance xml:lang="en">Local</opendata:Relevance>
<opendata:Relevance>Locală</opendata:Relevance>
</rdf:Description>
</dcterms:description>
</rdf:Description>
</dcterms:description>
<dbPedia:Building>
<rdf:Description rdf:about="http://opendata.cs.pub.ro/resource/_Odaia_Bunicii-Centrul_Folcloric_Gradinita_Galicea_Mare_Dolj/Building/">
<dbPedia:HistoricBuilding></dbPedia:HistoricBuilding>
<dcterms:abstract xml:lang="en"></dcterms:abstract>
<dcterms:abstract></dcterms:abstract>
<dc:identifier></dc:identifier>
<dc:type xml:lang="en">Building</dc:type>
<dc:type>Cladire</dc:type>
</rdf:Description>
</dbPedia:Building>
<opendata:MuseumTour>
<rdf:Description rdf:about="http://opendata.cs.pub.ro/resource/_Odaia_Bunicii-Centrul_Folcloric_Gradinita_Galicea_Mare_Dolj/Tour/">
<vCard:hasCalendarRequest xml:lang="en">Unspecified</vCard:hasCalendarRequest>
<vCard:hasCalendarRequest>luni-vineri 8:00-13:00</vCard:hasCalendarRequest>
<opendata:VirtualTour></opendata:VirtualTour>
</rdf:Description>
</opendata:MuseumTour>
<opendata:Contact>
<rdf:Description rdf:about="http://opendata.cs.pub.ro/resource/_Odaia_Bunicii-Centrul_Folcloric_Gradinita_Galicea_Mare_Dolj/Contact/">
<vCard:url>
<rdf:Description rdf:about="http://opendata.cs.pub.ro/resource/_Odaia_Bunicii-Centrul_Folcloric_Gradinita_Galicea_Mare_Dolj/Contact/URI/">
<opendata:SocialMediaUri>
<rdf:Description rdf:about="http://opendata.cs.pub.ro/resource/_Odaia_Bunicii-Centrul_Folcloric_Gradinita_Galicea_Mare_Dolj/Contact/URI/SocialMediaUri/">
<vCard:label>Link-uri social media.</vCard:label>
<vCard:hasValue></vCard:hasValue>
</rdf:Description>
</opendata:SocialMediaUri>
<opendata:CimecUri>
<rdf:Description rdf:about="http://opendata.cs.pub.ro/resource/_Odaia_Bunicii-Centrul_Folcloric_Gradinita_Galicea_Mare_Dolj/Contact/URI/CimecUri/">
<vCard:label>Link-ul catre portalul CIMEC.</vCard:label>
<vCard:hasValue>http://ghidulmuzeelor.cimec.ro/id.asp?k=2030&-„Odaia-bunicii”-Centrul-folcloric-Gradinita,-Galicea-Mare-GALICEA-MARE-Dolj</vCard:hasValue>
</rdf:Description>
</opendata:CimecUri>
<opendata:WebUri>
<rdf:Description rdf:about="http://opendata.cs.pub.ro/resource/_Odaia_Bunicii-Centrul_Folcloric_Gradinita_Galicea_Mare_Dolj/Contact/URI/WebUri/">
<vCard:label>Link-ul catre site-ul muzeului.</vCard:label>
<vCard:hasValue></vCard:hasValue>
</rdf:Description>
</opendata:WebUri>
</rdf:Description>
</vCard:url>
<vCard:Individual>
<rdf:Description rdf:about="http://opendata.cs.pub.ro/resource/_Odaia_Bunicii-Centrul_Folcloric_Gradinita_Galicea_Mare_Dolj/Contact/Individual/">
<opendata:Employee>
<rdf:Description rdf:about="http://opendata.cs.pub.ro/resource/_Odaia_Bunicii-Centrul_Folcloric_Gradinita_Galicea_Mare_Dolj/Contact/Individual/Employee/">
<vCard:hasName>Gologan Veronica</vCard:hasName>
<vCard:hasRole>Profesor</vCard:hasRole>
</rdf:Description>
</opendata:Employee>
<opendata:Manager>
<rdf:Description rdf:about="http://opendata.cs.pub.ro/resource/_Odaia_Bunicii-Centrul_Folcloric_Gradinita_Galicea_Mare_Dolj/Contact/Individual/Manager/">
<vCard:hasName>Văduva Cristian</vCard:hasName>
<vCard:hasRole>Director</vCard:hasRole>
</rdf:Description>
</opendata:Manager>
</rdf:Description>
</vCard:Individual>
<vCard:hasEmail></vCard:hasEmail>
<vCard:hasTelephone>
<rdf:Description rdf:about="http://opendata.cs.pub.ro/resource/_Odaia_Bunicii-Centrul_Folcloric_Gradinita_Galicea_Mare_Dolj/Contact/Telephone/">
<vCard:Fax>
<rdf:Description rdf:about="http://opendata.cs.pub.ro/resource/_Odaia_Bunicii-Centrul_Folcloric_Gradinita_Galicea_Mare_Dolj/Contact/Telephone/Fax/">
<vCard:rev></vCard:rev>
<vCard:value></vCard:value>
</rdf:Description>
</vCard:Fax>
<vCard:Work>
<rdf:Description rdf:about="http://opendata.cs.pub.ro/resource/_Odaia_Bunicii-Centrul_Folcloric_Gradinita_Galicea_Mare_Dolj/Contact/Telephone/Work/">
<vCard:rev></vCard:rev>
<vCard:value>0251.316.006; 0762.278.850</vCard:value>
</rdf:Description>
</vCard:Work>
</rdf:Description>
</vCard:hasTelephone>
</rdf:Description>
</opendata:Contact>
<dcterms:spatials>
<rdf:Description rdf:about="http://opendata.cs.pub.ro/resource/_Odaia_Bunicii-Centrul_Folcloric_Gradinita_Galicea_Mare_Dolj/Spatials/">
<vCard:hasAddress>
<rdf:Description rdf:about="http://opendata.cs.pub.ro/resource/_Odaia_Bunicii-Centrul_Folcloric_Gradinita_Galicea_Mare_Dolj/Spatials/Address/">
<vCard:postal-code>207270</vCard:postal-code>
<vCard:region>Dolj</vCard:region>
<dbPedia:AdministrativeRegion>Galicea Mare</dbPedia:AdministrativeRegion>
<vCard:hasLocality>
<rdf:Description rdf:about="http://opendata.cs.pub.ro/resource/_Odaia_Bunicii-Centrul_Folcloric_Gradinita_Galicea_Mare_Dolj/Spatials/Locality/">
<opendata:Siruta></opendata:Siruta>
<vCard:locality>Galicea Mare</vCard:locality>
</rdf:Description>
</vCard:hasLocality>
<vCard:street-address>Str. Calafatului nr. 10</vCard:street-address>
</rdf:Description>
</vCard:hasAddress>
<opendata:Access xml:lang="en"></opendata:Access>
<opendata:Access></opendata:Access>
<vCard:hasGeo>
<rdf:Description rdf:about="http://opendata.cs.pub.ro/resource/_Odaia_Bunicii-Centrul_Folcloric_Gradinita_Galicea_Mare_Dolj/Spatials/GeoPos/">
<vCard:longitude>23.3</vCard:longitude>
<vCard:latitude>44.1</vCard:latitude>
<vCard:label>Localitate</vCard:label>
</rdf:Description>
</vCard:hasGeo>
</rdf:Description>
</dcterms:spatials>
</dbPedia:Museum>
</rdf:RDF>
A better answer...
SELECT DISTINCT ?o ?museum_res ?locality ?calendar ?category ?importanta
FROM <http://opendata.cs.pub.ro/repo/context/TTT>
WHERE {
{
?museum_res ?p ?o.
?e dc:title ?title.
?a vCard:locality ?locality.
?b vCard:category ?category.
?c vCard:hasCalendarRequest ?calendar.
?d openDataP:Relevance ?importanta.
FILTER (
UCASE(?o) = UCASE("http://dbpedia.org/ontology/Museum") &&
contains(?title, "Odaia") &&
contains(?e, ?museum_res) &&
contains(?a, ?museum_res) && langMatches(lang(?locality),"") &&
contains(?b, ?museum_res) && langMatches(lang(?category),"") &&
contains(?c, ?museum_res) && langMatches(lang(?calendar),"") &&
contains(?d, ?museum_res) &&langMatches(lang(?importanta),"")
)
}
}
ORDER BY ?museum_res
LIMIT 1200
After 3-4 hours I found the solution:
SELECT DISTINCT ?locality ?category ?calendar ?importanta
FROM <http://opendata.cs.pub.ro/repo/context/ilie>
WHERE {
?a vCard:locality ?locality. FILTER (regex(?a, "odaia_bunicii", "i")).
?b vCard:category ?category. FILTER (regex(?b, "odaia_bunicii", "i")).
?c vCard:hasCalendarRequest ?calendar. FILTER (regex(?c, "odaia_bunicii", "i")).
?d openDataP:Relevance ?importanta. FILTER (regex(?d, "odaia_bunicii", "i")).
}

Sparql Update query for edit value of a property

i tried to update a value of a query in my DB on marmotta. I have a lot of resources like this:
<rdf:Description rdf:about="http://desktop-pqb3a65:8080/marmotta/resource/7e31bb9e-5dee-4f44-b082-9f770d465ea0">
<hasContentPath xmlns="http://www.kiwi-project.eu/kiwi/core/">D:\Software\Marmotta\marmotta-home\resources\56\cc\73\56cc736b-f597-47e8-9ffc-f37c3dbf66be</hasContentPath>
<about xmlns="http://schema.org/">Fondamenti di Informatica</about>
<name xmlns="http://schema.org/">Hello World!</name>
<author xmlns="http://schema.org/">EduOpen</author>
<audience xmlns="http://schema.org/">Qualsiasi</audience>
<actor xmlns="http://schema.org/">Gianni Vercelli</actor>
<description xmlns="http://schema.org/">Accenni storici sulla nascita del calcolatore</description>
<width xmlns="http://schema.org/"></width>
<height xmlns="http://schema.org/"></height>
<duration xmlns="http://schema.org/"></duration>
</rdf:Description>
I want to edit the hasContentPath field, i have a value like this:
D:\Software\Marmotta\marmotta-home\resources\56\cc\73\56cc736b-f597-47e8-9ffc-f37c3dbf66be
I'd like to edit and insert a value like :
resources\56\cc\73\56cc736b-f597-47e8-9ffc-f37c3dbf66be
Can you help me? i tried this query:
PREFIX schema: <http://schema.org/>
DELETE { ?resource <http://www.kiwi-project.eu/kiwi/core/> 'D:\Software\Marmotta\marmotta-home\resources\56\cc\73\56cc736b-f597-47e8-9ffc-f37c3dbf66be' }
INSERT { ?resource <http://www.kiwi-project.eu/kiwi/core/> 'resources\56\cc\73\56cc736b-f597-47e8-9ffc-f37c3dbf66be' }
WHERE
{ ?resource schema:name 'Hello World!'
}
Single \ in strings are for escape sequences. Unlike the linux shell, '' strings have escapes as well. \S is illegal as an escape — strictly speaking, that's a syntax error. It seems to be interpreted in some way, but it is unlikely to be the characters \ and S.

SPARQL - how to get individual data property from linked individual

I build this ontology in protege. I have this individual ev001 that has these types Room,hasRoom only {rm001} and rm001 has data property roomName "room 1"^^xsd:string.
Right now I have a SPARQL query that returns
Event Room RoomName
ev001 {rm001}
My question is, how to get the room name from there,
here is my query so far
SELECT ?event ?room ?roomname
WHERE { ?x owl:onProperty base:hasRoom .
?event a base:FilmScreening ;
a ?x .
?x owl:allValuesFrom ?room .
}
Any advice is appreciated, thank you very much
In general, it looks like you'd just need:
SELECT ?event ?room ?roomname
WHERE {
?event base:hasRoom ?room .
?room base:roomName ?roomname.
}
You don't need to be retrieving all the axiom stuff with owl:onProperty, etc. However, in your case, the ontology is structured a bit strangely. E.g., you have content like:
<!-- http://www.example.org/ontologies/loncon3#pi00314001 -->
<owl:NamedIndividual rdf:about="http://www.example.org/ontologies/loncon3#pi00314001">
<!-- ... -->
<rdf:type>
<owl:Restriction>
<owl:onProperty rdf:resource="http://www.example.org/ontologies/loncon3#hasRoom"/>
<owl:allValuesFrom>
<owl:Class>
<owl:oneOf rdf:parseType="Collection">
<rdf:Description rdf:about="http://www.example.org/ontologies/loncon3#rm03005"/>
</owl:oneOf>
</owl:Class>
</owl:allValuesFrom>
</owl:Restriction>
</rdf:type>
<!-- ... -->
</owl:NamedIndividual>
In the Manchester syntax, that says that pi00314001 has the type:
hasRoom only { rm03005 }
Based on your question, it sounds like you expect the
pi00314001 hasRoom rm03005
is in your data, or at least inferable from it. Unfortunately, that's not what it actually means. When you say that an individual X has the type
p only D
it means it if X has any value for the property p, then that value must be an instance of D. Similarly, the content in your ontology says that if pi00314001 has a value for the property hasRoom, then that value must be from the class { rm03005 }. It doesn't say that pi00314001 actually has a value for that property, so you don't actually know whether it has rm03005 as a value for hasRoom or not.
If it's under your control, I think you'd want to add some actual object property assertions to your ontology, so that the query I mentioned above will work. Right now your ontology is telling you more about what's possible than what's actually the case.
That said, if you do want to retrieve the room from the data as it's structured now, you can follow the structure of the data and make that work too. It'd be something like:
select ?event ?roomName {
?event a [ owl:onProperty base:hasRoom ;
owl:allValuesFrom/owl:oneOf/rdf:rest*/rdf:first ?room ] .
?room base:roomName ?roomName .
}

Searching semantically tagged documents in MarkLogic

Can any one please point me to some simple examples of semantic tagging and querying semantically tagged documents in MarkLogic?
I am fairly new in this area,so some beginner level examples will do.
When you say "semantically tagged" do you mean regular XML documents that happen to have some triples in them? The discussion and examples at http://docs.marklogic.com/guide/semantics/embedded are pretty good for that.
Start by enabling the triple index in your database. Then insert a test doc. This is just XML, but the sem:triple element represents a semantic fact.
xdmp:document-insert(
'test.xml',
<test>
<source>AP Newswire</source>
<sem:triple date="1972-02-21" confidence="100">
<sem:subject>http://example.org/news/Nixon</sem:subject>
<sem:predicate>http://example.org/wentTo</sem:predicate>
<sem:object>China</sem:object>
</sem:triple>
</test>)
Then query it. The example query is pretty complicated. To understand what's going on I'd insert variations on that sample document, using different URIs instead of just test.xml, and see how the various query terms match up. Try using just the SPARQL component, without the extra cts query. Try cts:search with no SPARQL, just the cts:query.
xquery version "1.0-ml";
import module namespace sem = "http://marklogic.com/semantics"
at "/MarkLogic/semantics.xqy";
sem:sparql('
SELECT ?country
WHERE {
<http://example.org/news/Nixon> <http://example.org/wentTo> ?country
}
',
(),
(),
cts:and-query((
cts:path-range-query( "//sem:triple/#confidence", ">", 80) ,
cts:path-range-query( "//sem:triple/#date", "<", xs:date("1974-01-01")),
cts:or-query((
cts:element-value-query( xs:QName("source"), "AP Newswire"),
cts:element-value-query( xs:QName("source"), "BBC"))))))
In case you are talking about enriching your content using semantic technology, that is not directly provided by MarkLogic.
You can enrich your content externally, for instance by calling a public service like the one provided by OpenCalais, and then insert the enrichments to the content before insert.
You can also build lists of lookup values, and then using cts:highlight to mark such terms within your content. That could be as simple as:
let $labels := ("MarkLogic", "StackOverflow")
return
cts:highlight($doc, cts:word-query($labels), <b>{$cts:text}</b>)
Or with a more dynamic replacement using spraql:
let $labels := map:new()
let $_ :=
for $result in sem:sparql('
PREFIX demo: <http://www.marklogic.com/ontologies/demo#>
SELECT DISTINCT ?label
WHERE {
?s a demo:person.
{
?s demo:fullName ?label
} UNION {
?s demo:initialsName ?label
} UNION {
?s demo:email ?label
}
}
')
return
map:put($labels, map:get($result, 'label'), 'person')
return
cts:highlight($doc, cts:word-query(map:keys($labels)),
let $result := sem:sparql(concat('
PREFIX demo: <http://www.marklogic.com/ontologies/demo#>
SELECT DISTINCT ?s ?p
{
?s a demo:', map:get($labels, $cts:text), ' .
?s ?p "', $cts:text, '" .
}
'))
return
if (map:contains($labels, $cts:text))
then
element { xs:QName(fn:concat("demo:", map:get($labels, $cts:text))) } {
attribute subject { map:get($result, 's') },
attribute predicate { map:get($result, 'p') },
$cts:text
}
else ()
)
HTH!