validate_semantics.py
1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
from django.core.management.base import BaseCommand
from dictionary.models import Lemma
from semantics.validation import validate_schemas
class Command(BaseCommand):
args = 'none'
help = ""
def handle(self, **options):
# validate_schemata()
find_related_entries_potential_errors()
def validate_schemata():
lemmas = Lemma.objects.filter(old=False).order_by('entry_obj__name')
for lemma in lemmas:
if lemma.semantics_ready():
error_msg = validate_schemas(lemma.id)
if error_msg:
print (u'%s' % lemma.entry_obj.name)
def find_related_entries_potential_errors():
errors = []
lemmas = Lemma.objects.filter(old=False).order_by('entry_obj__name')
for lemma in lemmas:
for rel_entry in lemma.entry_obj.related_entries().all():
potential_error = u'%s <--> %s' % (lemma.entry_obj.name, rel_entry.name)
potential_error_reverse = u'%s <--> %s' % (rel_entry.name, lemma.entry_obj.name)
if (potential_error not in errors and potential_error_reverse not in errors
and has_same_schemata_in_history(lemma.entry_obj, rel_entry)):
errors.append(potential_error)
print (potential_error)
def has_same_schemata_in_history(entry1, entry2):
for lemma1 in entry1.lemmas.all():
for lemma2 in entry2.lemmas.all():
if lemma1.frames.filter(pk__in=lemma2.frames.all()).exists():
return True
return False