Reputation: 13
I am working on an Ontology about Tolkien Elves' family branches. Here is the OWL file.
Now I have added the prefixes for the SPARQL tab in Protégé like this:
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 gene: <http://www.semanticweb.org/kayurin/ontologies/2015/1/casata_di_finwe#>
And then started to work on my first queries, the first successful one being:
SELECT ?Prole
WHERE
{
?x gene:nomeCompleto ?Prole;
gene:haGenitore gene:Finwe.
}
It's meant to return me, under the column "Prole" (Offspring) the Data Property NomeCompleto (A string value I used because unsure about using the specialcase characters in for the Members of the Individuo Class.) for all the member of the class "Individuo" (Person) who had the property haGenitore Finwe (Has Finwe as a parent.).
It works, feels a little too wordy but (At the same time.) it's a good base for me to work on other related queries like:
SELECT ?FigliMaschi
WHERE
{
?x gene:nomeCompleto ?FigliMaschi;
gene:haGenitore gene:Finwe;
gene:haSesso gene:MaschioSesso.
}
Which successfully returns me all the NomeCompleto strings for the male children of 'ol Finwe.
Now, my first problem:
The strings are returned to me in this exact format. "[insertnamehere]" @
They have "" and @ which I don't really know from where they come from.
Second Problem:
I tried the evolved Query:
SELECT ?Prole
WHERE
{
?x gene:nomeCompleto ?Prole;
gene:haGenitore gene:Finwe;
gene:haSesso gene:MaschioSesso.
?y gene:nomeCompleto ?FiglieFemmine;
gene:haGenitore gene:Finwe;
gene:haSesso gene:FemminaSesso.
}
The idea was to get two columns, one with the sons and another with the daughters of our prolificating elf.
It does, but the names in the male column are copied three times and the ones in the female column copied two times so that the numbers of entries in both columns are equal.
There is no way to fix this?
Third question:
I wanted to get two columns: Padre and Figli, the first supposed to have the name of just Finwe and the second all of his offsprings.
The Query was:
SELECT ?Padre ?Figli
WHERE
{
?a gene:nomeCompleto ?Padre;
gene:Finwe.
?x gene:nomeCompleto ?Figli;
gene:haGenitore gene:Finwe.
}
Doesn't work, empty field.
Finally, I wanted to improve the data properties by splitting nomeCompleto in nomeFormale and nomeComune (To add a second name for each member of the list.) I tried to make a query that would return nomeCompleto two times, but the only one working was this:
SELECT ?Nome1 ?Nome2
WHERE
{
?x gene:nomeCompleto ?Nome1;
gene:haGenitore gene:Finwe.
?y gene:nomeCompleto ?Nome2;
gene:haGenitore gene:Finwe.
}
And even with this, the list is a mess.
Anyone that could give an hand solving this thing?
Thanks in advance to everyone.
Notes:
I'm using Protégé 5.0 beta. (The only version that works on my pc.) HermiT 1.3.8.3 as a Reasoner. Java Version 8 Update 31 Windows 8.1 64bit
Upvotes: 1
Views: 96
Reputation: 3301
I think you really need to read up on SPARQL. You should stop thinking as if it is a database.
You can create a union of the two queries, so that you will have some empty cells, but you won't get repetition.
SELECT distinct ?Prole ?FiglieFemmine
WHERE
{
{?x gene:nomeCompleto ?Prole;
gene:haGenitore gene:Finwe;
gene:haSesso gene:MaschioSesso.
}
Union{
?y gene:nomeCompleto ?FiglieFemmine;
gene:haGenitore gene:Finwe;
gene:haSesso gene:FemminaSesso.
}
}
First your query is incomplete, you are missing a property which I assumed to be haProle. So you need to find all the individuals with their fathers and then filter them based on the father you have in mind. Something like this:
SELECT distinct *
WHERE
{
?padre gene:haProle ?figili.
?padre gene:nomeCompleto ?n1.
?figili gene:nomeCompleto ?n2.
Filter (?padre=gene:Finwe)
}
If you want to return something twice (the same thing) you nee to be use the same object (in your query x). I am really not sure what you want to do, but this is how to get a name twice.
SELECT ?Nome1 ?Nome2
WHERE
{
?x gene:nomeCompleto ?Nome1;
gene:haGenitore gene:Finwe.
?x gene:nomeCompleto ?Nome2;
gene:haGenitore gene:Finwe.
}
Upvotes: 2