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 26 Frame_Char_Value, Message, Change, Old_Frame, \
27 27 B_Frame, Entry, \
28 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 31 get_or_create_position, get_schemata_by_type, pos_compatible
32 32 from dictionary.forms import AddPositionForm, FrameForm, Pos_Cat_Form, \
33 33 AddNkjpExampleForm, MessageForm, SortForm, \
... ... @@ -781,12 +781,8 @@ def check_if_selected_and_get(lemma_id, preview_lemma_id):
781 781 return error, lemma, preview_lemma
782 782  
783 783 def are_entries_related(lemma, preview_lemma):
784   - related = False
785 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 787 def get_entries(lemma, preview_lemma):
792 788 lemma_entry = lemma.entry_obj
... ... @@ -822,8 +818,7 @@ def check_if_has_rights_to_relate(lemma, user):
822 818  
823 819 def add_entries_relation(lemma, preview_lemma):
824 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 823 @ajax(method='post')
829 824 def disrelate_entries(request, lemma_id, preview_lemma_id):
... ... @@ -850,8 +845,7 @@ def check_if_share_sematic_frames(lemma, preview_lemma):
850 845  
851 846 def cancel_entries_relation(request, lemma, preview_lemma):
852 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 851 @render('skladnica_examples.html')
... ... @@ -1155,11 +1149,11 @@ def need_conversion(request, from_lemma_id, to_lemma_id):
1155 1149  
1156 1150 def conversion_possible(from_entry, to_entry):
1157 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 1153 from_entry.pos.tag == 'verb' and
1160 1154 (to_entry.pos.tag == 'noun' or to_entry.pos.tag == 'adj')):
1161 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 1157 from_entry.pos.tag == 'adj' and to_entry.pos.tag == 'noun'):
1164 1158 can_be_converted = True
1165 1159 return can_be_converted
... ... @@ -1637,24 +1631,17 @@ def similar_lemmas_show_synonyms(request, lemma_id):
1637 1631  
1638 1632 @ajax(method='post')
1639 1633 def related_lemmas_show(request, lemma_id):
1640   - related_lemmas = []
1641 1634 try:
1642 1635 lemma = Lemma.objects.get(id=lemma_id)
1643 1636 except Lemma.DoesNotExist:
1644 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 1645 else:
1659 1646 raise AjaxError('related lemmas not found')
1660 1647 return {}
... ...
dictionary/management/commands/add_verbs.py
... ... @@ -6,7 +6,7 @@ import re
6 6 from django.core.management.base import BaseCommand
7 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 11 VERBS_IN_DICT = 2000
12 12 POLANSKI_PATH = 'data/dictionary.xml'
... ... @@ -118,8 +118,7 @@ def add_relations_by_verb_entries(entries, relations_path, pos_tag):
118 118 nverb_obj = Lemma.objects.get(old=False, entry=nverb, entry_obj__pos=pos)
119 119 nverb_entry = nverb_obj.entry_obj
120 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 122 print line
124 123 except Lemma.DoesNotExist:
125 124 pass
... ...
dictionary/management/commands/create_derivational_groups.py
... ... @@ -2,7 +2,7 @@
2 2  
3 3 from django.core.management.base import BaseCommand
4 4 from dictionary.models import Entry, DerivationalGroup, connect_entries
5   -from time import sleep
  5 +
6 6  
7 7 class Command(BaseCommand):
8 8  
... ... @@ -10,7 +10,6 @@ class Command(BaseCommand):
10 10 create_derivational_groups()
11 11  
12 12  
13   -
14 13 def create_derivational_groups():
15 14 for entry in Entry.objects.all():
16 15 print entry.name
... ...
dictionary/management/commands/load_entries_relations.py
... ... @@ -4,7 +4,7 @@ import codecs
4 4  
5 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 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 51 # val_entry = Entry(name=entry['entry'], pos=pos)
52 52 # val_entry.save()
53 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 56 print line
57 57 except Lemma.DoesNotExist:
58 58 pass
... ... @@ -81,8 +81,7 @@ def add_relations_by_nverb_entries(entries, entries_path, from_pos_tag, to_pos_t
81 81 'freq_300M': int(line_ls[2].strip())}
82 82 nverb_entry = nverb_obj.entry_obj
83 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 85 print line
87 86 except Lemma.DoesNotExist:
88 87 pass
... ...
dictionary/models.py
... ... @@ -1384,7 +1384,7 @@ class Entry(Model):
1384 1384 related_name='+')
1385 1385 der_group = ForeignKey('DerivationalGroup',
1386 1386 null=True, blank=True,
1387   - related_name='powiazane')
  1387 + related_name='entries')
