I'd like to automatically generate a CONSTRUCT query to pull out, say, songs from a set of music. (More generally, I want to pull out hierarchical data given a known data model.)
For example, let's say I know that a song has a title, and it may, optionally, have a composer. Composers, in turn, have names and optional birthYears. If none of the fields were optional, I'd just do:
CONSTRUCT {
?song dcterms:title ?title.
?song music:hasComposer ?composer.
?composer foaf:name ?cname.
?composer music:birthYear ?y.
}
WHERE {
?song dcterms:title ?title.
?song music:hasComposer ?composer.
?composer foaf:name ?cname.
?composer music:birthYear ?y.
}
-- but since the composer is optional, I need to restrict the composer-related lines of my WHERE clause. But once I do that, I can't CONSTRUCT them.
My problem is actually bigger: there are lots of types, in a hierarchical relation, with known properties and optional properties. and I want to automatically generate CONSTRUCT queries for arbitrary types. Any thoughts on a good strategy for doing this? Any clarification I can add?
Thanks!
-B