Commit 9d9ff22d0b8fc159b1fce9ff8f5be2190768705b

Authored by Tomasz Bartosiak
2 parents 8b50dd2f 17e8e780
dictionary/ajax_lemma_view.py
@@ -26,8 +26,8 @@ from dictionary.models import Vocabulary, Lemma, Lemma_Status, Frame_Opinion, \ @@ -26,8 +26,8 @@ from dictionary.models import Vocabulary, Lemma, Lemma_Status, Frame_Opinion, \
26 Frame_Char_Value, Message, Change, Old_Frame, \ 26 Frame_Char_Value, Message, Change, Old_Frame, \
27 B_Frame, Entry, \ 27 B_Frame, Entry, \
28 sorted_default_frame_char_vals, XcpExample, \ 28 sorted_default_frame_char_vals, XcpExample, \
29 - POS, get_frame_char_and_its_value, get_frame_char_by_type_and_value_pk, \  
30 - sortFrameChars, sortArguments, sortPositions, \ 29 + POS, connect_entries, disconnect_entries, entries_related, get_frame_char_and_its_value, \
  30 + get_frame_char_by_type_and_value_pk, sortFrameChars, sortArguments, sortPositions, \
31 get_or_create_position, get_schemata_by_type, pos_compatible 31 get_or_create_position, get_schemata_by_type, pos_compatible
32 from dictionary.forms import AddPositionForm, FrameForm, Pos_Cat_Form, \ 32 from dictionary.forms import AddPositionForm, FrameForm, Pos_Cat_Form, \
33 AddNkjpExampleForm, MessageForm, SortForm, \ 33 AddNkjpExampleForm, MessageForm, SortForm, \
@@ -781,12 +781,8 @@ def check_if_selected_and_get(lemma_id, preview_lemma_id): @@ -781,12 +781,8 @@ def check_if_selected_and_get(lemma_id, preview_lemma_id):
781 return error, lemma, preview_lemma 781 return error, lemma, preview_lemma
782 782
783 def are_entries_related(lemma, preview_lemma): 783 def are_entries_related(lemma, preview_lemma):
784 - related = False  
785 lemma_entry, preview_lemma_entry = get_entries(lemma, preview_lemma) 784 lemma_entry, preview_lemma_entry = get_entries(lemma, preview_lemma)
786 - if (lemma_entry.rel_entries.filter(id=preview_lemma_entry.id).exists() or  
787 - preview_lemma_entry.rel_entries.filter(id=lemma_entry.id).exists()):  
788 - related = True  
789 - return related 785 + return entries_related(lemma_entry, preview_lemma_entry)
790 786
791 def get_entries(lemma, preview_lemma): 787 def get_entries(lemma, preview_lemma):
792 lemma_entry = lemma.entry_obj 788 lemma_entry = lemma.entry_obj
@@ -822,8 +818,7 @@ def check_if_has_rights_to_relate(lemma, user): @@ -822,8 +818,7 @@ def check_if_has_rights_to_relate(lemma, user):
822 818
823 def add_entries_relation(lemma, preview_lemma): 819 def add_entries_relation(lemma, preview_lemma):
824 lemma_entry, preview_lemma_entry = get_entries(lemma, preview_lemma) 820 lemma_entry, preview_lemma_entry = get_entries(lemma, preview_lemma)
825 - lemma_entry.rel_entries.add(preview_lemma_entry)  
826 - preview_lemma_entry.rel_entries.add(lemma_entry) 821 + connect_entries(lemma_entry, preview_lemma_entry)
827 822
828 @ajax(method='post') 823 @ajax(method='post')
829 def disrelate_entries(request, lemma_id, preview_lemma_id): 824 def disrelate_entries(request, lemma_id, preview_lemma_id):
@@ -850,8 +845,7 @@ def check_if_share_sematic_frames(lemma, preview_lemma): @@ -850,8 +845,7 @@ def check_if_share_sematic_frames(lemma, preview_lemma):
850 845
851 def cancel_entries_relation(request, lemma, preview_lemma): 846 def cancel_entries_relation(request, lemma, preview_lemma):
852 lemma_entry, preview_lemma_entry = get_entries(lemma, preview_lemma) 847 lemma_entry, preview_lemma_entry = get_entries(lemma, preview_lemma)
853 - lemma_entry.rel_entries.remove(preview_lemma_entry)  
854 - preview_lemma_entry.rel_entries.remove(lemma_entry) 848 + disconnect_entries(lemma_entry, preview_lemma_entry)
855 849
856 ############################################################# 850 #############################################################
857 @render('skladnica_examples.html') 851 @render('skladnica_examples.html')
@@ -1155,11 +1149,11 @@ def need_conversion(request, from_lemma_id, to_lemma_id): @@ -1155,11 +1149,11 @@ def need_conversion(request, from_lemma_id, to_lemma_id):
1155 1149
1156 def conversion_possible(from_entry, to_entry): 1150 def conversion_possible(from_entry, to_entry):
1157 can_be_converted = False 1151 can_be_converted = False
1158 - if (to_entry.rel_entries.filter(pk=from_entry.pk).exists() and 1152 + if (entries_related(to_entry, from_entry) and
1159 from_entry.pos.tag == 'verb' and 1153 from_entry.pos.tag == 'verb' and
1160 (to_entry.pos.tag == 'noun' or to_entry.pos.tag == 'adj')): 1154 (to_entry.pos.tag == 'noun' or to_entry.pos.tag == 'adj')):
1161 can_be_converted = True 1155 can_be_converted = True
1162 - elif (to_entry.rel_entries.filter(pk=from_entry.pk).exists() and 1156 + elif (entries_related(to_entry, from_entry) and
1163 from_entry.pos.tag == 'adj' and to_entry.pos.tag == 'noun'): 1157 from_entry.pos.tag == 'adj' and to_entry.pos.tag == 'noun'):
1164 can_be_converted = True 1158 can_be_converted = True
1165 return can_be_converted 1159 return can_be_converted
@@ -1637,24 +1631,17 @@ def similar_lemmas_show_synonyms(request, lemma_id): @@ -1637,24 +1631,17 @@ def similar_lemmas_show_synonyms(request, lemma_id):
1637 1631
1638 @ajax(method='post') 1632 @ajax(method='post')
1639 def related_lemmas_show(request, lemma_id): 1633 def related_lemmas_show(request, lemma_id):
1640 - related_lemmas = []  
1641 try: 1634 try:
1642 lemma = Lemma.objects.get(id=lemma_id) 1635 lemma = Lemma.objects.get(id=lemma_id)
1643 except Lemma.DoesNotExist: 1636 except Lemma.DoesNotExist:
1644 raise AjaxError('main lemma not selected') 1637 raise AjaxError('main lemma not selected')
1645 - q_related_lemmas = []  
1646 - try:  
1647 - entry_obj = Entry.objects.get(name=lemma.entry)  
1648 - if entry_obj.rel_entries.exists():  
1649 - for related_lemma in entry_obj.rel_entries.all():  
1650 - q_related_lemmas.append(Q(entry=related_lemma.name))  
1651 - related_lemmas = Lemma.objects.filter(old=False).filter(reduce(operator.or_, q_related_lemmas)).distinct().all()  
1652 - else:  
1653 - related_lemmas = Lemma.objects.none()  
1654 - except Entry.DoesNotExist:  
1655 - pass  
1656 - if len(related_lemmas) > 0:  
1657 - request.session['similar_lemmas'] = related_lemmas 1638 +
  1639 + related_lemmas_pks = []
  1640 + for entry in lemma.entry_obj.related_entries():
  1641 + related_lemmas_pks.append(entry.lemmas.get(old=False).pk)
  1642 +
  1643 + if len(related_lemmas_pks) > 0:
  1644 + request.session['similar_lemmas'] = Lemma.objects.filter(pk__in=related_lemmas_pks)
