Skip to content

Avoid circularity in `ParentStrategy`

tamsin woo requested to merge feature/handle_circular_parentage into develop

Created by: no-reply

The solution to the circularity problem included here is as follows:

When an RDFSource instance is added to a Relation it's parent is set to the Relation's source (confusingly, also called a "parent"; we'll say "source" for clarity). This happens unless one of the following holds:

  • the Relation's source is the RDFSource being added (i.e. the relationship is self-referential).
  • the RDFSource is an ancestor of the Relation's source
  • the RDFSource instance already has a parent

These constraints rule out the creation of circular parentage relationships via #add_child_node.

When accessing a reloaded child node through a Relation, its internal graph contains the subset of the parent's statements where the subject is the child node. We can safely continually loop through circular relations in the graph without causing conflicts. E.g., the following works without problems:

person1.author_of = doc1
doc1.published_by = org1
org1.publishes = person1

person1.author_of
  .first.published_by
  .first.publishes
  .first.author_of
  .first.published_by...

Closes #147 (closed)

Merge request reports

Loading