I’m new to SPARQL and I’m trying to select two or more data properties from entity.
I have Artist entity which has two data properties (id and name). I’m trying to obtain a result like this:
id Name
0 Artist 1
1 Artist 2
But what I’m getting is this:
id Name
0 Artist 1
0 Artist 2
1 Artist 1
1 Artist 2
Here is my SPARQL query:
PREFIX wits: <http://wits.org/song/>
SELECT ?name, ?id
FROM <http://wits.org/song>
WHERE
{
<http://wits.org/song/Artist> wits:Name ?name .
<http://wits.org/song/Artist> wits:ID ?id
}
Here is RDF implementation of Artist Class:
<!ENTITY www "http://www.wits.org/" >
<owl:Class rdf:about="&www;Artist">
<rdfs:subClassOf rdf:resource="&owl;Thing"/>
<rdfs:subClassOf>
<owl:Restriction>
<owl:onProperty rdf:resource="&www;song#ID"/>
<owl:allValuesFrom rdf:resource="&xsd;unsignedInt"/>
</owl:Restriction>
</rdfs:subClassOf>
<rdfs:subClassOf>
<owl:Restriction>
<owl:onProperty rdf:resource="&www;song#Name"/>
<owl:qualifiedCardinality rdf:datatype="&xsd;nonNegativeInteger">1</owl:qualifiedCardinality>
<owl:onDataRange rdf:resource="&xsd;string"/>
</owl:Restriction>
</rdfs:subClassOf>
</owl:Class>
This is INSERT command which was executed previously:
PREFIX wits: <http://wits.org/song/>
INSERT DATA INTO <http://wits.org/song> {
wits:Artist wits:Name "Artist 2"
wits:ID 1 .
}
What am I doing wrong?
Any help is appreciated.
125125
I guess you are inserting the following data.
which is wrong because
wits:Artistwould have both names and both ids, you need to give different URIs to each Artist and provide the class asrdf:type.The right way according to your ontology would be …
ais equivalent tordf:type. In here we’re saying thatwits:Artist0is type of classwits:Artistwith nameArtist 0and id0.