SPARQL query for three sub-properties does not work - sparql

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")).
}

Related

SPAQRL create exclusion query

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)
}
}

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!

How to display specific individual from ontology using sparql query?

Actually I want to display 3 individuals from the same type of class and also their datatype. I have try some code but still it doesn't work. Where it could be wrong?
Here,the code in my jsp file
<%
model=FileManager.get().loadModel("data.rdf");
out.print("<tr><th scope='row'><b>Sarapan Pagi</b></th>");
out.print("<th scope='row'>");
queryString=
"PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax=ns#>"+
"PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>" +
"prefix owl: <http://www.w3.org/2002/07/owl#>" +
"prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>" +
"prefix ab: <http://www.semanticweb.org/user/ontologies/2016/3/untitled-ontology-23#>" +
"SELECT ?x " +
"WHERE{"+
" ?x rdf:type ab:KumpBijirin." +
" FILTER (? x= :BiskutKrimKraker)." +
"}";
query=QueryFactory.create(queryString);
qexec=QueryExecutionFactory.create(query,model);
try{
ResultSet results=qexec.execSelect();
while (results.hasNext()){
QuerySolution soln=results.nextSolution();
Literal name=soln.getLiteral("x");
out.print(name);
}
}finally{
qexec.close();
}out.print("</th></tr>"); %>
This is some of my data.rdf file.
<owl:NamedIndividual rdf:about="http://www.semanticweb.org/user/ontologies/2016/3/untitled-ontology-23#AcarTimun">
<rdf:type rdf:resource="http://www.semanticweb.org/user/ontologies/2016/3/untitled-ontology-23#JenisMakanMalam"/>
<rdf:type rdf:resource="http://www.semanticweb.org/user/ontologies/2016/3/untitled-ontology-23#JenisMakanTengahHari"/>
<rdf:type rdf:resource="http://www.semanticweb.org/user/ontologies/2016/3/untitled-ontology-23#KumpSayur"/>
<rdf:type rdf:resource="http://www.semanticweb.org/user/ontologies/2016/3/untitled-ontology-23#MenuHidanganSampingan"/>
<hasKalori rdf:datatype="http://www.w3.org/2001/XMLSchema#float">33.3</hasKalori>
<hasKarbohidrat rdf:datatype="http://www.w3.org/2001/XMLSchema#float">7.7</hasKarbohidrat>
<hasLemak rdf:datatype="http://www.w3.org/2001/XMLSchema#float">0.2</hasLemak>
<hasProtein rdf:datatype="http://www.w3.org/2001/XMLSchema#float">0.7</hasProtein>
<hasSaizHidangan rdf:datatype="http://www.w3.org/2001/XMLSchema#int">1hidangan</hasSaizHidangan>
</owl:NamedIndividual>
<!-- http://www.semanticweb.org/user/ontologies/2016/3/untitled-ontology-23#AirKosong -->
<owl:NamedIndividual rdf:about="http://www.semanticweb.org/user/ontologies/2016/3/untitled-ontology-23#AirKosong">
<rdf:type rdf:resource="http://www.semanticweb.org/user/ontologies/2016/3/untitled-ontology-23#JenisMakanMalam"/>
<rdf:type rdf:resource="http://www.semanticweb.org/user/ontologies/2016/3/untitled-ontology-23#JenisMakanTengahHari"/>
<rdf:type rdf:resource="http://www.semanticweb.org/user/ontologies/2016/3/untitled-ontology-23#JenisMinumMalam"/>
<rdf:type rdf:resource="http://www.semanticweb.org/user/ontologies/2016/3/untitled-ontology-23#JenisMinumPagi"/>
<rdf:type rdf:resource="http://www.semanticweb.org/user/ontologies/2016/3/untitled-ontology-23#MenuMinuman"/>
<hasKalori rdf:datatype="http://www.w3.org/2001/XMLSchema#float">0.0</hasKalori>
<hasKarbohidrat rdf:datatype="http://www.w3.org/2001/XMLSchema#float">0.0</hasKarbohidrat>
<hasLemak rdf:datatype="http://www.w3.org/2001/XMLSchema#float">0.0</hasLemak>
<hasProtein rdf:datatype="http://www.w3.org/2001/XMLSchema#float">0.0</hasProtein>
<hasSaizHidangan rdf:datatype="http://www.w3.org/2001/XMLSchema#float">1gelas</hasSaizHidangan>
</owl:NamedIndividual>
<!-- http://www.semanticweb.org/user/ontologies/2016/3/untitled-ontology-23#Anggur -->
<owl:NamedIndividual rdf:about="http://www.semanticweb.org/user/ontologies/2016/3/untitled-ontology-23#Anggur">
<rdf:type rdf:resource="http://www.semanticweb.org/user/ontologies/2016/3/untitled-ontology-23#JenisMakanMalam"/>
<rdf:type rdf:resource="http://www.semanticweb.org/user/ontologies/2016/3/untitled-ontology-23#JenisMakanTengahHari"/>
<rdf:type rdf:resource="http://www.semanticweb.org/user/ontologies/2016/3/untitled-ontology-23#KumpBuah"/>
<rdf:type rdf:resource="http://www.semanticweb.org/user/ontologies/2016/3/untitled-ontology-23#MenuPencuciMulut"/>
<hasKalori rdf:datatype="http://www.w3.org/2001/XMLSchema#float">63.2</hasKalori>
<hasKarbohidrat rdf:datatype="http://www.w3.org/2001/XMLSchema#float">15.0</hasKarbohidrat>
<hasLemak rdf:datatype="http://www.w3.org/2001/XMLSchema#float">0.0</hasLemak>
<hasProtein rdf:datatype="http://www.w3.org/2001/XMLSchema#float">0.8</hasProtein>
<hasSaizHidangan rdf:datatype="http://www.w3.org/2001/XMLSchema#int">8biji</hasSaizHidangan>
</owl:NamedIndividual>
<!-- http://www.semanticweb.org/user/ontologies/2016/3/untitled-ontology-23#AsamLaksaPenang -->
<owl:NamedIndividual rdf:about="http://www.semanticweb.org/user/ontologies/2016/3/untitled-ontology-23#AsamLaksaPenang">
<rdf:type rdf:resource="http://www.semanticweb.org/user/ontologies/2016/3/untitled-ontology-23#JenisMakanMalam"/>
<rdf:type rdf:resource="http://www.semanticweb.org/user/ontologies/2016/3/untitled-ontology-23#JenisMakanTengahHari"/>
<rdf:type rdf:resource="http://www.semanticweb.org/user/ontologies/2016/3/untitled-ontology-23#KumpBijirin"/>
<rdf:type rdf:resource="http://www.semanticweb.org/user/ontologies/2016/3/untitled-ontology-23#MenuHidanganUtama"/>
<hasKalori rdf:datatype="http://www.w3.org/2001/XMLSchema#float">432.0</hasKalori>
<hasKarbohidrat rdf:datatype="http://www.w3.org/2001/XMLSchema#float">53.0</hasKarbohidrat>
<hasLemak rdf:datatype="http://www.w3.org/2001/XMLSchema#float">2.0</hasLemak>
<hasProtein rdf:datatype="http://www.w3.org/2001/XMLSchema#float">21.1</hasProtein>
<hasSaizHidangan rdf:datatype="http://www.w3.org/2001/XMLSchema#int">1mangkuk</hasSaizHidangan>
</owl:NamedIndividual>