1658 else: 1645 else:
1659 raise AjaxError('related lemmas not found') 1646 raise AjaxError('related lemmas not found')
1660 return {} 1647 return {}
dictionary/management/commands/add_verbs.py
@@ -6,7 +6,7 @@ import re @@ -6,7 +6,7 @@ import re
6 from django.core.management.base import BaseCommand 6 from django.core.management.base import BaseCommand
7 from lxml import etree 7 from lxml import etree
8 8
9 -from dictionary.models import Entry, Lemma, Lemma_Status, POS, Vocabulary 9 +from dictionary.models import Entry, Lemma, Lemma_Status, POS, Vocabulary, connect_entries
10 10
11 VERBS_IN_DICT = 2000 11 VERBS_IN_DICT = 2000
12 POLANSKI_PATH = 'data/dictionary.xml' 12 POLANSKI_PATH = 'data/dictionary.xml'
@@ -118,8 +118,7 @@ def add_relations_by_verb_entries(entries, relations_path, pos_tag): @@ -118,8 +118,7 @@ def add_relations_by_verb_entries(entries, relations_path, pos_tag):
118 nverb_obj = Lemma.objects.get(old=False, entry=nverb, entry_obj__pos=pos) 118 nverb_obj = Lemma.objects.get(old=False, entry=nverb, entry_obj__pos=pos)
119 nverb_entry = nverb_obj.entry_obj 119 nverb_entry = nverb_obj.entry_obj
120 verb_entry = verb_obj.entry_obj 120 verb_entry = verb_obj.entry_obj
121 - verb_entry.rel_entries.add(nverb_entry)  
122 - nverb_entry.rel_entries.add(verb_entry) 121 + connect_entries(verb_entry, nverb_entry)
123 print line 122 print line
124 except Lemma.DoesNotExist: 123 except Lemma.DoesNotExist:
125 pass 124 pass
dictionary/management/commands/create_derivational_groups.py
@@ -2,7 +2,7 @@ @@ -2,7 +2,7 @@
2 2
3 from django.core.management.base import BaseCommand 3 from django.core.management.base import BaseCommand
4 from dictionary.models import Entry, DerivationalGroup, connect_entries 4 from dictionary.models import Entry, DerivationalGroup, connect_entries
5 -from time import sleep 5 +
6 6
7 class Command(BaseCommand): 7 class Command(BaseCommand):
8 8
@@ -10,7 +10,6 @@ class Command(BaseCommand): @@ -10,7 +10,6 @@ class Command(BaseCommand):
10 create_derivational_groups() 10 create_derivational_groups()
11 11
12 12
13 -  
14 def create_derivational_groups(): 13 def create_derivational_groups():
15 for entry in Entry.objects.all(): 14 for entry in Entry.objects.all():
16 print entry.name 15 print entry.name
dictionary/management/commands/load_entries_relations.py
@@ -4,7 +4,7 @@ import codecs @@ -4,7 +4,7 @@ import codecs
4 4
5 from django.core.management.base import BaseCommand 5 from django.core.management.base import BaseCommand
6 6
7 -from dictionary.models import Lemma, POS, get_or_create_entry 7 +from dictionary.models import Lemma, POS, connect_entries, get_or_create_entry
8 8
9 NOUN_VERB_RELATIONS_PATH = 'data/nverbs/nouns/nouns+verb-freq.txt' 9 NOUN_VERB_RELATIONS_PATH = 'data/nverbs/nouns/nouns+verb-freq.txt'
10 10
@@ -51,8 +51,8 @@ def add_relations(entries_path, pos_tag): @@ -51,8 +51,8 @@ def add_relations(entries_path, pos_tag):
51 # val_entry = Entry(name=entry['entry'], pos=pos) 51 # val_entry = Entry(name=entry['entry'], pos=pos)
52 # val_entry.save() 52 # val_entry.save()
53 verb_entry = verb_obj.entry_obj 53 verb_entry = verb_obj.entry_obj
54 - verb_entry.rel_entries.add(nverb_entry)  
55 - nverb_entry.rel_entries.add(verb_entry) 54 +
  55 + connect_entries(verb_entry, nverb_entry)
