Hello Guys,
I've been trying to "replace" a SPARQL query using RDFAlchemy's rdfSubject, but I didn't succeed.
Consider the query bellow, with which I'd like to acquire 10 musicians from DBPedia who play guitar or piano. I'd also like to retrieve the label of the instrument they play:
"""
SELECT distinct ?name ?label {
?artist
a dbonto:MusicalArtist;
dbprop:birthName ?name.
{
?artist dbonto:instrument db:Guitar .
db:Guitar rdfs:label ?label.
}
UNION
{
?artist dbonto:instrument db:Piano .
db:Piano rdfs:label ?label .
}
FILTER ( lang(?name) = "en" )
}
ORDER BY ?name
LIMIT 10
"""
I considered using rdfSubject as shown bellow, but I'm afraid the line commented with the "FIXME" is wrong:
------------------------------------------------------------------------
class Instrument(rdfSubject):
rdfs_label = rdfSingle(RDFS.label, 'label')
class MusicalArtist(rdfSubject):
rdf_type = DBONTO.MusicalArtist
dbprop_birthname = DBPROP.birthName
dbonto_instrument = Instrument # ? FIXME
------------------------------------------------------------------------
The idea is to be able to use rdfSubject such as shown bellow. This would bring musicians who play guitar, for instance (simpler than the original query - but on the way ;)).
------------------------------------------------------------------------
guitar_players_list = MusicalArtist.get_by(dbonto_instrument=DB.Guitar)
------------------------------------------------------------------------
However, in this case, it is throwing a AttributeError, saying "type object 'rdfSubject' has no attribute 'pred'."
What would be the best way of doing this?
The complete source code for this example is available here:
Thanks in advance!
Tatiana