Commit 932328433e797d19e94632f4e529aa07f1d7d9cc

Authored by Bartłomiej Nitoń
1 parent 32917def

Semantics rconnection bugfix.

dictionary/saving.py
... ... @@ -9,16 +9,17 @@ from wordnet.models import LexicalUnit
9 9 def get_semantic_operations(lemma, schemata_conversions):
10 10 connections = []
11 11 operations = []
  12 + frames = lemma.entry_obj.actual_frames()
12 13 for conv in schemata_conversions:
13   - schema_operations = get_reconnect_operations_and_extend_connections(connections,
  14 + schema_operations = get_reconnect_operations_and_extend_connections(frames,
  15 + connections,
14 16 conv['obj'],
15 17 conv['js'])
16 18 operations.extend(schema_operations)
17   - frames = lemma.entry_obj.actual_frames()
18 19 operations.extend(get_disconnect_operations(frames, connections))
19 20 return operations
20 21  
21   -def get_reconnect_operations_and_extend_connections(connections, schema, js_schema):
  22 +def get_reconnect_operations_and_extend_connections(frames, connections, schema, js_schema):
22 23 operations = []
23 24 used_poss_ids = []
24 25 for js_position in js_schema['positions']:
... ... @@ -29,7 +30,7 @@ def get_reconnect_operations_and_extend_connections(connections, schema, js_sche
29 30 'position': position,
30 31 'phrase_type': phrase_type}
31 32 for conn in js_phrase_type['connections']:
32   - operations.extend(reconnect_operations(conn, new_connection_target))
  33 + operations.extend(reconnect_operations(frames, conn, new_connection_target))
33 34 conn_dict = next((conn_dict
34 35 for conn_dict in connections if conn_dict['compl'] == conn['compl']), None)
35 36 if conn_dict:
... ... @@ -47,10 +48,11 @@ def get_position(schema, js_position, used_poss_ids):
47 48 used_poss_ids.append(position.id)
48 49 return position
49 50  
50   -def reconnect_operations(connection, new_target):
  51 +def reconnect_operations(frames, connection, new_target):
51 52 operations = []
52 53 compl = Complement.objects.get(id=connection['compl'])
53   - arg_ref = create_argument_ref(compl)
  54 + frame = frames.get(complements=compl)
  55 + arg_ref = create_argument_ref(frame, compl)
54 56 for real_id in connection['realizations']:
55 57 realization = compl.realizations.get(id=real_id)
56 58 old_phrase_type_ref = create_phrase_type_ref(realization.frame, realization.position,
... ... @@ -62,9 +64,8 @@ def reconnect_operations(connection, new_target):
62 64 operations.append(create_operation('connect', arg_ref, new_phrase_type_ref))
63 65 return operations
64 66  
65   -def create_argument_ref(complement):
66   - connected_frame = Complement.objects.get(id=complement.id)
67   - return 'frame_%d_comp_%d_' % (connected_frame.id, complement.id)
  67 +def create_argument_ref(frame, complement):
  68 + return 'frame_%d_comp_%d_' % (frame.id, complement.id)
68 69  
69 70 def create_phrase_type_ref(schema, position, phrase_type, alternation):
70 71 return 'schema_%d_pos_%d_arg_%d_alt_%d_' % (schema.id, position.id,
... ... @@ -80,10 +81,10 @@ def get_disconnect_operations(frames, connections):
80 81 conn_dict = next((conn_dict
81 82 for conn_dict in connections if conn_dict['compl'] == compl.id), None)
82 83 for real in compl.realizations.all():
83   - if not real.id in conn_dict['realizations']:
  84 + if not conn_dict or not real.id in conn_dict['realizations']:
84 85 phrase_type_ref = create_phrase_type_ref(real.frame, real.position,
85 86 real.argument, real.alternation)
86   - arg_ref = create_argument_ref(compl)
  87 + arg_ref = create_argument_ref(frame, compl)
87 88 operations.append(create_operation('disconnect', arg_ref, phrase_type_ref))
88 89 return operations
89 90  
... ...
semantics/admin.py
1 1 from django.contrib import admin
2 2  
3 3 from models import FramePosition, GeneralSelectivePreference, LexicalUnitExamples, \
4   - SelectivePreferenceRelations, SemanticRole, SemanticRolesDisplay
  4 + SelectivePreferenceRelations, SemanticFrame, SemanticRole, \
  5 + SemanticRolesDisplay
5 6  
6 7  
7 8  
... ... @@ -11,6 +12,7 @@ class SemanticRoleAdmin(admin.ModelAdmin):
11 12 admin.site.register(FramePosition)
12 13 admin.site.register(GeneralSelectivePreference)
13 14 admin.site.register(LexicalUnitExamples)
  15 +admin.site.register(SemanticFrame)
14 16 admin.site.register(SelectivePreferenceRelations)
15 17 admin.site.register(SemanticRolesDisplay)
16 18 admin.site.register(SemanticRole, SemanticRoleAdmin)
... ...