Skip to content

Commit cc07a74

Browse files
committed
Fix CMR expansion to not attach remote Rs
1 parent c7bc4c7 commit cc07a74

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

ucca/normalization.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -281,17 +281,19 @@ def split_coordinated_main_rel(node, l1):
281281
else:
282282
top = node
283283
outgoing = list(node.outgoing)
284+
external = [e for e in outgoing if KEEP_OUTSIDE_CMR.intersection(e.tags)]
285+
internal = [e for e in outgoing if not KEEP_OUTSIDE_CMR.intersection(e.tags) and
286+
e.ID != edge.ID] # Not the CMR edge itself
287+
for scene_edge in external: # A category that should be kept outside of both scenes
288+
copy_edge(scene_edge, parent=top)
284289
scenes = []
285290
for center in centers:
286291
new_scene = l1.add_fnode(top, ETags.ParallelScene)
287292
copy_edge(edge, parent=new_scene, child=center, attrib=attrib)
288-
for scene_edge in outgoing:
289-
if scene_edge.ID != edge.ID and not (
290-
scenes and NO_MULTIPLE_INCOMING_CATEGORIES.intersection(scene_edge.tags)):
291-
# Not the CMR edge itself, and not a category that does not allow multiple parents
292-
copy_edge(scene_edge,
293-
parent=top if KEEP_OUTSIDE_CMR.intersection(scene_edge.tags) else new_scene,
294-
attrib={"remote": True} if scenes else None)
293+
for scene_edge in internal:
294+
if not (scenes and NO_MULTIPLE_INCOMING_CATEGORIES.intersection(scene_edge.tags)):
295+
# Attach inside the 1st scene and potentially also as remote in 2nd scene
296+
copy_edge(scene_edge, parent=new_scene, attrib={"remote": True} if scenes else None)
295297
scenes.append(new_scene)
296298
for main_rel_edge in main_rel_non_centers:
297299
tags = main_rel_edge.tags

ucca/tests/test_normalization.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ def expanded_remote_cmr():
350350
return p
351351

352352

353-
def cmr_with_relator():
353+
def cmr_with_relator_outside():
354354
"""
355355
[suitable_S [for_R the_F [breeding_C and_N growing_C]_P|CMR [of_R giants_C]_A]_A]_H
356356
"""
@@ -361,14 +361,14 @@ def cmr_with_relator():
361361
r1 = l1.add_fnode(a_scene, layer1.EdgeTags.Relator)
362362
f = l1.add_fnode(a_scene, layer1.EdgeTags.Function)
363363
p1, c1, n, c2 = insert_cmr(l1, a_scene)
364-
a2 = l1.add_fnode(ps, layer1.EdgeTags.Participant)
364+
a2 = l1.add_fnode(a_scene, layer1.EdgeTags.Participant)
365365
r2 = l1.add_fnode(a2, layer1.EdgeTags.Relator)
366366
c3 = l1.add_fnode(a2, layer1.EdgeTags.Center)
367367
attach_terminals(terms, s, r1, f, c1, n, c2, r2, c3)
368368
return p
369369

370370

371-
def expanded_cmr_with_relator():
371+
def expanded_cmr_with_relator_outside():
372372
"""
373373
[suitable_S [for_R [[the_F breeding_C]_P [of_R giants_C]_A]_H and_L [[growing_P] [*of giants]_A]_H]_H
374374
"""
@@ -381,14 +381,13 @@ def expanded_cmr_with_relator():
381381
linker = l1.add_fnode(a_superscene, layer1.EdgeTags.Linker)
382382
ps3 = l1.add_fnode(a_superscene, layer1.EdgeTags.ParallelScene)
383383
p1 = l1.add_fnode(ps2, layer1.EdgeTags.Process)
384-
f = l1.add_fnode(p1, layer1.EdgeTags.Function)
385-
c1 = l1.add_fnode(p1, layer1.EdgeTags.Center)
384+
f = l1.add_fnode(ps2, layer1.EdgeTags.Function)
386385
a = l1.add_fnode(ps2, layer1.EdgeTags.Participant)
387386
r2 = l1.add_fnode(a, layer1.EdgeTags.Relator)
388387
c2 = l1.add_fnode(a, layer1.EdgeTags.Center)
389388
p2 = l1.add_fnode(ps3, layer1.EdgeTags.Process)
390389
l1.add_remote(ps3, layer1.EdgeTags.Participant, a)
391-
attach_terminals(terms, s, r1, f, c1, linker, p2, r2, c2)
390+
attach_terminals(terms, s, r1, f, p1, linker, p2, r2, c2)
392391
return p
393392

394393

@@ -423,7 +422,7 @@ def normalize_and_compare(unnormalized, normalized, extra=False):
423422
(cmr_no_attrib, cmr_no_attrib),
424423
(cmr, expanded_cmr),
425424
(remote_cmr, expanded_remote_cmr),
426-
(cmr_with_relator, expanded_cmr_with_relator),
425+
(cmr_with_relator_outside, expanded_cmr_with_relator_outside),
427426
))
428427
def test_normalize(unnormalized, normalized):
429428
normalize_and_compare(unnormalized, normalized)

0 commit comments

Comments
 (0)