Need assistance with SPARQL query

53 views
Skip to first unread message

bryj...@gmail.com

unread,
Feb 3, 2022, 9:31:16 PM2/3/22
to islandora
Hi all,

I'm trying to build an API for our 7.x site that returns a list of what we call "terminal collections", or collections that don't have any subcollections, as these are the only collections we want our submission system to deposit into. I'm trying to implement this via SPARQL query along the lines of "get me the PID and label for all objects that have the collection cmodel, and exclude any that have collection cmodel children" but trying to turn this into a SPARQL query is turning out to be harder than I thought. 

Here's what I have so far:

SELECT ?pid ?label
FROM <#ri>
WHERE {
?pid  <fedora-model:hasModel> <info:fedora/islandora:collectionCModel> ;
         <fedora-model:label> ?label ;
         FILTER (<info:fedora/fedora-system:def/relations-external#isMemberOfCollection> !=  ?pid)
}

I have a feeling that the answer lies in using the FILTER operator correctly, as what I'm trying to do is filter things out from the original query, but I can confirm that the current filter above is doing absolutely nothing because it returns the same amount of results if I take it out completely.

What is the proper incantation, SPARQL wizards?

- Bryan

Don Richards

unread,
Feb 4, 2022, 9:59:13 AM2/4/22
to islandora
Totally guessing, it's been a while, have you tried moving the "NOT" to in front of the 'ismemberofCollection'?

SELECT ?pid ?label
FROM <#ri>
WHERE {
?pid  <fedora-model:hasModel> <info:fedora/islandora:collectionCModel> ;
         <fedora-model:label> ?label ;
         FILTER (! <info:fedora/fedora-system:def/relations-external#isMemberOfCollection> = ?pid)
}

Jonathan Hunt

unread,
Feb 9, 2022, 11:39:55 PM2/9/22
to isla...@googlegroups.com
Hi Bryan

Perhaps something like:

SELECT DISTINCT ?obj ?label ?parent
WHERE {
?obj <info:fedora/fedora-system:def/model#hasModel> <info:fedora/islandora:collectionCModel> ;
<fedora-model:label> ?label .
OPTIONAL {?obj <info:fedora/fedora-system:def/relations-external#isMemberOfCollection> ?parent . }
FILTER(!bound(?parent)) .
}

/J
> --
> For more information about using this group, please read our Listserv Guidelines: http://islandora.ca/content/welcome-islandora-listserv
> ---
> You received this message because you are subscribed to the Google Groups "islandora" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to islandora+...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/islandora/9f7b74cc-4de0-4ab1-8c22-9138f8b9e573n%40googlegroups.com.

p: +64 3 963 3733 x7802
Catalyst IT - Expert Open Source Solutions
https://catalyst.net.nz/

signature.asc

bryj...@gmail.com

unread,
Feb 10, 2022, 11:49:14 AM2/10/22
to islandora
Ooooh this is getting REALLY close, but what this query actually seems to be doing is only returning collections that don't have parents (which in my case is the two root collections).

What I'm trying to do is ONLY return collections don't have any collections as children, and the more I think about it the more I think that this must be some sort of subselect thing. Here's what I'm thinking in pseudocode:

Select ?pid ?label
Where {
?pid hasModel islandora:collectionCModel
     Subselect ?childCollectionPid 
     Where {
         ?childCollectionPid hasModel islandora:collectionCModel
         ?childCollectionPid isMemberOfCollection ?pid
      }
Filter (?pids where the subselect found ?childCollectionPids)
}

Aside from this being not actual SPARQL code, this kind of shows the logic I'm trying to implement. My problem is that I don't understand subselects, filters, optionals, bindings or bounds at all and I'm fairly certain one or all of those are the key to making the query do what I want.

Anyone know how to make that pseudocode real?

Thanks!

Reply all
Reply to author
Forward
0 new messages