56 print line 56 print line
57 except Lemma.DoesNotExist: 57 except Lemma.DoesNotExist:
58 pass 58 pass
@@ -81,8 +81,7 @@ def add_relations_by_nverb_entries(entries, entries_path, from_pos_tag, to_pos_t @@ -81,8 +81,7 @@ def add_relations_by_nverb_entries(entries, entries_path, from_pos_tag, to_pos_t
81 'freq_300M': int(line_ls[2].strip())} 81 'freq_300M': int(line_ls[2].strip())}
82 nverb_entry = nverb_obj.entry_obj 82 nverb_entry = nverb_obj.entry_obj
83 verb_entry = verb_obj.entry_obj 83 verb_entry = verb_obj.entry_obj
84 - verb_entry.rel_entries.add(nverb_entry)  
85 - nverb_entry.rel_entries.add(verb_entry) 84 + connect_entries(verb_entry, nverb_entry)
86 print line 85 print line
87 except Lemma.DoesNotExist: 86 except Lemma.DoesNotExist:
88 pass 87 pass
dictionary/models.py
@@ -1384,7 +1384,7 @@ class Entry(Model): @@ -1384,7 +1384,7 @@ class Entry(Model):
1384 related_name='+') 1384 related_name='+')
1385 der_group = ForeignKey('DerivationalGroup', 1385 der_group = ForeignKey('DerivationalGroup',
1386 null=True, blank=True, 1386 null=True, blank=True,
1387 - related_name='powiazane') 1387 + related_name='entries')
1388 synonyms = ManyToManyField('Entry', db_table='synonimy', 1388 synonyms = ManyToManyField('Entry', db_table='synonimy',
1389 null=True, blank=True, 1389 null=True, blank=True,
1390 related_name='rel_synonyms') 1390 related_name='rel_synonyms')
@@ -1405,6 +1405,18 @@ class Entry(Model): @@ -1405,6 +1405,18 @@ class Entry(Model):
1405 ('view_semantics', u'Moลผe oglฤ…daฤ‡ semantykฤ™.'), 1405 ('view_semantics', u'Moลผe oglฤ…daฤ‡ semantykฤ™.'),
1406 ) 1406 )
1407 1407
  1408 + def all_der_entries(self):
  1409 + rel_entries = Entry.objects.none()
  1410 + if self.der_group is not None:
  1411 + rel_entries = self.der_group.entries.all()
  1412 + return rel_entries
  1413 +
  1414 + def related_entries(self):
  1415 + rel_entries = Entry.objects.none()
  1416 + if self.der_group is not None:
  1417 + rel_entries = self.der_group.entries.exclude(pk=self.pk)
  1418 + return rel_entries
  1419 +
1408 def related_frames(self): 1420 def related_frames(self):
1409 visible = self.visible_frames() 1421 visible = self.visible_frames()
1410 actual = self.actual_frames() 1422 actual = self.actual_frames()
@@ -1424,8 +1436,8 @@ class Entry(Model): @@ -1424,8 +1436,8 @@ class Entry(Model):
1424 return get_model('semantics', 'SemanticFrame').objects.filter(pk__in=frames) 1436 return get_model('semantics', 'SemanticFrame').objects.filter(pk__in=frames)
1425 1437
1426 def all_frames(self): 1438 def all_frames(self):
1427 - frames = self.actual_frames()  
1428 - for entry in self.rel_entries.all(): 1439 + frames = get_model('semantics', 'SemanticFrame').objects.none()
  1440 + for entry in self.all_der_entries():
1429 new_frames = entry.actual_frames() 1441 new_frames = entry.actual_frames()
1430 frames |= new_frames 1442 frames |= new_frames
1431 return get_model('semantics', 'SemanticFrame').objects.filter(pk__in=frames) 1443 return get_model('semantics', 'SemanticFrame').objects.filter(pk__in=frames)
@@ -1490,7 +1502,7 @@ def connect_entries(entry1, entry2): @@ -1490,7 +1502,7 @@ def connect_entries(entry1, entry2):
1490 if entry1.der_group is not None: 1502 if entry1.der_group is not None:
1491 if entry2.der_group is not None: 1503 if entry2.der_group is not None:
1492 if entry1.der_group.id != entry2.der_group.id: 1504 if entry1.der_group.id != entry2.der_group.id:
1493 - entries = entry2.der_group.powiazane.all() 1505 + entries = entry2.der_group.entries.all()
1494 der_group = entry2.der_group 1506 der_group = entry2.der_group
1495 for entry in entries: 1507 for entry in entries:
1496 entry.der_group = entry1.der_group 1508 entry.der_group = entry1.der_group
@@ -1511,10 +1523,14 @@ def connect_entries(entry1, entry2): @@ -1511,10 +1523,14 @@ def connect_entries(entry1, entry2):
1511 entry2.save() 1523 entry2.save()
1512 1524
1513 def disconnect_entries(entry1, entry2): 1525 def disconnect_entries(entry1, entry2):
1514 - if entry1.der_group.id == entry2.der_group.id: 1526 + if entries_related(entry1, entry2):
1515 entry2.der_group = None 1527 entry2.der_group = None
1516 entry2.save() 1528 entry2.save()
1517 - 1529 +
  1530 +def entries_related(entry1, entry2):
  1531 + if entry1.der_group is None or entry2.der_group is None:
  1532 + return False
  1533 + return entry1.der_group == entry2.der_group