How to list all elements of the selected enumerations with the use of SPARQL?

The following is a subquestion to my previous question: available here.
How to modify the following SPARQL query:
prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
prefix owl: <http://www.w3.org/2002/07/owl#>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
select ?dt ?element ?elementType {
?dt a rdfs:Datatype ;
owl:oneOf/rdf:rest*/rdf:first ?element .
bind(datatype(?element) as ?elementType)
}
in order to to get a result of only A and C? I would like to obtain { "a1" "a2" "c1" "c2" }. The above query returns all enumeration values from the ontology, I mean: { "a1" "a2" "b1" "b2" "c1" "c2" }
We are given the ontology (A and B are equivalent but presented in different style syntax):
Variant A) in the functional style syntax:
Prefix(ont:=<http://www/ont.owl#>)
Prefix(owl:=<http://www.w3.org/2002/07/owl#>)
Prefix(rdf:=<http://www.w3.org/1999/02/22-rdf-syntax-ns#>)
Prefix(xsd:=<http://www.w3.org/2001/XMLSchema#>)
Prefix(rdfs:=<http://www.w3.org/2000/01/rdf-schema#>)
Ontology(<http://www/ont.owl>
DatatypeDefinition( ont:A DataOneOf( "a1" "a2" ) )
DatatypeDefinition( ont:B DataOneOf( "b1" "b2" ) )
DatatypeDefinition( ont:C DataOneOf( "c1" "c2" ) )
)
Variant B) in the RDF/XML style syntax:
<?xml version="1.0"?>
<!DOCTYPE rdf:RDF [
<!ENTITY ont "http://www/ont.owl#" >
<!ENTITY owl "http://www.w3.org/2002/07/owl#" >
<!ENTITY xsd "http://www.w3.org/2001/XMLSchema#" >
<!ENTITY xml "http://www.w3.org/XML/1998/namespace" >
<!ENTITY rdfs "http://www.w3.org/2000/01/rdf-schema#" >
<!ENTITY rdf "http://www.w3.org/1999/02/22-rdf-syntax-ns#" >
]>
<rdf:RDF xmlns="http://www/ont.owl#"
xml:base="http://www/ont.owl"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
xmlns:ont="http://www/ont.owl#"
xmlns:owl="http://www.w3.org/2002/07/owl#"
xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:xml="http://www.w3.org/XML/1998/namespace">
<owl:Ontology rdf:about="http://www/ont.owl"/>
<!--
///////////////////////////////////////////////////////////////////////////////////////
//
// Datatypes
//
///////////////////////////////////////////////////////////////////////////////////////
-->
<!-- http://www/ont.owl#A -->
<rdfs:Datatype rdf:about="&ont;A">
<owl:equivalentClass>
<rdfs:Datatype>
<owl:oneOf>
<rdf:Description>
<rdf:type rdf:resource="&rdf;List"/>
<rdf:first>a1</rdf:first>
<rdf:rest>
<rdf:Description>
<rdf:type rdf:resource="&rdf;List"/>
<rdf:first>a2</rdf:first>
<rdf:rest rdf:resource="&rdf;nil"/>
</rdf:Description>
</rdf:rest>
</rdf:Description>
</owl:oneOf>
</rdfs:Datatype>
</owl:equivalentClass>
</rdfs:Datatype>
<!-- http://www/ont.owl#B -->
<rdfs:Datatype rdf:about="&ont;B">
<owl:equivalentClass>
<rdfs:Datatype>
<owl:oneOf>
<rdf:Description>
<rdf:type rdf:resource="&rdf;List"/>
<rdf:first>b1</rdf:first>
<rdf:rest>
<rdf:Description>
<rdf:type rdf:resource="&rdf;List"/>
<rdf:first>b2</rdf:first>
<rdf:rest rdf:resource="&rdf;nil"/>
</rdf:Description>
</rdf:rest>
</rdf:Description>
</owl:oneOf>
</rdfs:Datatype>
</owl:equivalentClass>
</rdfs:Datatype>
<!-- http://www/ont.owl#C -->
<rdfs:Datatype rdf:about="&ont;C">
<owl:equivalentClass>
<rdfs:Datatype>
<owl:oneOf>
<rdf:Description>
<rdf:type rdf:resource="&rdf;List"/>
<rdf:first>c1</rdf:first>
<rdf:rest>
<rdf:Description>
<rdf:type rdf:resource="&rdf;List"/>
<rdf:first>c2</rdf:first>
<rdf:rest rdf:resource="&rdf;nil"/>
</rdf:Description>
</rdf:rest>
</rdf:Description>
</owl:oneOf>
</rdfs:Datatype>
</owl:equivalentClass>
</rdfs:Datatype>
</rdf:RDF>
<!-- Generated by the OWL API (version 3.4.2) http://owlapi.sourceforge.net -->
As I said in the comments on the previous answer:
#Annabelle I was basing the retrieval methods on the ontology that I provided. There are certainly other ways to select the data types if they're identified by IRIs. In your case, it looks like it would be values ?dt {:A :B } if you only want ?dt to be A or B.
and
In this case, note that the axiom is encoded by saying that :A is owl:equivalentClass to the datatype class expression. That's the extra link you need between the class IRI and the expression.
That gives us:
select ?dt ?element ?elementType {
values ?dt { ont:A ont:B }
?dt owl:equivalentClass/a rdfs:Datatype ;
owl:oneOf/rdf:rest*/rdf:first ?element .
bind(datatype(?element) as ?elementType)
}
This really isn't much different from the previous answer. You just need to add on the specific values that you're looking for, and then add the equivalentClass link.

in owl "Dl query" how to use advanced valu query in protege

I am developing an ontology and I have a problem with my Dl query
there is a class called "flower"
and this class has subclasses which are some flowers names
and also there is another class called "flowersColor"
and it has these values ("red","green" and "blue") as individuals-not subclass-
every flower has one color or more
I want to search for a flower that has red color and only red
my DL Query is :
"flower and hasColor value red"
this query will give me all flowers that has the color red even if it has other colors
however I want all flowers that has ONLY the color red
I want to write something like this
"flower and hasColor only value red" <- this is not correct grammatically
I main if the color has a combination of "red" and "green" then I don't want to see it in my result
I hope you can help me in my query
Thanks
Remember that OWL uses the open world assumption, so you are somewhat limited in what can be inferred via description logic.
So your "query", as Kaarel mentions, could be:
flower and (hasColor only {red})
Yet this is unprovable in the open world assumption. There could be statement, somewhere in the universe, which asserts:
<RedRose> :hasColor :StackOverflow .
Which, when combined with your assertions (which you're trying to query):
<RedRose> :hasColor :Red .
<RedRose> a :Flower .
Will cause the DL query to return no results. So due to the open world assumption, and the theoretical existence of wild, inaccurate, and irrelevant assertions (at least from your perspective), the DL query will fail, since it can only infer statements it can prove are true.
However, your example query can be used in an OWL restriction to determine if something is not something else. As an example, if you have a class (:OnlyRedFlower) which must only have the color red, but it has the color blue (you've asserted this additional color), then you can infer that this new flower is not in the set of :OnlyRedFlower.
Update: For those that are interested in trying this themselves, here's the ontology I created based on this question:
<?xml version="1.0"?>
<!DOCTYPE rdf:RDF [
<!ENTITY owl "http://www.w3.org/2002/07/owl#" >
<!ENTITY xsd "http://www.w3.org/2001/XMLSchema#" >
<!ENTITY owl2xml "http://www.w3.org/2006/12/owl2-xml#" >
<!ENTITY rdfs "http://www.w3.org/2000/01/rdf-schema#" >
<!ENTITY rdf "http://www.w3.org/1999/02/22-rdf-syntax-ns#" >
<!ENTITY onto "http://www.elastra.com/onto/2009/5/30/onto.owl#" >
]>
<rdf:RDF xmlns="http://stackoverflow.com/users/64881/ontology_842588.rdf#"
xml:base="http://stackoverflow.com/users/64881/ontology_842588.rdf"
xmlns:owl2xml="http://www.w3.org/2006/12/owl2-xml#"
xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:owl="http://www.w3.org/2002/07/owl#"
xmlns:onto="http://www.elastra.com/onto/2009/5/30/onto.owl#">
<owl:Ontology rdf:about="">
<rdfs:comment xml:lang="en"
>Example for http://stackoverflow.com/questions/842588/in-owl-dl-query-how-to-use-advanced-valu-query-in-protege</rdfs:comment>
</owl:Ontology>
<owl:ObjectProperty rdf:about="&onto;hasColor"/>
<owl:Class rdf:about="&onto;Color"/>
<owl:Class rdf:about="&onto;ExampleFlower">
<rdfs:subClassOf rdf:resource="&onto;Flower"/>
</owl:Class>
<owl:Class rdf:about="&onto;Flower"/>
<owl:Class rdf:about="&onto;OnlyRedFlower">
<owl:equivalentClass>
<owl:Class>
<owl:intersectionOf rdf:parseType="Collection">
<rdf:Description rdf:about="&onto;Flower"/>
<owl:Restriction>
<owl:onProperty rdf:resource="&onto;hasColor"/>
<owl:allValuesFrom>
<owl:Class>
<owl:oneOf rdf:parseType="Collection">
<rdf:Description rdf:about="&onto;Red"/>
</owl:oneOf>
</owl:Class>
</owl:allValuesFrom>
</owl:Restriction>
</owl:intersectionOf>
</owl:Class>
</owl:equivalentClass>
<rdfs:subClassOf rdf:resource="&onto;Flower"/>
</owl:Class>
<owl:Class rdf:about="&onto;OtherFlower">
<rdfs:subClassOf rdf:resource="&onto;Flower"/>
</owl:Class>
<onto:Color rdf:about="&onto;Blue">
<rdf:type rdf:resource="&owl;Thing"/>
</onto:Color>
<onto:Flower rdf:about="&onto;BlueOrchid">
<rdf:type rdf:resource="&owl;Thing"/>
<onto:hasColor rdf:resource="&onto;Blue"/>
</onto:Flower>
<onto:Color rdf:about="&onto;Red">
<rdf:type rdf:resource="&owl;Thing"/>
</onto:Color>
<onto:Flower rdf:about="&onto;RedRose">
<rdf:type rdf:resource="&owl;Thing"/>
<onto:hasColor rdf:resource="&onto;Red"/>
</onto:Flower>
</rdf:RDF>
The query that you are after is:
flower and (hasColor only {red})
Note that the {.} constructor creates a class from an individual, or a list of individuals. So you can use it everywhere where a class is syntactically required, e.g.
(not {blue}) subClassOf
{red} and {green,blue} or (hasColor max 10 ({red} or {blue}))