SPARQL Select two columns
I'm new to SPARQL and I'm trying to select two or more data properties f开发者_如何学Pythonrom 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.
INSERT DATA INTO <http://wits.org/song> {
wits:Artist wits:Name "Artist 0"; wits:ID 0 .
wits:Artist wits:Name "Artist 1"; wits:ID 1 .
}
which is wrong because wits:Artist
would have both names and both ids, you need to give different URIs to each Artist and provide the class as rdf:type
.
The right way according to your ontology would be ...
INSERT DATA INTO <http://wits.org/song> {
wits:Artist0 a wits:Artist; wits:Name "Artist 0"; wits:ID 0 .
wits:Artist1 a wits:Artist; wits:Name "Artist 1"; wits:ID 1 .
}
a
is equivalent to rdf:type
. In here we're saying that wits:Artist0
is type of class wits:Artist
with name Artist 0
and id 0
.
精彩评论