Skip to content

Commit

Permalink
fix subject deduping bug
Browse files Browse the repository at this point in the history
  • Loading branch information
aaxelb committed Mar 10, 2021
1 parent f470c98 commit dba4d51
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 3 deletions.
1 change: 1 addition & 0 deletions share/disambiguation/strategies/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ def match_subjects(self, nodes):
matches = [
n for n in graph_nodes
if n != node
and n['parent'] == node['parent']
and n['central_synonym'] == node['central_synonym']
and (equal_not_none(n['uri'], node['uri']) or equal_not_none(n['name'], node['name']))
]
Expand Down
1 change: 1 addition & 0 deletions share/schema/schema-spec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@
- name: central_synonym
relation_shape: many_to_one
related_concrete_type: Subject
inverse_relation: custom_synonyms

- concrete_type: ThroughSubjects
attributes:
Expand Down
4 changes: 2 additions & 2 deletions share/util/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -560,13 +560,13 @@ def delete(self, cascade=True):
self.graph.remove_node(self.id, cascade)
self.__graph = None

def to_jsonld(self, ref=False, in_edges=True):
def to_jsonld(self, ref=False, in_edges=False):
ld_node = {
'@id': self.id,
'@type': self.type,
}
if not ref:
ld_node.update(self.relations(in_edges=False, jsonld=True))
ld_node.update(self.relations(in_edges=in_edges, jsonld=True))
ld_node.update(self.attrs())
return ld_node

Expand Down
22 changes: 21 additions & 1 deletion tests/share/regulate/steps/test_deduplicate.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,27 @@ def test_no_change(self, Graph, input):
WorkIdentifier(4),
WorkIdentifier(uri='http://osf.io/guidguid'),
]),
])
]),
([
Registration(0, subjects=[
Subject(
0,
name='custom-child',
central_synonym=Subject(1, name='central-child', parent=Subject(3, name='central-parent')),
parent=Subject(2, name='custom-parent', central_synonym=Subject(3, name='central-parent')),
)
for _ in range(3)
]),
], [
Registration(0, subjects=[
Subject(
0,
name='custom-child',
central_synonym=Subject(1, name='central-child', parent=Subject(3, id='central-parent', name='central-parent')),
parent=Subject(2, name='custom-parent', central_synonym=Subject(id='central-parent')),
)
]),
]),
])
def test_deduplicate(self, Graph, input, output):
graph = Graph(input)
Expand Down

0 comments on commit dba4d51

Please sign in to comment.