1388 1388 synonyms = ManyToManyField('Entry', db_table='synonimy',
1389 1389 null=True, blank=True,
1390 1390 related_name='rel_synonyms')
... ... @@ -1405,6 +1405,18 @@ class Entry(Model):
1405 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 1420 def related_frames(self):
1409 1421 visible = self.visible_frames()
1410 1422 actual = self.actual_frames()
... ... @@ -1424,8 +1436,8 @@ class Entry(Model):
1424 1436 return get_model('semantics', 'SemanticFrame').objects.filter(pk__in=frames)
1425 1437  
1426 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 1441 new_frames = entry.actual_frames()
1430 1442 frames |= new_frames
1431 1443 return get_model('semantics', 'SemanticFrame').objects.filter(pk__in=frames)
... ... @@ -1490,7 +1502,7 @@ def connect_entries(entry1, entry2):
1490 1502 if entry1.der_group is not None:
1491 1503 if entry2.der_group is not None:
1492 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 1506 der_group = entry2.der_group
1495 1507 for entry in entries:
1496 1508 entry.der_group = entry1.der_group
... ... @@ -1511,10 +1523,14 @@ def connect_entries(entry1, entry2):
1511 1523 entry2.save()
1512 1524  
1513 1525 def disconnect_entries(entry1, entry2):
1514   - if entry1.der_group.id == entry2.der_group.id:
  1526 + if entries_related(entry1, entry2):
1515 1527 entry2.der_group = None
1516 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 1535 class POS(Model):
1520 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 6 from semantics.saving import modify_frames, update_meanings
7 7 from wordnet.models import LexicalUnit
8 8  
  9 +
9 10 def get_semantic_operations(lemma, schemata_conversions):
10 11 connections = []
11 12 operations = []
12 13  
13   - frames = lemma.entry_obj.visible_frames()
14   -
15 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 16 connections,
18 17 conv['obj'],
19 18 conv['js'])
20 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 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 26 operations = []
27   - used_poss_ids = []
  27 + used_poss_ids = []
28 28 for js_position in js_schema['positions']:
29 29 if len(js_position['arguments']) > 0:
30 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 34 'position': position,
35 35 'phrase_type': phrase_type}
36 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 38 conn_dict = next((conn_dict
39 39 for conn_dict in connections if conn_dict['compl'] == conn['compl']), None)
40 40 if conn_dict:
... ... @@ -44,6 +44,7 @@ def get_reconnect_operations_and_extend_connections(frames, connections, schema,
44 44 'realizations': conn['realizations']})
45 45 return operations
46 46  
  47 +
47 48 def get_position(schema, js_position, used_poss_ids):
48 49 position = jsPosToObj(js_position)
49 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 53 used_poss_ids.append(position.id)
53 54 return position
54 55  
55   -def reconnect_operations(frames, connection, new_target):
  56 +
  57 +def reconnect_operations(lemma, connection, new_target):
56 58 operations = []
  59 + visible_frames = lemma.entry_obj.visible_frames()
  60 + shared_schemata_ids = get_shared_schemata_ids(lemma)
57 61 compl = Complement.objects.get(id=connection['compl'])
58   - frame = frames.get(complements=compl)
  62 + frame = visible_frames.get(complements=compl)
59 63 arg_ref = create_argument_ref(frame, compl)
60 64 for real_id in connection['realizations']:
61 65 realization = compl.realizations.get(id=real_id)
... ... @@ -64,26 +68,31 @@ def reconnect_operations(frames, connection, new_target):
64 68 new_phrase_type_ref = create_phrase_type_ref(new_target['schema'], new_target['position'],
65 69 new_target['phrase_type'], realization.alternation)
66 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 73 operations.append(create_operation('connect', arg_ref, new_phrase_type_ref))
69 74 return operations
70   -
  75 +
  76 +
71 77 def create_argument_ref(frame, complement):
72 78 return 'frame_%d_comp_%d_' % (frame.id, complement.id)
73   -
  79 +
  80 +
