Commit cffcfa4cb117067d2ad13cf12a0dc1bc1352ffe8

Authored by Tomasz Bartosiak
1 parent 0c9241a6

usuwanie niepowiązanego argumentu Lemma po zapisie

Showing 1 changed file with 12 additions and 0 deletions
semantics/saving.py
... ... @@ -15,6 +15,7 @@ def modify_frames(lemma_id, operations, user):
15 15 make_operations(lemma_id, operations)
16 16  
17 17 def make_operations(lemma_id, operations):
  18 + complements_to_test = set([])
18 19 translation = {'unit_id': {}, 'frame_id': {}, 'complement_id': {}, 'preference_id': {}}
19 20 entry = Lemma.objects.get(id=lemma_id).entry_obj
20 21 for operation in operations:
... ... @@ -78,6 +79,7 @@ def make_operations(lemma_id, operations):
78 79 argument_id = int(schema_data[5])
79 80 alternation = int(schema_data[7])
80 81 disconnect(frame_id, complement_id, schema_id, position_id, argument_id, alternation)
  82 + complements_to_test.add((frame_id, complement_id))
81 83 elif operation['operation'] == "assign_role":
82 84 if int(operation['frame_id']) in translation['frame_id']:
83 85 frame_id = translation['frame_id'][int(operation['frame_id'])]
... ... @@ -133,6 +135,16 @@ def make_operations(lemma_id, operations):
133 135 remove_preference(frame_id, complement_id, preference_id)
134 136 else:
135 137 pass
  138 +
  139 + for frame_id, complement_id in complements_to_test:
  140 + complements = Complement.objects.filter(id=complement_id)
  141 + if len(complements) > 0:
  142 + complement = complements[0]
  143 + for role in complement.roles.all():
  144 + if role.role == u'Lemma':
  145 + if len(complement.realizations.all()) == 0:
  146 + remove_argument(frame_id, complement_id)
  147 +
136 148  
137 149 def create_frame(entry, luids):
138 150 frame = SemanticFrame(entry=entry)
... ...