- From: Rob Walpole <robkwalpole@gmail.com>
- Date: Mon, 28 Jan 2013 15:54:52 +0000
- To: Andy Seaborne <andy.seaborne@epimorphics.com>
- Cc: public-sparql-dev@w3.org
- Message-ID: <CACGPhhOi7JtF7+9vZbGBFbMxSftUYXu+fNKhdy3ChurMHVHHcA@mail.gmail.com>
Hi Andy, Thanks for your speedy reply. > FILTER tests the values of a variable in the current row, not all possible > values of a variable anywhere. Ah, I had failed to grasp this. I thought rows were a relational db concept I didn't need to worry about anymore ;-) So in applying a filter we are iterating over the values in the result set and applying the filter to each value in turn. > What you need to do is check the data to see if what ever value ?child > has, then it is not used as an ancestor. The value of ?ancestor in the row > is only one match, not all matches. > > Unfortunately any child can also be an ancestor of something (i.e. the ancestor of something else I am not interested in) so I need to be more selective than this. However by using the ?export value (of which I know there is only one) I can find the ancestor that is also a member of the export using... FILTER EXISTS { ?export rdfs:member ?ancestor } Although I am still not clear why... FILTER( ?ancestor IN ( ?member ) ) ...doesn't work as an export can have many members (although it may only have one). Anyway, the following query is now giving me the results I expect: DESCRIBE ?child WHERE { ?export rdfs:member ?member ; OPTIONAL { { SELECT ?ancestor WHERE { BIND(URI(" http://nationalarchives.gov.uk/dri/catalogue/item/c2433752-b1e5-44e4-a271-c36d29aa6a3b") AS ?deselected) # get the ancestors of the deselected item ?deselected dri:parent+ ?ancestor . # get the ancestor that is a member of the export list FILTER EXISTS { ?export rdfs:member ?ancestor } . } } # get all of the children of the ancestor/member ?child dri:parent ?ancestor . FILTER NOT EXISTS { ?deselected dri:parent+ ?child } . } } As you say, FILTER EXISTS and FILTER NOT EXISTS are the key :-) Thanks for your help. Rob -- Rob Walpole Email robkwalpole@gmail.com Tel. +44 (0)7969 869881 Skype: RobertWalpolehttp://www.linkedin.com/in/robwalpole
Received on Monday, 28 January 2013 15:55:20 UTC