74 81 def create_phrase_type_ref(schema, position, phrase_type, alternation):
75 82 return 'schema_%d_pos_%d_arg_%d_alt_%d_' % (schema.id, position.id,
76 83 phrase_type.id, alternation)
77 84  
  85 +
78 86 def create_operation(operation, arg_ref, phrase_type_ref):
79 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 91 operations = []
83 92 shared_schemata_ids = get_shared_schemata_ids(lemma)
84   - for frame in frames:
  93 + for frame in lemma.entry_obj.visible_frames():
85 94 for compl in frame.complements.all():
86   - conn_dict = next((conn_dict
  95 + conn_dict = next((conn_dict
87 96 for conn_dict in connections if conn_dict['compl'] == compl.id), None)
88 97 for real in compl.realizations.all():
89 98 if real.frame.id not in shared_schemata_ids:
... ... @@ -94,16 +103,19 @@ def get_disconnect_operations(lemma, frames, connections):
94 103 operations.append(create_operation('disconnect', arg_ref, phrase_type_ref))
95 104 return operations
96 105  
  106 +
97 107 def get_shared_schemata_ids(lemma):
98 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 110 if connected.defined():
101 111 ids += [f.id for f in connected.actual_lemma().frames.all()]
102 112 return ids
103 113  
  114 +
104 115 def update_connections(lemma_id, reconnect_operations, user):
105 116 modify_frames(lemma_id, reconnect_operations, user)
106 117  
  118 +
107 119 def disconnect_all_examples_operations(lemma):
108 120 operations = []
109 121 lex_units = lemma.entry_obj.meanings.all()
... ... @@ -116,13 +128,16 @@ def disconnect_all_examples_operations(lemma):
116 128 'example': example.id})
117 129 return operations
118 130  
  131 +
119 132 def connect_example_operation(example_dict, example_obj):
120 133 lu = LexicalUnit.objects.get(id=example_dict['lexical_unit'])
121 134 return {'operation': 'add_example', 'unit': lu.id, 'example': example_obj.id}
122 135  
  136 +
123 137 def disconnect_example_operation(example_dict, example_obj):
124 138 lu = LexicalUnit.objects.get(id=example_dict['lexical_unit'])
125 139 return {'operation': 'remove_example', 'unit': lu.id, 'example': example_obj.id}
126 140  
  141 +
127 142 def reconnect_examples(lemma, operations):
128 143 update_meanings(lemma.id, operations)
... ...
dictionary/validation.py
... ... @@ -239,7 +239,7 @@ def get_deriv_miss_frames(lemma):
239 239  
240 240 def get_deriv_related_lemmas(entry):
241 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 243 try:
244 244 rel_lemma = Lemma.objects.get(entry_obj=rel_entry, old=False)
245 245 deriv_related_lemmas.append(rel_lemma)
... ...
semantics/management/commands/adjectives_todo.py
... ... @@ -28,7 +28,7 @@ def adj_todo():
28 28 except ObjectDoesNotExist:
29 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 32 for rel_entry in rel_entries:
33 33 if rel_entry.actual_lemma().status.status == REL_STATUS:
34 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 1 #! /usr/bin/python
2 2 # -*- coding: utf-8 -*-
3 3  
4   -import sys, os, codecs
5   -
6 4 from django.core.management.base import BaseCommand
7 5  
8 6 from django.core.exceptions import ObjectDoesNotExist
9 7 from dictionary.models import Entry, POS
10   -from wordnet.models import LexicalUnit
11   -from settings import PROJECT_PATH
  8 +
12 9  
13 10 class Command(BaseCommand):
14 11 args = 'none'
... ... @@ -17,6 +14,7 @@ class Command(BaseCommand):
17 14 def handle(self, **options):
18 15 nouns_todo()
19 16  
  17 +
20 18 def nouns_todo():
21 19 noun = POS.objects.get(tag='noun')
22 20 verb = POS.objects.get(tag='verb')
... ... @@ -27,7 +25,7 @@ def nouns_todo():
27 25 except ObjectDoesNotExist:
28 26 continue
29 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 29 for rel_entry in rel_entries:
32 30 try:
33 31 temp = entry.actual_lemma()
... ... @@ -35,4 +33,3 @@ def nouns_todo():
35 33 continue
36 34 if rel_entry.actual_lemma().status.priority >= 90:
37 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 1 #! /usr/bin/python
2 2 # -*- coding: utf-8 -*-
3 3  
4   -import sys, os, codecs
5   -
6 4 from django.core.management.base import BaseCommand
7 5  
8 6 from django.core.exceptions import ObjectDoesNotExist
9 7 from dictionary.models import Entry, POS
10   -from wordnet.models import LexicalUnit
11   -from settings import PROJECT_PATH
  8 +