1518 1534
1519 class POS(Model): 1535 class POS(Model):
1520 tag = CharField(max_length=16, db_column='tag', unique=True) 1536 tag = CharField(max_length=16, db_column='tag', unique=True)
dictionary/saving.py
@@ -6,25 +6,25 @@ from semantics.models import Complement, LexicalUnitExamples @@ -6,25 +6,25 @@ from semantics.models import Complement, LexicalUnitExamples
6 from semantics.saving import modify_frames, update_meanings 6 from semantics.saving import modify_frames, update_meanings
7 from wordnet.models import LexicalUnit 7 from wordnet.models import LexicalUnit
8 8
  9 +
9 def get_semantic_operations(lemma, schemata_conversions): 10 def get_semantic_operations(lemma, schemata_conversions):
10 connections = [] 11 connections = []
11 operations = [] 12 operations = []
12 13
13 - frames = lemma.entry_obj.visible_frames()  
14 -  
15 for conv in schemata_conversions: 14 for conv in schemata_conversions:
16 - schema_operations = get_reconnect_operations_and_extend_connections(frames, 15 + schema_operations = get_reconnect_operations_and_extend_connections(lemma,
17 connections, 16 connections,
18 conv['obj'], 17 conv['obj'],
19 conv['js']) 18 conv['js'])
20 operations.extend(schema_operations) 19 operations.extend(schema_operations)
21 - operations.extend(get_disconnect_operations(lemma, frames, connections)) 20 + operations.extend(get_disconnect_operations(lemma, connections))
22 21
23 return operations 22 return operations
24 -  
25 -def get_reconnect_operations_and_extend_connections(frames, connections, schema, js_schema): 23 +
  24 +
  25 +def get_reconnect_operations_and_extend_connections(lemma, connections, schema, js_schema):
26 operations = [] 26 operations = []
27 - used_poss_ids = [] 27 + used_poss_ids = []
28 for js_position in js_schema['positions']: 28 for js_position in js_schema['positions']:
29 if len(js_position['arguments']) > 0: 29 if len(js_position['arguments']) > 0:
30 position = get_position(schema, js_position, used_poss_ids) 30 position = get_position(schema, js_position, used_poss_ids)
@@ -34,7 +34,7 @@ def get_reconnect_operations_and_extend_connections(frames, connections, schema, @@ -34,7 +34,7 @@ def get_reconnect_operations_and_extend_connections(frames, connections, schema,
34 'position': position, 34 'position': position,
35 'phrase_type': phrase_type} 35 'phrase_type': phrase_type}
36 for conn in js_phrase_type['connections']: 36 for conn in js_phrase_type['connections']:
37 - operations.extend(reconnect_operations(frames, conn, new_connection_target)) 37 + operations.extend(reconnect_operations(lemma, conn, new_connection_target))
38 conn_dict = next((conn_dict 38 conn_dict = next((conn_dict
39 for conn_dict in connections if conn_dict['compl'] == conn['compl']), None) 39 for conn_dict in connections if conn_dict['compl'] == conn['compl']), None)
40 if conn_dict: 40 if conn_dict:
@@ -44,6 +44,7 @@ def get_reconnect_operations_and_extend_connections(frames, connections, schema, @@ -44,6 +44,7 @@ def get_reconnect_operations_and_extend_connections(frames, connections, schema,
44 'realizations': conn['realizations']}) 44 'realizations': conn['realizations']})
45 return operations 45 return operations
46 46
  47 +
47 def get_position(schema, js_position, used_poss_ids): 48 def get_position(schema, js_position, used_poss_ids):
48 position = jsPosToObj(js_position) 49 position = jsPosToObj(js_position)
49 same_poss = schema.positions.filter(text_rep=position.text_rep) 50 same_poss = schema.positions.filter(text_rep=position.text_rep)
@@ -52,10 +53,13 @@ def get_position(schema, js_position, used_poss_ids): @@ -52,10 +53,13 @@ def get_position(schema, js_position, used_poss_ids):
52 used_poss_ids.append(position.id) 53 used_poss_ids.append(position.id)
53 return position 54 return position
54 55
55 -def reconnect_operations(frames, connection, new_target): 56 +
  57 +def reconnect_operations(lemma, connection, new_target):
56 operations = [] 58 operations = []
  59 + visible_frames = lemma.entry_obj.visible_frames()
  60 + shared_schemata_ids = get_shared_schemata_ids(lemma)
