|
1
2
3
|
#-*- coding:utf-8 -*-
import codecs
|
|
4
|
import datetime
|
|
5
6
7
8
|
import os
from django.core.management.base import BaseCommand
|
|
9
|
from dictionary.models import Lemma, get_ready_statuses
|
|
10
11
12
13
|
from settings import PROJECT_PATH
BASE_PATH = os.path.join(PROJECT_PATH, 'data')
|
|
14
15
16
17
18
19
20
21
22
|
LABELS = (u'hasło',
u'status hasła',
u'identyfikator schematu',
u'schemat',
u'opinia o schemacie',
u'przykład',
u'opinia o przykładzie',
u'zródło przykładu',
u'wybór typów fraz')
|
|
23
24
25
26
27
|
class Command(BaseCommand):
help = 'Get pinned examples from Slowal.'
def handle(self, **options):
|
|
28
29
30
31
32
33
|
get_examples()
def get_examples():
ready_statuses = get_ready_statuses()
write_detailed_examples(ready_statuses)
# write_examples(ready_statuses)
|
|
34
|
|
|
35
|
def write_detailed_examples(statuses):
|
|
36
|
try:
|
|
37
38
39
40
41
42
|
lemmas = Lemma.objects.filter(old=False)
lemmas = lemmas.filter(status__in=statuses)
now = datetime.datetime.now().strftime('%Y%m%d')
examples_file = codecs.open(os.path.join(BASE_PATH, 'detailed_examples_%s.csv' % now), 'wt', 'utf-8')
examples_file.write(u'%s\n' % u'\t'.join(LABELS))
for lemma in lemmas.order_by('entry_obj__name'):
|
|
43
|
print lemma
|
|
44
|
lemma_entry = lemma.entry_obj.name
|
|
45
46
|
lemma_status = lemma.status.status
for frame in lemma.frames.order_by('text_rep').all():
|
|
47
48
|
if not lemma.phraseology_ready() and frame.phraseologic:
continue
|
|
49
50
|
frame_opinion = lemma.frame_opinions.filter(frame=frame).all()[0].value
for example in lemma.nkjp_examples.filter(frame=frame):
|
|
51
|
sentence = example.sentence.replace('\n', ' ').replace('\r', '').replace('\t', ' ')
|
|
52
|
arguments_selection = u'%s' % u' + '.join([u'%s' % selection.__unicode__() for selection in example.arguments.all()])
|
|
53
54
55
56
57
58
59
60
61
|
examples_file.write(u'%s\t%s\t%d\t%s\t%s\t%s\t%s\t%s\t%s\n' % (lemma_entry,
lemma_status,
frame.id,
frame.get_position_spaced_text_rep(),
frame_opinion,
sentence,
example.opinion.opinion,
example.source.source,
arguments_selection))
|
|
62
63
64
|
finally:
examples_file.close()
|
|
65
66
|
def write_examples(statuses):
try:
|
|
67
|
examples_file = codecs.open(os.path.join(BASE_PATH,
|
|
68
69
70
71
72
73
74
75
76
77
|
'examples_gotowe_plus.txt'), 'wt', 'utf-8')
for lemma in Lemma.objects.filter(old=False).filter(status__in=statuses).order_by('entry').all():
print lemma
examples_file.write(lemma.entry+'\n')
for frame in lemma.frames.order_by('text_rep').all():
if lemma.frame_opinions.get(frame=frame).value.value != u'zła':
examples_file.write('\t%s\n' % frame.text_rep)
for example in lemma.nkjp_examples.filter(frame=frame):
examples_file.write('\t\t--> %s\n' % example.sentence)
examples_file.write('\n\n')
|
|
78
|
finally:
|
|
79
|
examples_file.close()
|