Commit 8692f5ffee3faed3f7d05dbd1379ab3c141bde8e

Authored by Bartłomiej Nitoń
1 parent d99b279f

Small fixes for comparing frames methods.

semantics/utils.py
... ... @@ -20,12 +20,17 @@ def get_frames_differences(initial_frames, frames):
20 20 differences['part_matching_frames'].append(miss_frame)
21 21 differences['missing_frames'] = list(set(differences['missing_frames']) - set(differences['part_matching_frames']))
22 22 return differences
23   -
  23 +
24 24 def get_matching_frame(frames, frame_to_find):
25 25 for frame in frames.all():
26   - if frames_match(frame, frame_to_find):
  26 + if lexical_units_match(frame, frame_to_find) and frames_match(frame, frame_to_find):
27 27 return frame
28 28 return None
  29 +
  30 +def lexical_units_match(frame1, frame2):
  31 + if set(frame1.lexical_units.all()) == set(frame2.lexical_units.all()):
  32 + return True
  33 + return False
29 34  
30 35 def frames_match(frame1, frame2):
31 36 complements1 = frame1.complements
... ... @@ -110,7 +115,7 @@ def matching_synset_relation_exists(rel_to_find, relations):
110 115 def get_partially_matching_frames(frames, frame_to_find):
111 116 matching_frames = []
112 117 for frame in frames:
113   - if frames_partially_match(frame, frame_to_find):
  118 + if lexical_units_match(frame, frame_to_find) and frames_partially_match(frame, frame_to_find):
114 119 matching_frames.append(frame)
115 120 return matching_frames
116 121  
... ... @@ -135,3 +140,9 @@ def complements_partially_match(compl1, compl2):
135 140 if roles_match(compl1.roles, compl2.roles):
136 141 return True
137 142 return False
  143 +
  144 +def get_structural_matching_frame(frames, frame_to_find):
  145 + for frame in frames.all():
  146 + if frames_match(frame, frame_to_find):
  147 + return frame
  148 + return None
... ...
semantics/validation.py
... ... @@ -4,7 +4,7 @@ from django.db.models import Max
4 4  
5 5 from dictionary.models import Lemma, reflex_phrase_types, Argument_Model
6 6 from semantics.models import LexicalUnitExamples
7   -from semantics.utils import get_matching_frame
  7 +from semantics.utils import get_structural_matching_frame
8 8  
9 9 def validate_frames(lemma_id):
10 10 lemma = Lemma.objects.get(id=lemma_id)
... ... @@ -90,7 +90,7 @@ def examples_added(frame):
90 90  
91 91 def duplicates_exists(frame, actual_frames):
92 92 frames_to_check = actual_frames.exclude(id=frame.id)
93   - if get_matching_frame(frames_to_check, frame):
  93 + if get_structural_matching_frame(frames_to_check, frame):
94 94 return True
95 95 return False
96 96  
... ...