57 compl = Complement.objects.get(id=connection['compl']) 61 compl = Complement.objects.get(id=connection['compl'])
58 - frame = frames.get(complements=compl) 62 + frame = visible_frames.get(complements=compl)
59 arg_ref = create_argument_ref(frame, compl) 63 arg_ref = create_argument_ref(frame, compl)
60 for real_id in connection['realizations']: 64 for real_id in connection['realizations']:
61 realization = compl.realizations.get(id=real_id) 65 realization = compl.realizations.get(id=real_id)
@@ -64,26 +68,31 @@ def reconnect_operations(frames, connection, new_target): @@ -64,26 +68,31 @@ def reconnect_operations(frames, connection, new_target):
64 new_phrase_type_ref = create_phrase_type_ref(new_target['schema'], new_target['position'], 68 new_phrase_type_ref = create_phrase_type_ref(new_target['schema'], new_target['position'],
65 new_target['phrase_type'], realization.alternation) 69 new_target['phrase_type'], realization.alternation)
66 if new_phrase_type_ref != old_phrase_type_ref: 70 if new_phrase_type_ref != old_phrase_type_ref:
67 - operations.append(create_operation('disconnect', arg_ref, old_phrase_type_ref)) 71 + if realization.frame.id not in shared_schemata_ids:
  72 + operations.append(create_operation('disconnect', arg_ref, old_phrase_type_ref))
68 operations.append(create_operation('connect', arg_ref, new_phrase_type_ref)) 73 operations.append(create_operation('connect', arg_ref, new_phrase_type_ref))
69 return operations 74 return operations
70 - 75 +
  76 +
71 def create_argument_ref(frame, complement): 77 def create_argument_ref(frame, complement):
72 return 'frame_%d_comp_%d_' % (frame.id, complement.id) 78 return 'frame_%d_comp_%d_' % (frame.id, complement.id)
73 - 79 +
  80 +
74 def create_phrase_type_ref(schema, position, phrase_type, alternation): 81 def create_phrase_type_ref(schema, position, phrase_type, alternation):
75 return 'schema_%d_pos_%d_arg_%d_alt_%d_' % (schema.id, position.id, 82 return 'schema_%d_pos_%d_arg_%d_alt_%d_' % (schema.id, position.id,
76 phrase_type.id, alternation) 83 phrase_type.id, alternation)
77 84
  85 +
78 def create_operation(operation, arg_ref, phrase_type_ref): 86 def create_operation(operation, arg_ref, phrase_type_ref):
79 return {'operation': operation, 'arg': arg_ref, 'connect': phrase_type_ref} 87 return {'operation': operation, 'arg': arg_ref, 'connect': phrase_type_ref}
80 88
81 -def get_disconnect_operations(lemma, frames, connections): 89 +
  90 +def get_disconnect_operations(lemma, connections):
82 operations = [] 91 operations = []
83 shared_schemata_ids = get_shared_schemata_ids(lemma) 92 shared_schemata_ids = get_shared_schemata_ids(lemma)
84 - for frame in frames: 93 + for frame in lemma.entry_obj.visible_frames():
85 for compl in frame.complements.all(): 94 for compl in frame.complements.all():
86 - conn_dict = next((conn_dict 95 + conn_dict = next((conn_dict
87 for conn_dict in connections if conn_dict['compl'] == compl.id), None) 96 for conn_dict in connections if conn_dict['compl'] == compl.id), None)
88 for real in compl.realizations.all(): 97 for real in compl.realizations.all():
89 if real.frame.id not in shared_schemata_ids: 98 if real.frame.id not in shared_schemata_ids:
@@ -94,16 +103,19 @@ def get_disconnect_operations(lemma, frames, connections): @@ -94,16 +103,19 @@ def get_disconnect_operations(lemma, frames, connections):
94 operations.append(create_operation('disconnect', arg_ref, phrase_type_ref)) 103 operations.append(create_operation('disconnect', arg_ref, phrase_type_ref))
95 return operations 104 return operations
96 105
  106 +
97 def get_shared_schemata_ids(lemma): 107 def get_shared_schemata_ids(lemma):
98 ids = [f.id for f in lemma.frames.all()] 108 ids = [f.id for f in lemma.frames.all()]
99 - for connected in lemma.entry_obj.rel_entries.all(): 109 + for connected in lemma.entry_obj.related_entries():
100 if connected.defined(): 110 if connected.defined():
101 ids += [f.id for f in connected.actual_lemma().frames.all()] 111 ids += [f.id for f in connected.actual_lemma().frames.all()]
102 return ids 112 return ids
103 113
  114 +
104 def update_connections(lemma_id, reconnect_operations, user): 115 def update_connections(lemma_id, reconnect_operations, user):
105 modify_frames(lemma_id, reconnect_operations, user) 116 modify_frames(lemma_id, reconnect_operations, user)
106 117
  118 +
107 def disconnect_all_examples_operations(lemma): 119 def disconnect_all_examples_operations(lemma):
108 operations = [] 120 operations = []
109 lex_units = lemma.entry_obj.meanings.all() 121 lex_units = lemma.entry_obj.meanings.all()
@@ -116,13 +128,16 @@ def disconnect_all_examples_operations(lemma): @@ -116,13 +128,16 @@ def disconnect_all_examples_operations(lemma):
116 'example': example.id}) 128 'example': example.id})
117 return operations 129 return operations
118 130
  131 +
119 def connect_example_operation(example_dict, example_obj): 132 def connect_example_operation(example_dict, example_obj):
120 lu = LexicalUnit.objects.get(id=example_dict['lexical_unit']) 133 lu = LexicalUnit.objects.get(id=example_dict['lexical_unit'])
121 return {'operation': 'add_example', 'unit': lu.id, 'example': example_obj.id} 134 return {'operation': 'add_example', 'unit': lu.id, 'example': example_obj.id}
122 135
  136 +
