Graph¶
Graph module.
Models¶
Graph database models.
-
class
asclepias_broker.graph.models.
Group
(**kwargs)[source]¶ Group model.
A simple constructor that allows initialization from kwargs.
Sets attributes on the constructed instance using the names and values in
kwargs
.Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.
-
class
asclepias_broker.graph.models.
GroupM2M
(**kwargs)[source]¶ Many-to-many model for Groups.
A simple constructor that allows initialization from kwargs.
Sets attributes on the constructed instance using the names and values in
kwargs
.Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.
-
class
asclepias_broker.graph.models.
GroupRelationship
(**kwargs)[source]¶ Group relationship model.
A simple constructor that allows initialization from kwargs.
Sets attributes on the constructed instance using the names and values in
kwargs
.Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.
-
class
asclepias_broker.graph.models.
GroupRelationshipM2M
(**kwargs)[source]¶ Many-to-many model for Group Relationships.
A simple constructor that allows initialization from kwargs.
Sets attributes on the constructed instance using the names and values in
kwargs
.Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.
-
class
asclepias_broker.graph.models.
Identifier2Group
(**kwargs)[source]¶ Many-to-many model for Identifier and Group.
A simple constructor that allows initialization from kwargs.
Sets attributes on the constructed instance using the names and values in
kwargs
.Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.
-
class
asclepias_broker.graph.models.
Relationship2GroupRelationship
(**kwargs)[source]¶ Many-to-many model for Relationship to GroupRelationship.
A simple constructor that allows initialization from kwargs.
Sets attributes on the constructed instance using the names and values in
kwargs
.Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.
API¶
Graph functions.
-
asclepias_broker.graph.api.
add_group_relationship
(relationship, src_id_grp, tar_id_grp, src_ver_grp, tar_ver_grp)[source]¶ Add a group relationship between corresponding groups.
-
asclepias_broker.graph.api.
delete_duplicate_group_m2m
(group_a, group_b)[source]¶ Delete any duplicate GroupM2M objects.
Removes one of each pair of GroupM2M objects for groups A and B.
-
asclepias_broker.graph.api.
delete_duplicate_relationship_m2m
(group_a, group_b, cls=<class 'asclepias_broker.graph.models.GroupRelationshipM2M'>)[source]¶ Delete any duplicate relationship M2M objects.
Deletes any duplicate (unique-constraint violating) M2M objects between relationships and group relationships. This step is required before merging of two groups.
-
asclepias_broker.graph.api.
get_group_from_id
(identifier_value, id_type='doi', group_type=<GroupType.Identity: 1>)[source]¶ Resolve from ‘A’ to Identity Group of A or to a Version Group of A.
Return type: Group
-
asclepias_broker.graph.api.
get_or_create_groups
(identifier)[source]¶ Given an Identifier, fetch or create its Identity and Version groups.
Return type: Tuple
[Group
,Group
]
-
asclepias_broker.graph.api.
merge_group_relationships
(group_a, group_b, merged_group)[source]¶ Merge the relationships of merged groups A and B to avoid collisions.
Parameters: Groups ‘group_a’ and ‘group_b’ will be merged as ‘merged_group’. This function takes care of moving any duplicate group relations, e.g.:
If we have 4 relations:
- A Cites X
- B Cites X
- Y Cites A
- Y Cites B
and we merge groups A and B, we also need to squash the first two and last two relations together:
- {AB} Cites X
- Y Cites {AB}
before we can perform the actual marging of A and B. Otherwise we will violate the unique constraint. We do that by removing the duplicate relationships (only one of each duplicate pair), so that we can later execute and UPDATE.
-
asclepias_broker.graph.api.
merge_identity_groups
(group_a, group_b)[source]¶ Merge two groups of type “Identity”.
Merges the groups together into one group, taking care of migrating all group relationships and M2M objects.
Return type: Tuple
[Optional
[Group
],Optional
[Group
]]
Tasks¶
Asynchronous tasks.
-
asclepias_broker.graph.tasks.
compact_indexing_groups
(groups_ids)[source]¶ Compact the collected group IDs into minimal set of UUIDs.
Return type: Tuple
[Set
[str
],Set
[str
],Set
[str
],Set
[str
],Dict
[str
,str
]]
-
asclepias_broker.graph.tasks.
create_relation_object_events
(event, relationship, payload_idx)[source]¶ Create the object event models.