<?xml version="1.0"?>
<rdf:RDF xmlns="http://localhost/mydata#"
xml:base="http://localhost/mydata"
xmlns:g="http://localhost/mydata/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:owl="http://www.w3.org/2002/07/owl#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:xml="http://www.w3.org/XML/1998/namespace"
xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#">
<owl:Ontology rdf:about="http://localhost/mydata">
<owl:imports rdf:resource="http://www.owl-ontologies.com/travel.owl"/>
<owl:imports rdf:resource="http://www.w3.org/1999/02/22-rdf-syntax-ns#"/>
</owl:Ontology>
</rdf:RDF>
I have my RDF in the above format. I wish to query the data in the resource http://www.owl-ontologies.com/travel.owl as well. How can I do it? I get the URI value using the below query but shall be done next?
prefix ab:<http://www.owl-ontologies.com/travel.owl#>
prefix rdfs:<https://www.w3.org/2000/01/rdf-schema#>
prefix rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
prefix owl:<http://www.w3.org/2002/07/owl#>
SELECT ?y
WHERE { ?x owl:imports ?y.
?
}
Related
For context I am using GraphDB (SPARQL 1.1), and I have extended the What To Make ontology. I'd like to construct a query that can select ONLY the subjects that contain all of the objects with matching values for a particular predicate.
In my data (below) selecting the individual &so;KitchenDrawer's so:contains predicates and matching those against only those '&wtm;Recipe''s that contain just the values for wtm:hasIngredient. The subject and predicate are the same but there are alternating objects.
When I run the query (with &so;KitchenDrawer only containing &ind;Basil and &ind;Tomato), I would like to only get the subject's &ind;JustTomatoAndBasil and &ind;JustTomato, omitting &ind;Pesto as it has ingredients other than basil and tomato.
RDF Data:
<?xml version="1.0"?>
<!DOCTYPE rdf:RDF [
<!ENTITY rdf "http://www.w3.org/1999/02/22-rdf-syntax-ns#" >
<!ENTITY rdfs "http://www.w3.org/2000/01/rdf-schema#" >
<!ENTITY owl "http://www.w3.org/2002/07/owl#" >
<!ENTITY xsd "http://www.w3.org/2001/XMLSchema#" >
<!ENTITY dct "http://purl.org/dc/terms/" >
<!ENTITY obo "http://purl.obolibrary.org/obo/" >
<!ENTITY skos "http://www.w3.org/2004/02/skos/core#" >
<!ENTITY wtm "http://purl.org/heals/food/" >
<!ENTITY ind "http://purl.org/heals/ingredient/" >
<!ENTITY prov "http://www.w3.org/ns/prov#">
<!ENTITY sm "http://www.omg.org/techprocess/ab/SpecificationMetadata/">
<!ENTITY so "http://example.com/storage-ontology/">
]>
<rdf:RDF xml:base="http://purl.org/heals/ingredient/"
xmlns:so="http://example.com/storage-ontology/"
xmlns:wtm="http://purl.org/heals/food/"
xmlns:dct="http://purl.org/dc/terms/"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:owl="http://www.w3.org/2002/07/owl#"
xmlns:xml="http://www.w3.org/XML/1998/namespace"
xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
xmlns:skos="http://www.w3.org/2004/02/skos/core#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
xmlns:obo="http://purl.obolibrary.org/obo/"
xmlns:prov="http://www.w3.org/ns/prov#"
xmlns:ind="http://purl.org/heals/ingredient/"
xmlns:sm="https://www.omg.org/techprocess/ab/SpecificationMetadata/">
<owl:Ontology rdf:about="http://purl.org/heals/ingredient/">
<owl:imports rdf:resource="http://purl.org/heals/food/"/>
<owl:imports rdf:resource="http://www.omg.org/techprocess/ab/SpecificationMetadata/"/>
<rdfs:label>What to Make Individuals Extensions</rdfs:label>
<dct:license rdf:datatype="&xsd;anyURI">http://opensource.org/licenses/MIT</dct:license>
</owl:Ontology>
<owl:NamedIndividual rdf:about="&ind;JustTomato">
<rdf:type rdf:resource="&wtm;Recipe"/>
<wtm:hasIngredient rdf:resource="&ind;Tomato"/>
<wtm:isRecommendedForMeal rdf:resource="&wtm;Lunch"/>
<wtm:isRecommendedForMeal rdf:resource="&wtm;Dinner"/>
<wtm:isRecommendedForMeal rdf:resource="&wtm;Snack"/>
<skos:scopeNote>recipe</skos:scopeNote>
</owl:NamedIndividual>
<owl:NamedIndividual rdf:about="&ind;JustTomatoAndBasil">
<rdf:type rdf:resource="&wtm;Recipe"/>
<wtm:hasIngredient rdf:resource="&ind;Tomato"/>
<wtm:hasIngredient rdf:resource="&ind;Basil"/>
<wtm:isRecommendedForMeal rdf:resource="&wtm;Lunch"/>
<wtm:isRecommendedForMeal rdf:resource="&wtm;Dinner"/>
<wtm:isRecommendedForMeal rdf:resource="&wtm;Snack"/>
<skos:scopeNote>recipe</skos:scopeNote>
</owl:NamedIndividual>
<owl:NamedIndividual rdf:about="&ind;Pesto">
<rdf:type rdf:resource="&wtm;Recipe"/>
<wtm:hasIngredient rdf:resource="&ind;Basil"/>
<wtm:hasIngredient rdf:resource="&ind;PineNuts"/>
<wtm:hasIngredient rdf:resource="&ind;Parmesan"/>
<wtm:hasIngredient rdf:resource="&ind;Garlic"/>
<wtm:hasIngredient rdf:resource="&ind;OliveOil"/>
<wtm:isRecommendedForMeal rdf:resource="&wtm;Lunch"/>
<wtm:isRecommendedForMeal rdf:resource="&wtm;Dinner"/>
<wtm:isRecommendedForMeal rdf:resource="&wtm;Snack"/>
<wtm:serves rdf:datatype="&xsd;integer">4</wtm:serves>
<rdfs:label>basil pesto</rdfs:label>
<skos:definition>a traditional pesto made from paresan cheese and basil</skos:definition>
<skos:scopeNote>recipe</skos:scopeNote>
</owl:NamedIndividual>
<owl:Class rdf:about="&so;StorageLocation">
</owl:Class>
<owl:Class rdf:about="&so;Drawer">
<rdfs:subClassOf rdf:resource="&so;StorageLocation"/>
</owl:Class>
<owl:ObjectProperty rdf:about="&so;contains">
</owl:ObjectProperty>
<owl:NamedIndividual rdf:about="&so;KitchenDrawer">
<rdf:type rdf:resource="&so;Rack"/>
<so:contains rdf:resource="&ind;Basil"></so:contains>
<so:contains rdf:resource="&ind;Tomato"></so:contains>
</owl:NamedIndividual>
</rdf:RDF>
I have an ontology that I am trying to qrite SPARQL queries for.
I'm using the Ontology IRI (http://www.semanticweb.org/chris/ontologies/2020/2/dis-coursework-ontology) displayed on the Active ontology tab to define the PREFIX value in the query below:
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#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX chris: <http://www.semanticweb.org/chris/ontologies/2020/2/dis-coursework-ontology#>
SELECT ?class ?activity
WHERE { ?class chris:hasActivity ?activity }
When I run this nothing is returned, yet when I output the ontology into RDF format I can see instances if what I want to be returned:
<owl:Class rdf:about="http://www.semanticweb.org/chris/ontologies/2020/2/dis-coursework-ontology#SportsHallBooking">
<rdfs:subClassOf rdf:resource="http://www.semanticweb.org/chris/ontologies/2020/2/dis-coursework-ontology#BookableTimetable"/>
<rdfs:subClassOf>
<owl:Restriction>
<owl:onProperty rdf:resource="http://www.semanticweb.org/chris/ontologies/2020/2/dis-coursework-ontology#hasActivity"/>
<owl:someValuesFrom rdf:resource="http://www.semanticweb.org/chris/ontologies/2020/2/dis-coursework-ontology#Badminton"/>
</owl:Restriction>
</rdfs:subClassOf>
<rdfs:subClassOf>
</rdfs:subClassOf>
<rdfs:subClassOf>
<owl:Restriction>
<owl:onProperty rdf:resource="http://www.semanticweb.org/chris/ontologies/2020/2/dis-coursework-ontology#hasActivity"/>
<owl:someValuesFrom rdf:resource="http://www.semanticweb.org/chris/ontologies/2020/2/dis-coursework-ontology#Football"/>
</owl:Restriction>
</rdfs:subClassOf>
</owl:Class>
So I would expect the results to include:
class | activity SportsHallBooking | Badminton
SportsHallBooking | Football
Yet I get nothing back.
Credit to Stanislav for the answer.
select * { ?class rdfs:subClassOf [ owl:onProperty chris:hasActivity; owl:someValuesFrom ?activity ] }
While uploading .owl file to fusuki server I'm getting errror saying
2.1kb
Result: failed with message "SyntaxError: Unexpected token < in JSON at position 0"]2]2
and my .owl file is
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE rdf:RDF [
<!ENTITY xsd "http://www.w3.org/2001/XMLSchema#">
<!ENTITY rdf "http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<!ENTITY rdfs "http://www.w3.org/2000/01/rdf-schema#">
<!ENTITY owl "http://www.w3.org/2002/07/owl#">
<!ENTITY ns_transport "file://www.ibm.com/WSRR/Transport#">
<!ENTITY wsrr "http://www.ibm.com/xmlns/prod/serviceregistry/6/1/model#">
]>
<rdf:RDF
xmlns:xsd="&xsd;"
xmlns:rdf="&rdf;"
xmlns:rdfs="&rdfs;"
xmlns:owl="&owl;"
xmlns:ns_transport="&ns_transport;"
xmlns:wsrr="&wsrr;"
>
<owl:Ontology rdf:about="&ns_transport;TransportOntology">
<owl:imports rdf:resource="http://www.ibm.com/xmlns/prod/serviceregistry/6/1/model"/>
<wsrr:prefix rdf:datatype="http://www.w3.org/2001/XMLSchema#string">transport</wsrr:prefix>
<rdfs:label>A transport classification system.</rdfs:label>
<rdfs:comment>Cars and buses and some superclasses.</rdfs:comment>
</owl:Ontology>
<owl:Class rdf:about="&ns_transport;Transport">
<rdfs:label>Transport</rdfs:label>
<rdfs:comment>Top-level root class for transport.</rdfs:comment>
</owl:Class>
<owl:Class rdf:about="&ns_transport;LandTransport">
<rdfs:subClassOf rdf:resource="&ns_transport;Transport"/>
<rdfs:label>Land Transport.</rdfs:label>
<rdfs:comment>Middle-level land transport class.</rdfs:comment>
</owl:Class>
<owl:Class rdf:about="&ns_transport;AirTransport">
<rdfs:subClassOf rdf:resource="&ns_transport;Transport"/>
<rdfs:label>Air Transport.</rdfs:label>
<rdfs:comment>Middle-level air transport class.</rdfs:comment>
</owl:Class>
<owl:Class rdf:about="&ns_transport;Bus">
<rdfs:subClassOf rdf:resource="&ns_transport;LandTransport"/>
<rdfs:label>Bus.</rdfs:label>
<rdfs:comment>Bottom-level bus class.</rdfs:comment>
</owl:Class>
<owl:Class rdf:about="&ns_transport;Car">
<rdfs:subClassOf rdf:resource="&ns_transport;LandTransport"/>
<rdfs:label>Car.</rdfs:label>
<rdfs:comment>Bottom-level car class.</rdfs:comment>
</owl:Class>
</rdf:RDF>
While uploading .owl file to fusuki server I'm getting errror saying
2.1kb
While uploading .owl file to fusuki server I'm getting errror saying
2.1kb
While uploading .owl file to fusuki server I'm getting errror saying
2.1kb
While uploading .owl file to fusuki server I'm getting errror saying
2.1kb
While uploading .owl file to fusuki server I'm getting errror saying
2.1kb
I had the same problem in apache-jena-fuseki-3.5.0 version, but this error has handled in apache-jena-fuseki-3.6.0
For a school exercise, I have an RDF file and an OWL file.
There is an owl:Class Lecturer and an owl:Class Researcher. The intersection of both should be a Professor. I have put my RDF and OWL file below.
Problem is: when I do my query, no resource is of type Professor, while in the RDF file we can see that Laura should be a Professor.
Reduced version of rdf file:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE rdf:RDF [
<!ENTITY humans "http://www.inria.fr/2007/09/11/humans.rdfs">
<!ENTITY xsd "http://www.w3.org/2001/XMLSchema#"> ]>
<rdf:RDF
xmlns:rdf ="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
xmlns:xsd ="&xsd;"
xmlns ="&humans;#"
xml:base ="&humans;-instances" >
<Person rdf:ID="Laura">
<name>Laura</name>
</Person>
<Lecturer rdf:about="#Laura"/>
<Researcher rdf:about="#Laura">
<name>Laura</name>
</Researcher>
</rdf:RDF>
Reduced version of owl file:
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
xmlns="http://www.w3.org/2000/01/rdf-schema#"
xml:base="http://www.inria.fr/2007/09/11/humans.rdfs"
xmlns:owl="http://www.w3.org/2002/07/owl#">
<owl:Class rdf:ID="Person">
</owl:Class>
<owl:Class rdf:ID="Lecturer">
<subClassOf rdf:resource="#Person"/>
</owl:Class>
<owl:Class rdf:ID="Researcher">
<subClassOf rdf:resource="#Person"/>
</owl:Class>
<owl:Class rdf:id="Professor">
<owl:intersectionOf rdf:parseType="Collection">
<owl:Class rdf:about="#Lecturer"/>
<owl:Class rdf:about="#Researcher"/>
</owl:intersectionOf>
</owl:Class>
</rdf:RDF>
The query I used was the defautl query:
select * where {
?x ?p ?y
}
But what I actually would expect to do is the following:
select * where {
?x a <http://www.inria.fr/2007/09/11/humans.rdfs#Professor>
}
I did look at this answer: Why do we need to use rdf:parseType="Collection" with owl:intersectionOf? but I don't understand in which way it should be used for my specific problem.
I hope somebody can help. By the way, it's my first post here, so let me know if something's missing.
Paraphrased from comments by #stanislav-kralin:
Use correct capitalization of rdf:ID (not rdf:id), and enable "OWL-Max" reasoning when loading your RDF into GraphDB.
My ontology is about Cocktail. This is a cocktail named "AfterGlow"
<owl:Class rdf:about="&cocktails;AfterGlow">
<owl:equivalentClass>
<owl:Class>
<owl:intersectionOf rdf:parseType="Collection">
<owl:Restriction>
<owl:onProperty rdf:resource="&cocktails;aPourIngredient"/>
<owl:someValuesFrom rdf:resource="&cocktails;JusAnanas"/>
</owl:Restriction>
<owl:Restriction>
<owl:onProperty rdf:resource="&cocktails;aPourIngredient"/>
<owl:someValuesFrom rdf:resource="&cocktails;JusOrange"/>
</owl:Restriction>
<owl:Restriction>
<owl:onProperty rdf:resource="&cocktails;aPourIngredient"/>
<owl:someValuesFrom rdf:resource="&cocktails;SiropGrenadine"/>
</owl:Restriction>
<owl:Restriction>
<owl:onProperty rdf:resource="&cocktails;aPourDescription"/>
<owl:hasValue>Descriptoion AfterGlow</owl:hasValue>
</owl:Restriction>
<owl:Restriction>
<owl:onProperty rdf:resource="&cocktails;aPourTitre"/>
<owl:hasValue>AfterGlow</owl:hasValue>
</owl:Restriction>
</owl:intersectionOf>
</owl:Class>
</owl:equivalentClass>
<rdfs:subClassOf rdf:resource="&cocktails;Cocktail"/>
</owl:Class>
JusOrange means Orange juice
JusAnanas means Pineapple juice
aPourIngredient is a property which means "has(contain) the ingredient"
This is the request which list all my cocktails with theirs rectrictions
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#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX : <http://www.semanticweb.org/cocktails#>
SELECT *
WHERE {
?Cocktail rdfs:subClassOf :Cocktail.
?Cocktail owl:equivalentClass ?restriction .
}
How can I request for example "select all cocktail which contains JusAnanas AND JusOrange"
You can find my ontology here :
https://s3-eu-west-1.amazonaws.com/ontologycero/cocktailsOnthology.owl
I've already found an ugly request, but it's not usable because we have to know the ontology for use this kind of request.
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#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX : <http://www.semanticweb.org/cocktails#>
SELECT *
WHERE {
?Cocktail rdfs:subClassOf :Cocktail.
?Cocktail owl:equivalentClass ?restriction .
?restriction owl:intersectionOf ?intersection.
?intersection rdf:first ?ingredient1.
?intersection rdf:rest ?rest1.
?rest1 rdf:first ?ingredient2.
?rest1 rdf:rest ?rest2.
?rest2 rdf:first ?ingredient3.
?ingredient1 owl:someValuesFrom :JusAnanas.
?ingredient2 owl:someValuesFrom :JusOrange.
}
I am not sure what you are looking for, but as far as I understand you want to bypass the structure of the ontology. Since you don't know what comes after restriction, you can mention to the query to check wall the possible combinations.
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX : <http://www.semanticweb.org/cocktails#>
SELECT *
WHERE {
?Cocktail rdfs:subClassOf :Cocktail.
?Cocktail owl:equivalentClass ?restriction .
?restriction (rdfs:subClassOf|(owl:intersectionOf/rdf:rest*/rdf:first))* ?ingredient1.
?restriction (rdfs:subClassOf|(owl:intersectionOf/rdf:rest*/rdf:first))* ?ingredient2.
?ingredient1 owl:someValuesFrom :JusAnanas.
?ingredient2 owl:someValuesFrom :JusOrange.
}
SPARQL isn't meant to understand the formal OWL model you've set up. It's a graph pattern matching query language for RDF triples. So instead of trying to query through the model, query the data using the semantics of the model you've designed:
SELECT *
WHERE {
?coctails rdfs:subClassOf* :Cocktail .
?aoCocktail a ?coctails .
?aoCocktail :aPourIngredient :JusAnanas .
?aoCocktail :aPourIngredient :JusOrange .
}
The first two triple patterns find all member of :Cocktail and its subclasses. The last two triple patterns find all members that have both :JusOrange and :JusAnanas as values for the property :aPourIngredient.