123 def disconnect_example_operation(example_dict, example_obj): 137 def disconnect_example_operation(example_dict, example_obj):
124 lu = LexicalUnit.objects.get(id=example_dict['lexical_unit']) 138 lu = LexicalUnit.objects.get(id=example_dict['lexical_unit'])
125 return {'operation': 'remove_example', 'unit': lu.id, 'example': example_obj.id} 139 return {'operation': 'remove_example', 'unit': lu.id, 'example': example_obj.id}
126 140
  141 +
127 def reconnect_examples(lemma, operations): 142 def reconnect_examples(lemma, operations):
128 update_meanings(lemma.id, operations) 143 update_meanings(lemma.id, operations)
dictionary/validation.py
@@ -239,7 +239,7 @@ def get_deriv_miss_frames(lemma): @@ -239,7 +239,7 @@ def get_deriv_miss_frames(lemma):
239 239
240 def get_deriv_related_lemmas(entry): 240 def get_deriv_related_lemmas(entry):
241 deriv_related_lemmas = [] 241 deriv_related_lemmas = []
242 - for rel_entry in entry.rel_entries.order_by('name'): 242 + for rel_entry in entry.related_entries.order_by('name'):
243 try: 243 try:
244 rel_lemma = Lemma.objects.get(entry_obj=rel_entry, old=False) 244 rel_lemma = Lemma.objects.get(entry_obj=rel_entry, old=False)
245 deriv_related_lemmas.append(rel_lemma) 245 deriv_related_lemmas.append(rel_lemma)
semantics/management/commands/adjectives_todo.py
@@ -28,7 +28,7 @@ def adj_todo(): @@ -28,7 +28,7 @@ def adj_todo():
28 except ObjectDoesNotExist: 28 except ObjectDoesNotExist:
29 continue 29 continue
30 30
31 - rel_entries = entry.rel_entries.filter(pos__tag=REL_POS) 31 + rel_entries = entry.related_entries().filter(pos__tag=REL_POS)
32 for rel_entry in rel_entries: 32 for rel_entry in rel_entries:
33 if rel_entry.actual_lemma().status.status == REL_STATUS: 33 if rel_entry.actual_lemma().status.status == REL_STATUS:
34 print entry.name, ' ', entry.actual_lemma().status.status, '\t->\t', rel_entry.name, ' ', rel_entry.actual_lemma().status.status 34 print entry.name, ' ', entry.actual_lemma().status.status, '\t->\t', rel_entry.name, ' ', rel_entry.actual_lemma().status.status
semantics/management/commands/nouns_semantics_todo.py
1 #! /usr/bin/python 1 #! /usr/bin/python
2 # -*- coding: utf-8 -*- 2 # -*- coding: utf-8 -*-
3 3
4 -import sys, os, codecs  
5 -  
6 from django.core.management.base import BaseCommand 4 from django.core.management.base import BaseCommand
7 5
8 from django.core.exceptions import ObjectDoesNotExist 6 from django.core.exceptions import ObjectDoesNotExist
9 from dictionary.models import Entry, POS 7 from dictionary.models import Entry, POS
10 -from wordnet.models import LexicalUnit  
11 -from settings import PROJECT_PATH 8 +
12 9
13 class Command(BaseCommand): 10 class Command(BaseCommand):
14 args = 'none' 11 args = 'none'
@@ -17,6 +14,7 @@ class Command(BaseCommand): @@ -17,6 +14,7 @@ class Command(BaseCommand):
17 def handle(self, **options): 14 def handle(self, **options):
18 nouns_todo() 15 nouns_todo()
19 16
  17 +
20 def nouns_todo(): 18 def nouns_todo():
21 noun = POS.objects.get(tag='noun') 19 noun = POS.objects.get(tag='noun')
22 verb = POS.objects.get(tag='verb') 20 verb = POS.objects.get(tag='verb')
@@ -27,7 +25,7 @@ def nouns_todo(): @@ -27,7 +25,7 @@ def nouns_todo():
27 except ObjectDoesNotExist: 25 except ObjectDoesNotExist:
28 continue 26 continue
29 if entry.actual_lemma().status.priority == 40: 27 if entry.actual_lemma().status.priority == 40:
30 - rel_entries = entry.rel_entries.filter(pos=verb) 28 + rel_entries = entry.related_entries().filter(pos=verb)
31 for rel_entry in rel_entries: 29 for rel_entry in rel_entries:
32 try: 30 try:
33 temp = entry.actual_lemma() 31 temp = entry.actual_lemma()
@@ -35,4 +33,3 @@ def nouns_todo(): @@ -35,4 +33,3 @@ def nouns_todo():
35 continue 33 continue
36 if rel_entry.actual_lemma().status.priority >= 90: 34 if rel_entry.actual_lemma().status.priority >= 90:
37 print entry.name, ' ', entry.actual_lemma().status.status, '\t->\t', rel_entry.name, ' ', rel_entry.actual_lemma().status.status 35 print entry.name, ' ', entry.actual_lemma().status.status, '\t->\t', rel_entry.name, ' ', rel_entry.actual_lemma().status.status
38 -  
semantics/management/commands/nouns_syntax_todo.py
1 #! /usr/bin/python 1 #! /usr/bin/python
2 # -*- coding: utf-8 -*- 2 # -*- coding: utf-8 -*-
3 3
4 -import sys, os, codecs  
5 -  
6 from django.core.management.base import BaseCommand 4 from django.core.management.base import BaseCommand
7 5
8 from django.core.exceptions import ObjectDoesNotExist 6 from django.core.exceptions import ObjectDoesNotExist
9 from dictionary.models import Entry, POS 7 from dictionary.models import Entry, POS
10 -from wordnet.models import LexicalUnit  
11 -from settings import PROJECT_PATH 8 +
12 9
13 class Command(BaseCommand): 10 class Command(BaseCommand):
14 args = 'none' 11 args = 'none'
@@ -17,6 +14,7 @@ class Command(BaseCommand): @@ -17,6 +14,7 @@ class Command(BaseCommand):
17 def handle(self, **options): 14 def handle(self, **options):
18 nouns_todo() 15 nouns_todo()
19 16
  17 +