12 9  
13 10 class Command(BaseCommand):
14 11 args = 'none'
... ... @@ -17,6 +14,7 @@ class Command(BaseCommand):
17 14 def handle(self, **options):
18 15 nouns_todo()
19 16  
  17 +
20 18 def nouns_todo():
21 19 noun = POS.objects.get(tag='noun')
22 20 verb = POS.objects.get(tag='verb')
... ... @@ -27,7 +25,7 @@ def nouns_todo():
27 25 except ObjectDoesNotExist:
28 26 continue
29 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 29 for rel_entry in rel_entries:
32 30 try:
33 31 temp = entry.actual_lemma()
... ... @@ -35,4 +33,3 @@ def nouns_todo():
35 33 continue
36 34 if rel_entry.actual_lemma().status.priority >= 90:
37 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 1 #! /usr/bin/python
2 2 # -*- coding: utf-8 -*-
3 3  
4   -import sys, os, codecs
5   -
6 4 from django.core.management.base import BaseCommand
7 5  
8 6 from django.core.exceptions import ObjectDoesNotExist
9 7 from dictionary.models import Entry, POS
10   -from wordnet.models import LexicalUnit
11   -from settings import PROJECT_PATH
  8 +
12 9  
13 10 class Command(BaseCommand):
14 11 args = 'none'
... ... @@ -17,6 +14,7 @@ class Command(BaseCommand):
17 14 def handle(self, **options):
18 15 nouns_todo()
19 16  
  17 +
20 18 def nouns_todo():
21 19 noun = POS.objects.get(tag='noun')
22 20 entries = Entry.objects.filter(pos=noun).order_by('name')
... ... @@ -26,8 +24,7 @@ def nouns_todo():
26 24 except ObjectDoesNotExist:
27 25 continue
28 26 if entry.actual_lemma().status.priority == 40:
29   - rel_entries = entry.rel_entries.all()
  27 + rel_entries = entry.related_entries().all()
30 28 for rel_entry in rel_entries:
31 29 if rel_entry.actual_lemma().status.priority >= 90:
32 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 1 #! /usr/bin/python
2 2 # -*- coding: utf-8 -*-
3 3  
4   -import sys, os, codecs
5   -
6 4 from django.core.management.base import BaseCommand
7 5  
8 6 from django.core.exceptions import ObjectDoesNotExist
9 7 from dictionary.models import Entry, POS
10   -from wordnet.models import LexicalUnit
11   -from settings import PROJECT_PATH
  8 +
12 9  
13 10 class Command(BaseCommand):
14 11 args = 'none'
... ... @@ -17,6 +14,7 @@ class Command(BaseCommand):
17 14 def handle(self, **options):
18 15 nouns_todo()
19 16  
  17 +
20 18 def nouns_todo():
21 19 verb = POS.objects.get(tag='verb')
22 20 noun = POS.objects.get(tag='noun')
... ... @@ -27,7 +25,7 @@ def nouns_todo():
27 25 except ObjectDoesNotExist:
28 26 continue
29 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 29 for rel_entry in rel_entries:
32 30 try:
33 31 temp = rel_entry.actual_lemma()
... ... @@ -35,4 +33,3 @@ def nouns_todo():
35 33 continue
36 34 if rel_entry.actual_lemma().status.priority == 40:
37 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 83  
84 84 def create_frames_context(lemma_id, user):
85 85 lemma = Lemma.objects.get(id=lemma_id)
86   - connected = lemma.entry_obj.rel_entries.all()
87 86  
88 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 88 # lexical_units = lemma.entry_obj.meanings.order_by('sense')
... ... @@ -280,7 +279,7 @@ def ajax_connected(request, lemma_id):
280 279  
281 280 def create_connected_context(lemma_id, user):
282 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 283 context = {'frames_display': [], 'connections':{'connected_reverse': [], 'connected': []}}
285 284  
286 285 for entry in connected:
... ...