Dear Joshua and others,
yes, the file was not correctly formatted because I just write it by hand,
not with any editor. Thanks, Joshua! Anyway, it was just an example. Maybe
I did not formulate the question precisely. It is how to write a query
which results connects two categories ("person" and "city" in the example)
because these categories are connected through the third category ("gender"
in the example)?
The question is how to get answer like the below without directly
connecting "person" and "city" in the query itself:
| person | city |
| Ivan | London |
Between, I got errors while I was using VALUES in the query. Is there any
recommendation how to use this keyword correctly (I guess it is wrong
something with brackets or other syntax)?
I used the following way:
SELECT DISTINCT ?person ?city WHERE{ VALUES (?gender ?city) {base:Gender
base:City} ?person a base:Person; owl:topObjectProperty ?gender. ?city a
base:City; owl:topObjectProperty ?gender};
Yours,
Darius
2013/8/19 Joshua TAYLOR <[email protected]>
> The ontology data that you provided is not well formed XML, let alone
> RDF/XML. It looks like, however, that you're aiming for something
> like:
>
>
> <rdf:RDF
> xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
> xmlns:owl="http://www.w3.org/2002/07/owl#"
> xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
> xmlns="http://www.semanticweb.org/darius/ontologies/2013/6/rooms#"
> xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#">
> <owl:Ontology
> rdf:about="http://www.semanticweb.org/darius/ontologies/2013/6/rooms"/>
> <owl:Class rdf:about="
> http://www.semanticweb.org/darius/ontologies/2013/6/rooms#Gender"/>
> <owl:Class rdf:about="
> http://www.semanticweb.org/darius/ontologies/2013/6/rooms#Person"/>
> <owl:Class rdf:about="
> http://www.semanticweb.org/darius/ontologies/2013/6/rooms#City"/>
> <owl:NamedIndividual
> rdf:about="
> http://www.semanticweb.org/darius/ontologies/2013/6/rooms#London">
> <rdf:type rdf:resource="
> http://www.semanticweb.org/darius/ontologies/2013/6/rooms#City"/>
> <owl:topObjectProperty>
> <owl:NamedIndividual
> rdf:about="http://www.semanticweb.org/darius/ontologies/2013/6/rooms#Male
> ">
> <rdf:type
> rdf:resource="
> http://www.semanticweb.org/darius/ontologies/2013/6/rooms#Gender"/>
> </owl:NamedIndividual>
> </owl:topObjectProperty>
> </owl:NamedIndividual>
> <owl:NamedIndividual
> rdf:about="http://www.semanticweb.org/darius/ontologies/2013/6/rooms#Ana">
> <rdf:type rdf:resource="
> http://www.semanticweb.org/darius/ontologies/2013/6/rooms#Person"/>
> </owl:NamedIndividual>
> <owl:NamedIndividual
> rdf:about="http://www.semanticweb.org/darius/ontologies/2013/6/rooms#Ivan
> ">
> <rdf:type rdf:resource="
> http://www.semanticweb.org/darius/ontologies/2013/6/rooms#Person"/>
> <owl:topObjectProperty
> rdf:resource="
> http://www.semanticweb.org/darius/ontologies/2013/6/rooms#Male"/>
> </owl:NamedIndividual>
> </rdf:RDF>
>
>
> or, in the more readable Turtle syntax:
>
>
> @prefix : <
> http://www.semanticweb.org/darius/ontologies/2013/6/rooms#> .
> @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
> @prefix owl: <http://www.w3.org/2002/07/owl#> .
> @prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
> @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
>
> :Gender
> a owl:Class .
>
> <http://www.semanticweb.org/darius/ontologies/2013/6/rooms>
> a owl:Ontology .
>
> :Male
> a :Gender , owl:NamedIndividual .
>
> :London
> a owl:NamedIndividual , :City ;
> owl:topObjectProperty
> :Male .
>
> :Ana a owl:NamedIndividual , :Person .
>
> :Ivan
> a owl:NamedIndividual , :Person ;
> owl:topObjectProperty
> :Male .
>
> :Person
> a owl:Class .
>
> :City
> a owl:Class .
>
>
> Given that ontology, you can use a query like this:
>
>
> prefix rooms: <http://www.semanticweb.org/darius/ontologies/2013/6/rooms#>
> prefix owl: <http://www.w3.org/2002/07/owl#>
>
> select ?person ?personProperty ?city ?cityProperty ?gender where {
>
> values (?person ?city) {
> (rooms:Ivan rooms:London)
> }
>
> ?person a rooms:Person ;
> ?personProperty ?gender .
> ?gender a rooms:Gender .
> ?city a rooms:City ;
> ?cityProperty ?gender .
> }
>
>
> and get results like:
>
>
> $ arq --data data.rdf --query query.sparql
>
> ------------------------------------------------------------------------------------------
> | person | personProperty | city | cityProperty
> | gender |
>
> ==========================================================================================
> | rooms:Ivan | owl:topObjectProperty | rooms:London |
> owl:topObjectProperty | rooms:Male |
>
> ------------------------------------------------------------------------------------------
>
>
> which looks like it should at least get you started toward what you're
> trying to achieve.
>
> //JT
>
>
> On Mon, Aug 19, 2013 at 10:16 AM, Darius Miliauskas
> <[email protected]> wrote:
> > Dear Arthur,
> >
> > Thanks for the prompt answer, I will try. Here, is the ontology as
> RDF/XML
> > file:
> >
> >
> > <?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 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.semanticweb.org/darius/ontologies/2013/6/rooms#"
> > xml:base="http://www.semanticweb.org/darius/ontologies/2013/6/rooms
> "
> > xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
> > 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#">
> > <owl:Ontology rdf:about="
> > http://www.semanticweb.org/darius/ontologies/2013/6/rooms"/>
> >
> > <!--
> >
> >
> ///////////////////////////////////////////////////////////////////////////////////////
> > //
> > // Classes
> > //
> >
> >
> ///////////////////////////////////////////////////////////////////////////////////////
> > -->
> >
> > <!--
> http://www.semanticweb.org/darius/ontologies/2013/6/rooms#Person-->
> >
> > <owl:Class rdf:about="
> > http://www.semanticweb.org/darius/ontologies/2013/6/rooms#Person"/>
> >
> >
> > <!-- http://www.semanticweb.org/darius/ontologies/2013/6/rooms#City-->
> >
> > <owl:Class rdf:about="
> > http://www.semanticweb.org/darius/ontologies/2013/6/rooms#City"/>
> >
> >
> > <!--
> http://www.semanticweb.org/darius/ontologies/2013/6/rooms#Gender-->
> >
> > <owl:Class rdf:about="
> > http://www.semanticweb.org/darius/ontologies/2013/6/rooms#Gender"/>
> >
> >
> ///////////////////////////////////////////////////////////////////////////////////////
> > //
> > // Individuals
> > //
> >
> >
> ///////////////////////////////////////////////////////////////////////////////////////
> > -->
> >
> > <!-- http://www.semanticweb.org/darius/ontologies/2013/6/rooms#Ivan -->
> >
> > <owl:NamedIndividual rdf:about="
> > http://www.semanticweb.org/darius/ontologies/2013/6/rooms#Ivan">
> >
> > <rdf:type rdf:resource="
> > http://www.semanticweb.org/darius/ontologies/2013/6/rooms#Person"/>
> > <owl:topObjectProperty rdf:resource="
> > http://www.semanticweb.org/darius/ontologies/2013/6/rooms#Male"/>
> >
> >
> > <!-- http://www.semanticweb.org/darius/ontologies/2013/6/rooms#Ana -->
> >
> > <owl:NamedIndividual rdf:about="
> > http://www.semanticweb.org/darius/ontologies/2013/6/rooms#Ana">
> >
> > <rdf:type rdf:resource="
> > http://www.semanticweb.org/darius/ontologies/2013/6/rooms#Person"/>
> >
> >
> > <!-- http://www.semanticweb.org/darius/ontologies/2013/6/rooms#Male -->
> >
> > <owl:NamedIndividual rdf:about="
> > http://www.semanticweb.org/darius/ontologies/2013/6/rooms#Male">
> >
> > <rdf:type rdf:resource="
> > http://www.semanticweb.org/darius/ontologies/2013/6/rooms#Gender"/>
> >
> >
> > <!-- http://www.semanticweb.org/darius/ontologies/2013/6/rooms#London-->
> >
> > <owl:NamedIndividual rdf:about="
> > http://www.semanticweb.org/darius/ontologies/2013/6/rooms#London">
> >
> > <rdf:type rdf:resource="
> > http://www.semanticweb.org/darius/ontologies/2013/6/rooms#City"/>
> > <owl:topObjectProperty rdf:resource="
> > http://www.semanticweb.org/darius/ontologies/2013/6/rooms#Male"/>
> >
> >
> > 2013/8/19 Arthur Vaïsse-Lesteven <[email protected]>
> >
> >> There is missing information about object properties. And the link
> between
> >> Ivan and London isn't clear.
> >>
> >> Assuming you are requesting a query to create a triple of type (Ivan, a
> >> relation, London) you could try something like this:
> >>
> >> INSERT{ ?person isRelatedTo ?city}
> >> WHERE{
> >> ?person a Person.
> >> ?person name "Ivan"^^xsd:String.
> >> ?city a City.
> >> ?city name "London"^^xsd:String.
> >> }
> >>
> >>
> >> where "isRelatedTo" is an object properties of your choice.
> >> This query will create a triple for each city with a name of London and
> >> every Person with a name equal to "Ivan".
> >>
> >> I hope this will help you. For more information about SPARQL queries I
> >> suggest you to read the current W3C Recommendation (
> >> http://www.w3.org/TR/sparql11-query/ )
> >>
> >> It would be much easier to help you with your minimal ontology include
> in
> >> the mail.
> >>
> >> VAÏSSE-LESTEVEN Arthur
> >>
> >> >Dear Sir or Madam,
> >> >
> >> >let's say I have an ontology, to make things clear and simple it looks
> >> like
> >> >this one:
> >> >
> >> >a) three classes, every one has two individuals:
> >> >Person: Ivan and Ana;
> >> >City: London and Paris;
> >> >Gender: Male and Female.
> >> >
> >> >b) Ivan from the class "Person" is related to Male from the class
> >> "Gender";
> >> >London from the class "City" is related to Male from the class
> "Gender".
> >> >
> >> >How to write the SPARQL query to find/connect Ivan from the class
> "Person"
> >> >to London from the class "City"?
> >> >
> >> >In SQL it would look something the following way (between, it could be
> >> >wrong):
> >> >SELECT London FROM City WHERE Ivan=Male AND London=Male;
> >> >
> >> >
> >> >Sincerely Yours,
> >> >
> >> >Darius Miliauskas
> >>
>
>
>
> --
> Joshua Taylor, http://www.cs.rpi.edu/~tayloj/
>