20 def nouns_todo(): 18 def nouns_todo():
21 noun = POS.objects.get(tag='noun') 19 noun = POS.objects.get(tag='noun')
22 verb = POS.objects.get(tag='verb') 20 verb = POS.objects.get(tag='verb')
@@ -27,7 +25,7 @@ def nouns_todo(): @@ -27,7 +25,7 @@ def nouns_todo():
27 except ObjectDoesNotExist: 25 except ObjectDoesNotExist:
28 continue 26 continue
29 if entry.actual_lemma().status.priority == 10: 27 if entry.actual_lemma().status.priority == 10:
30 - rel_entries = entry.rel_entries.filter(pos=verb) 28 + rel_entries = entry.related_entries().filter(pos=verb)
31 for rel_entry in rel_entries: 29 for rel_entry in rel_entries:
32 try: 30 try:
33 temp = entry.actual_lemma() 31 temp = entry.actual_lemma()
@@ -35,4 +33,3 @@ def nouns_todo(): @@ -35,4 +33,3 @@ def nouns_todo():
35 continue 33 continue
36 if rel_entry.actual_lemma().status.priority >= 90: 34 if rel_entry.actual_lemma().status.priority >= 90:
37 print entry.name, ' ', entry.actual_lemma().status.status, '\t->\t', rel_entry.name, ' ', rel_entry.actual_lemma().status.status 35 print entry.name, ' ', entry.actual_lemma().status.status, '\t->\t', rel_entry.name, ' ', rel_entry.actual_lemma().status.status
38 -  
semantics/management/commands/nouns_todo.py
1 #! /usr/bin/python 1 #! /usr/bin/python
2 # -*- coding: utf-8 -*- 2 # -*- coding: utf-8 -*-
3 3
4 -import sys, os, codecs  
5 -  
6 from django.core.management.base import BaseCommand 4 from django.core.management.base import BaseCommand
7 5
8 from django.core.exceptions import ObjectDoesNotExist 6 from django.core.exceptions import ObjectDoesNotExist
9 from dictionary.models import Entry, POS 7 from dictionary.models import Entry, POS
10 -from wordnet.models import LexicalUnit  
11 -from settings import PROJECT_PATH 8 +
12 9
13 class Command(BaseCommand): 10 class Command(BaseCommand):
14 args = 'none' 11 args = 'none'
@@ -17,6 +14,7 @@ class Command(BaseCommand): @@ -17,6 +14,7 @@ class Command(BaseCommand):
17 def handle(self, **options): 14 def handle(self, **options):
18 nouns_todo() 15 nouns_todo()
19 16
  17 +
20 def nouns_todo(): 18 def nouns_todo():
21 noun = POS.objects.get(tag='noun') 19 noun = POS.objects.get(tag='noun')
22 entries = Entry.objects.filter(pos=noun).order_by('name') 20 entries = Entry.objects.filter(pos=noun).order_by('name')
@@ -26,8 +24,7 @@ def nouns_todo(): @@ -26,8 +24,7 @@ def nouns_todo():
26 except ObjectDoesNotExist: 24 except ObjectDoesNotExist:
27 continue 25 continue
28 if entry.actual_lemma().status.priority == 40: 26 if entry.actual_lemma().status.priority == 40:
29 - rel_entries = entry.rel_entries.all() 27 + rel_entries = entry.related_entries().all()
30 for rel_entry in rel_entries: 28 for rel_entry in rel_entries:
31 if rel_entry.actual_lemma().status.priority >= 90: 29 if rel_entry.actual_lemma().status.priority >= 90:
32 print entry.name, ' ', entry.actual_lemma().status.status, '\t->\t', rel_entry.name, ' ', rel_entry.actual_lemma().status.status 30 print entry.name, ' ', entry.actual_lemma().status.status, '\t->\t', rel_entry.name, ' ', rel_entry.actual_lemma().status.status
33 -  
semantics/management/commands/validate_semantics.py 0 โ†’ 100644
  1 +from django.core.management.base import BaseCommand
  2 +
  3 +from dictionary.models import Lemma
  4 +from semantics.validation import validate_schemas
  5 +
  6 +
  7 +class Command(BaseCommand):
  8 + args = 'none'
  9 + help = ""
  10 +
  11 + def handle(self, **options):
  12 + # validate_schemata()
  13 + find_related_entries_potential_errors()
  14 +
  15 +
  16 +def validate_schemata():
  17 + lemmas = Lemma.objects.filter(old=False).order_by('entry_obj__name')
  18 + for lemma in lemmas:
  19 + if lemma.semantics_ready():
  20 + error_msg = validate_schemas(lemma.id)
  21 + if error_msg:
  22 + print (u'%s' % lemma.entry_obj.name)
  23 +
  24 +
  25 +def find_related_entries_potential_errors():
  26 + errors = []
  27 + lemmas = Lemma.objects.filter(old=False).order_by('entry_obj__name')
  28 + for lemma in lemmas:
  29 + for rel_entry in lemma.entry_obj.related_entries().all():
  30 + potential_error = u'%s <--> %s' % (lemma.entry_obj.name, rel_entry.name)
  31 + potential_error_reverse = u'%s <--> %s' % (rel_entry.name, lemma.entry_obj.name)
  32 + if (potential_error not in errors and potential_error_reverse not in errors
  33 + and has_same_schemata_in_history(lemma.entry_obj, rel_entry)):
  34 + errors.append(potential_error)
  35 + print (potential_error)
  36 +
  37 +
  38 +def has_same_schemata_in_history(entry1, entry2):
  39 + for lemma1 in entry1.lemmas.all():
  40 + for lemma2 in entry2.lemmas.all():
  41 + if lemma1.frames.filter(pk__in=lemma2.frames.all()).exists():
  42 + return True
  43 + return False
