RDFLib / prez

Prez is a data-configurable Linked Data API framework that delivers profiles of Knowledge Graph data according to the Content Negotiation by Profile standard.
BSD 3-Clause "New" or "Revised" License
18 stars 7 forks source link

Fix get_bnode_depth edge case #156

Closed edmondchuc closed 9 months ago

edmondchuc commented 9 months ago

The current get_bnode_depth function only works for resources with a single top-level blank node.

Effectively, it is counting the total number of blank nodes in the given graph closure.

This PR fixes the issue where multiple top-level blank nodes are counted incorrectly based on the description of the previous behaviour above. It counts the maximum depth of the blank nodes for a given graph closure correctly by performing a depth-first search.

A new test case bnode_depth-2-2.ttl has been added to illustrate the correct behaviour has been implemented now.

edmondchuc commented 9 months ago

@hjohns, yes this is what fixes it. The progressive loading of vocabs APIs call this bnode depth function, which previously calculated it wrong if you have more than 1 top-level blank node. In your case, you had two top-level blank nodes because you had two custodians described with the prov:qualifiedAttribution property. This is tested in the new test data added in this PR.

edmondchuc commented 9 months ago

Cyclic graphs are not an issue here. As described in the function, it is intended to work on a resource's concise bounded description.