Commit e016c6c74fead4a7adee8d078e9afbee17101829

Authored by Bartłomiej Nitoń
2 parents b898170b d566f6f3

Merge branch 'bartek'

Showing 1 changed file with 15 additions and 13 deletions
dictionary/validation.py
... ... @@ -191,19 +191,21 @@ def find_similar_frames(frames):
191 191  
192 192 def check_max_args_coor(frame1, frame2):
193 193 max_occurr = 0
194   - pos_diff1 = frame1.positions.exclude(pk__in=frame2.positions.all())
195   - pos_diff2 = frame2.positions.exclude(pk__in=frame1.positions.all())
196   - if(frame1.positions.count() == frame2.positions.count() and
197   - pos_diff1.count() == 1 and pos_diff2.count() == 1 and
198   - pos_diff1.all()[0].categories.count() == pos_diff2.all()[0].categories.count() and
199   - (pos_diff1.all()[0].categories.all() |
200   - pos_diff2.all()[0].categories.all()).count() == pos_diff1.all()[0].categories.count()):
201   - for phrase_type1 in pos_diff1.all()[0].arguments.all():
202   - for phrase_type2 in pos_diff2.all()[0].arguments.all():
203   - matching_positions = Position.objects.filter(arguments=phrase_type1).filter(arguments=phrase_type2)
204   - occurr = matching_positions.aggregate(Sum('occurrences'))['occurrences__sum']
205   - if occurr and occurr > max_occurr:
206   - max_occurr = occurr
  194 + if frame1.positions.count() == frame2.positions.count():
  195 + frame1_poss_text_reps = [pos.text_rep for pos in frame1.positions.all()]
  196 + frame2_poss_text_reps = [pos.text_rep for pos in frame2.positions.all()]
  197 + pos_diff1 = frame1.positions.exclude(text_rep__in=frame2_poss_text_reps)
  198 + pos_diff2 = frame2.positions.exclude(text_rep__in=frame1_poss_text_reps)
  199 + if(pos_diff1.count() == 1 and pos_diff2.count() == 1 and
  200 + pos_diff1.all()[0].categories.count() == pos_diff2.all()[0].categories.count() and
  201 + (pos_diff1.all()[0].categories.all() |
  202 + pos_diff2.all()[0].categories.all()).count() == pos_diff1.all()[0].categories.count()):
  203 + for phrase_type1 in pos_diff1.all()[0].arguments.all():
  204 + for phrase_type2 in pos_diff2.all()[0].arguments.all():
  205 + matching_positions = Position.objects.filter(arguments=phrase_type1).filter(arguments=phrase_type2)
  206 + occurr = matching_positions.aggregate(Sum('occurrences'))['occurrences__sum']
  207 + if occurr and occurr > max_occurr:
  208 + max_occurr = occurr
207 209 return max_occurr
208 210  
209 211 def check_frames_diff(frame1, frame2):
... ...