semantics/management/commands/verbs_semantics_todo.py
1 #! /usr/bin/python 1 #! /usr/bin/python
2 # -*- coding: utf-8 -*- 2 # -*- coding: utf-8 -*-
3 3
4 -import sys, os, codecs  
5 -  
6 from django.core.management.base import BaseCommand 4 from django.core.management.base import BaseCommand
7 5
8 from django.core.exceptions import ObjectDoesNotExist 6 from django.core.exceptions import ObjectDoesNotExist
9 from dictionary.models import Entry, POS 7 from dictionary.models import Entry, POS
10 -from wordnet.models import LexicalUnit  
11 -from settings import PROJECT_PATH 8 +
12 9
13 class Command(BaseCommand): 10 class Command(BaseCommand):
14 args = 'none' 11 args = 'none'
@@ -17,6 +14,7 @@ class Command(BaseCommand): @@ -17,6 +14,7 @@ class Command(BaseCommand):
17 def handle(self, **options): 14 def handle(self, **options):
18 nouns_todo() 15 nouns_todo()
19 16
  17 +
20 def nouns_todo(): 18 def nouns_todo():
21 verb = POS.objects.get(tag='verb') 19 verb = POS.objects.get(tag='verb')
22 noun = POS.objects.get(tag='noun') 20 noun = POS.objects.get(tag='noun')
@@ -27,7 +25,7 @@ def nouns_todo(): @@ -27,7 +25,7 @@ def nouns_todo():
27 except ObjectDoesNotExist: 25 except ObjectDoesNotExist:
28 continue 26 continue
29 if entry.actual_lemma().status.priority == 40 or entry.actual_lemma().status.priority == 70: 27 if entry.actual_lemma().status.priority == 40 or entry.actual_lemma().status.priority == 70:
30 - rel_entries = entry.rel_entries.filter(pos=noun) 28 + rel_entries = entry.related_entries().filter(pos=noun)
31 for rel_entry in rel_entries: 29 for rel_entry in rel_entries:
32 try: 30 try:
33 temp = rel_entry.actual_lemma() 31 temp = rel_entry.actual_lemma()
@@ -35,4 +33,3 @@ def nouns_todo(): @@ -35,4 +33,3 @@ def nouns_todo():
35 continue 33 continue
36 if rel_entry.actual_lemma().status.priority == 40: 34 if rel_entry.actual_lemma().status.priority == 40:
37 print entry.name, ' ', entry.actual_lemma().status.status, '\t->\t', rel_entry.name, ' ', rel_entry.actual_lemma().status.status 35 print entry.name, ' ', entry.actual_lemma().status.status, '\t->\t', rel_entry.name, ' ', rel_entry.actual_lemma().status.status
38 -  
semantics/views.py
@@ -83,7 +83,6 @@ def ajax_frames(request, lemma_id): @@ -83,7 +83,6 @@ def ajax_frames(request, lemma_id):
83 83
84 def create_frames_context(lemma_id, user): 84 def create_frames_context(lemma_id, user):
85 lemma = Lemma.objects.get(id=lemma_id) 85 lemma = Lemma.objects.get(id=lemma_id)
86 - connected = lemma.entry_obj.rel_entries.all()  
87 86
88 #lexical_units = LexicalUnit.objects.filter(Q(base__startswith=lemma.entry + u' ')|Q(base__contains=u' '+lemma.entry+u' ')|Q(base__endswith=u' '+lemma.entry)|Q(base=lemma.entry)).order_by('sense') 87 #lexical_units = LexicalUnit.objects.filter(Q(base__startswith=lemma.entry + u' ')|Q(base__contains=u' '+lemma.entry+u' ')|Q(base__endswith=u' '+lemma.entry)|Q(base=lemma.entry)).order_by('sense')
89 # lexical_units = lemma.entry_obj.meanings.order_by('sense') 88 # lexical_units = lemma.entry_obj.meanings.order_by('sense')
@@ -280,7 +279,7 @@ def ajax_connected(request, lemma_id): @@ -280,7 +279,7 @@ def ajax_connected(request, lemma_id):
280 279
281 def create_connected_context(lemma_id, user): 280 def create_connected_context(lemma_id, user):
282 lemma = Lemma.objects.get(id=lemma_id) 281 lemma = Lemma.objects.get(id=lemma_id)
283 - connected = lemma.entry_obj.rel_entries.all() 282 + connected = lemma.entry_obj.related_entries().all()
284 context = {'frames_display': [], 'connections':{'connected_reverse': [], 'connected': []}} 283 context = {'frames_display': [], 'connections':{'connected_reverse': [], 'connected': []}}
285 284
286 for entry in connected: 285 for entry in connected: