check_frame_existence.py
52.5 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
#-*- coding:utf-8 -*-
# author: B.Niton
import re
import codecs
import itertools
from django.core.management.base import BaseCommand
from dictionary.models import *
DICT_PATH = 'data/Skladnica/ramki_skl_v_140213.txt'
BAD_PATH = 'data/Skladnica/bad_frames.txt'
GOOD_PATH = 'data/Skladnica/good_frames.txt'
NLEMMA_PATH = 'data/Skladnica/nlemma_frames.txt'
ADVP_PP_PATH = 'data/Skladnica/advp_pp_frames.txt'
class Command(BaseCommand):
help = 'Checks if Skladnica frames exists in Walenty.'
def handle(self, file_path=DICT_PATH, **options):
check_frames()
def update_case(arg):
arg = arg.replace(u'mian', u'nom')
arg = arg.replace(u'bier', u'acc')
arg = arg.replace(u'cel', u'dat')
arg = arg.replace(u'dop', u'gen')
arg = arg.replace(u'miej', u'loc')
arg = arg.replace(u'narz', u'inst')
arg = arg.replace(u'pop', u'postp')
return arg
#def triple_arg_poss(arg, positions_cats_ls, need_controll, case, ):
# possibilities = []
# for pos_cat in positions_cats_ls:
# possibilities.append({'category_ls' : [pos_cat],
# 'arg' : arg,
# 'need_controll': False,
# 'preposition' : '',
# 'case' : '',
# 'pos_nps' : []})
# return possibilities
def possible_args(arg, pos):
posibilities = []
if arg == 'subj':
posibilities.append({'category_ls' : ['subj'],
'arg' : 'np(str)',
'need_controll': False,
'preposition' : '',
'case' : '',
'pos_nps' : []})
elif arg == 'np(bier)':
posibilities.append({'category_ls': [],
'arg' : u'np(str)',
'need_controll': False,
'preposition' : '',
'case' : '',
'pos_nps' : []})
posibilities.append({'category_ls': ['obj'],
'arg' : u'np(str)',
'need_controll': False,
'preposition' : '',
'case' : '',
'pos_nps' : []})
posibilities.append({'category_ls': [],
'arg' : arg,
'need_controll': False,
'preposition' : '',
'case' : '',
'pos_nps' : []}) # ==> np(acc)
posibilities.append({'category_ls': ['subj'],
'arg' : arg,
'need_controll': False,
'preposition' : '',
'case' : '',
'pos_nps' : []}) # ==> np(acc)
posibilities.append({'category_ls': ['obj'],
'arg' : arg,
'need_controll': False,
'preposition' : '',
'case' : '',
'pos_nps' : []}) # ==> np(acc)
posibilities.append({'category_ls': [],
'arg' : u'np(part)',
'need_controll': False,
'preposition' : '',
'case' : '',
'pos_nps' : []})
posibilities.append({'category_ls': ['subj'],
'arg' : u'np(part)',
'need_controll': False,
'preposition' : '',
'case' : '',
'pos_nps' : []})
posibilities.append({'category_ls': ['obj'],
'arg' : u'np(part)',
'need_controll': False,
'preposition' : '',
'case' : '',
'pos_nps' : []})
elif arg == 'np(dop)':
posibilities.append({'category_ls': [],
'arg' : arg,
'need_controll': False,
'preposition' : '',
'case' : '',
'pos_nps' : []}) # ==> np(gen)
posibilities.append({'category_ls': ['subj'],
'arg' : arg,
'need_controll': False,
'preposition' : '',
'case' : '',
'pos_nps' : []}) # ==> np(gen)
posibilities.append({'category_ls': ['obj'],
'arg' : arg,
'need_controll': False,
'preposition' : '',
'case' : '',
'pos_nps' : []}) # ==> np(gen)
posibilities.append({'category_ls': [],
'arg' : u'np(part)',
'need_controll': False,
'preposition' : '',
'case' : '',
'pos_nps' : []})
posibilities.append({'category_ls': ['subj'],
'arg' : u'np(part)',
'need_controll': False,
'preposition' : '',
'case' : '',
'pos_nps' : []})
posibilities.append({'category_ls': ['obj'],
'arg' : u'np(part)',
'need_controll': False,
'preposition' : '',
'case' : '',
'pos_nps' : []})
if pos == 'ger': # przechodzi tez na biernik
posibilities.append({'category_ls': [],
'arg' : u'np(str)',
'need_controll': False,
'preposition' : '',
'case' : '',
'pos_nps' : []})
posibilities.append({'category_ls': ['obj'],
'arg' : u'np(str)',
'need_controll': False,
'preposition' : '',
'case' : '',
'pos_nps' : []})
posibilities.append({'category_ls': [],
'arg' : u'np(acc)',
'need_controll': False,
'preposition' : '',
'case' : '',
'pos_nps' : []})
posibilities.append({'category_ls': ['subj'],
'arg' : u'np(acc)',
'need_controll': False,
'preposition' : '',
'case' : '',
'pos_nps' : []})
posibilities.append({'category_ls': ['obj'],
'arg' : u'np(acc)',
'need_controll': False,
'preposition' : '',
'case' : '',
'pos_nps' : []})
elif (arg.startswith('prepnp(jak,') or arg.startswith('prepnp(jako,') or
arg.startswith(u'prepnp(niż,')):
prepnp_atr_ls = arg.replace('prepnp(', '').replace(')', '').split(',')
preposition = prepnp_atr_ls[0]
case = prepnp_atr_ls[1]
posibilities.append({'category_ls': [],
'arg' : arg,
'need_controll': False,
'preposition' : '',
'case' : '',
'pos_nps' : []})
posibilities.append({'category_ls': ['subj'],
'arg' : arg,
'need_controll': False,
'preposition' : '',
'case' : '',
'pos_nps' : []})
posibilities.append({'category_ls': ['obj'],
'arg' : arg,
'need_controll': False,
'preposition' : '',
'case' : '',
'pos_nps' : []})
if case == 'mian':
pos_nps = []
pos_nps.extend(possible_args('subj', pos))
pos_nps.extend(possible_args('np(mian)', pos))
posibilities.append({'category_ls': [],
'arg' : 'prepnp(' + preposition + ',str)',
'need_controll': True,
'preposition' : preposition,
'case' : case,
'pos_nps' : pos_nps})
elif case == 'bier':
posibilities.append({'category_ls': [],
'arg' : 'prepnp(' + preposition + ',str)',
'need_controll': True,
'preposition' : preposition,
'case' : case,
'pos_nps' : possible_args('np(bier)', pos)})
elif(arg == u"prepnp(na temat,dop)"): # nie znajduje tego w wywleczonych
posibilities.append({'category_ls': [],
'arg' : u'comprepnp(na temat)',
'need_controll': False,
'preposition' : '',
'case' : '',
'pos_nps' : []})
posibilities.append({'category_ls': ['subj'],
'arg' : u'comprepnp(na temat)',
'need_controll': False,
'preposition' : '',
'case' : '',
'pos_nps' : []})
posibilities.append({'category_ls': ['obj'],
'arg' : u'comprepnp(na temat)',
'need_controll': False,
'preposition' : '',
'case' : '',
'pos_nps' : []})
elif(arg == u"prepnp(w sprawie,dop)"):
posibilities.append({'category_ls': [],
'arg' : u'comprepnp(w sprawie)',
'need_controll': False,
'preposition' : '',
'case' : '',
'pos_nps' : []})
posibilities.append({'category_ls': ['subj'],
'arg' : u'comprepnp(w sprawie)',
'need_controll': False,
'preposition' : '',
'case' : '',
'pos_nps' : []})
posibilities.append({'category_ls': ['obj'],
'arg' : u'comprepnp(w sprawie)',
'need_controll': False,
'preposition' : '',
'case' : '',
'pos_nps' : []})
elif(arg == u"prepnp(z powodu,dop)"):
posibilities.append({'category_ls': [],
'arg' : u'comprepnp(z powodu)',
'need_controll': False,
'preposition' : '',
'case' : '',
'pos_nps' : []})
posibilities.append({'category_ls': ['subj'],
'arg' : u'comprepnp(z powodu)',
'need_controll': False,
'preposition' : '',
'case' : '',
'pos_nps' : []})
posibilities.append({'category_ls': ['obj'],
'arg' : u'comprepnp(z powodu)',
'need_controll': False,
'preposition' : '',
'case' : '',
'pos_nps' : []})
elif(arg == u"adjp(mian)"):
posibilities.append({'category_ls': [],
'arg' : arg,
'need_controll': False,
'preposition' : '',
'case' : '',
'pos_nps' : []})
posibilities.append({'category_ls': ['subj'],
'arg' : arg,
'need_controll': False,
'preposition' : '',
'case' : '',
'pos_nps' : []})
posibilities.append({'category_ls': ['obj'],
'arg' : arg,
'need_controll': False,
'preposition' : '',
'case' : '',
'pos_nps' : []})
posibilities.append({'category_ls': [],
'arg' : 'adjp(pred)',
'need_controll': False,
'preposition' : '',
'case' : '',
'pos_nps' : []})
posibilities.append({'category_ls': ['subj'],
'arg' : 'adjp(pred)',
'need_controll': False,
'preposition' : '',
'case' : '',
'pos_nps' : []})
posibilities.append({'category_ls': ['obj'],
'arg' : 'adjp(pred)',
'need_controll': False,
'preposition' : '',
'case' : '',
'pos_nps' : []})
elif(arg == u"adjp(narz)"):
posibilities.append({'category_ls': [],
'arg' : arg,
'need_controll': False,
'preposition' : '',
'case' : '',
'pos_nps' : []})
posibilities.append({'category_ls': ['subj'],
'arg' : arg,
'need_controll': False,
'preposition' : '',
'case' : '',
'pos_nps' : []})
posibilities.append({'category_ls': ['obj'],
'arg' : arg,
'need_controll': False,
'preposition' : '',
'case' : '',
'pos_nps' : []})
posibilities.append({'category_ls': [],
'arg' : 'adjp(pred)',
'need_controll': False,
'preposition' : '',
'case' : '',
'pos_nps' : []})
posibilities.append({'category_ls': ['subj'],
'arg' : 'adjp(pred)',
'need_controll': False,
'preposition' : '',
'case' : '',
'pos_nps' : []})
posibilities.append({'category_ls': ['obj'],
'arg' : 'adjp(pred)',
'need_controll': False,
'preposition' : '',
'case' : '',
'pos_nps' : []})
elif(arg.startswith(u'sentp')):
# liczy przecinki by sprawdzic liczbe atrybutow w 'sentp'
number_of_commas = arg.count(u',')
conv_arg = arg.replace(u'pz', u'int')
if(number_of_commas == 0):
posibilities.append({'category_ls': [],
'arg' : conv_arg.replace(u'sentp', u'cp'),
'need_controll': False,
'preposition' : '',
'case' : '',
'pos_nps' : []})
posibilities.append({'category_ls': ['subj'],
'arg' : conv_arg.replace(u'sentp', u'cp'),
'need_controll': False,
'preposition' : '',
'case' : '',
'pos_nps' : []})
posibilities.append({'category_ls': ['obj'],
'arg' : conv_arg.replace(u'sentp', u'cp'),
'need_controll': False,
'preposition' : '',
'case' : '',
'pos_nps' : []})
elif(number_of_commas == 1):
posibilities.append({'category_ls': [],
'arg' : conv_arg.replace(u'sentp', u'ncp'),
'need_controll': False,
'preposition' : '',
'case' : '',
'pos_nps' : []})
posibilities.append({'category_ls': ['subj'],
'arg' : conv_arg.replace(u'sentp', u'ncp'),
'need_controll': False,
'preposition' : '',
'case' : '',
'pos_nps' : []})
posibilities.append({'category_ls': ['obj'],
'arg' : conv_arg.replace(u'sentp', u'ncp'),
'need_controll': False,
'preposition' : '',
'case' : '',
'pos_nps' : []})
elif(number_of_commas == 2):
posibilities.append({'category_ls': [],
'arg' : conv_arg.replace(u'sentp', u'prepncp'),
'need_controll': False,
'preposition' : '',
'case' : '',
'pos_nps' : []})
posibilities.append({'category_ls': ['subj'],
'arg' : conv_arg.replace(u'sentp', u'prepncp'),
'need_controll': False,
'preposition' : '',
'case' : '',
'pos_nps' : []})
posibilities.append({'category_ls': ['obj'],
'arg' : conv_arg.replace(u'sentp', u'prepncp'),
'need_controll': False,
'preposition' : '',
'case' : '',
'pos_nps' : []})
elif(arg == u'advp'):
posibilities.append({'category_ls': [],
'arg' : u'xp(_)',
'need_controll': False,
'preposition' : '',
'case' : '',
'pos_nps' : []})
posibilities.append({'category_ls': ['subj'],
'arg' : u'xp(_)',
'need_controll': False,
'preposition' : '',
'case' : '',
'pos_nps' : []})
posibilities.append({'category_ls': ['obj'],
'arg' : u'xp(_)',
'need_controll': False,
'preposition' : '',
'case' : '',
'pos_nps' : []})
posibilities.append({'category_ls': [],
'arg' : u'advp(pron)',
'need_controll': False,
'preposition' : '',
'case' : '',
'pos_nps' : []})
posibilities.append({'category_ls': ['subj'],
'arg' : u'advp(pron)',
'need_controll': False,
'preposition' : '',
'case' : '',
'pos_nps' : []})
posibilities.append({'category_ls': ['obj'],
'arg' : u'advp(pron)',
'need_controll': False,
'preposition' : '',
'case' : '',
'pos_nps' : []})
posibilities.append({'category_ls': [],
'arg' : u'advp(misc)',
'need_controll': False,
'preposition' : '',
'case' : '',
'pos_nps' : []})
posibilities.append({'category_ls': ['subj'],
'arg' : u'advp(misc)',
'need_controll': False,
'preposition' : '',
'case' : '',
'pos_nps' : []})
posibilities.append({'category_ls': ['obj'],
'arg' : u'advp(misc)',
'need_controll': False,
'preposition' : '',
'case' : '',
'pos_nps' : []})
posibilities.append({'category_ls': [],
'arg' : u'advp(locat)',
'need_controll': False,
'preposition' : '',
'case' : '',
'pos_nps' : []})
posibilities.append({'category_ls': ['subj'],
'arg' : u'advp(locat)',
'need_controll': False,
'preposition' : '',
'case' : '',
'pos_nps' : []})
posibilities.append({'category_ls': ['obj'],
'arg' : u'advp(locat)',
'need_controll': False,
'preposition' : '',
'case' : '',
'pos_nps' : []})
posibilities.append({'category_ls': [],
'arg' : u'advp(abl)',
'need_controll': False,
'preposition' : '',
'case' : '',
'pos_nps' : []})
posibilities.append({'category_ls': ['subj'],
'arg' : u'advp(abl)',
'need_controll': False,
'preposition' : '',
'case' : '',
'pos_nps' : []})
posibilities.append({'category_ls': ['obj'],
'arg' : u'advp(abl)',
'need_controll': False,
'preposition' : '',
'case' : '',
'pos_nps' : []})
posibilities.append({'category_ls': [],
'arg' : u'advp(adl)',
'need_controll': False,
'preposition' : '',
'case' : '',
'pos_nps' : []})
posibilities.append({'category_ls': ['subj'],
'arg' : u'advp(adl)',
'need_controll': False,
'preposition' : '',
'case' : '',
'pos_nps' : []})
posibilities.append({'category_ls': ['obj'],
'arg' : u'advp(adl)',
'need_controll': False,
'preposition' : '',
'case' : '',
'pos_nps' : []})
posibilities.append({'category_ls': [],
'arg' : u'advp(perl)',
'need_controll': False,
'preposition' : '',
'case' : '',
'pos_nps' : []})
posibilities.append({'category_ls': ['subj'],
'arg' : u'advp(perl)',
'need_controll': False,
'preposition' : '',
'case' : '',
'pos_nps' : []})
posibilities.append({'category_ls': ['obj'],
'arg' : u'advp(perl)',
'need_controll': False,
'preposition' : '',
'case' : '',
'pos_nps' : []})
posibilities.append({'category_ls': [],
'arg' : u'advp(temp)',
'need_controll': False,
'preposition' : '',
'case' : '',
'pos_nps' : []})
posibilities.append({'category_ls': ['subj'],
'arg' : u'advp(temp)',
'need_controll': False,
'preposition' : '',
'case' : '',
'pos_nps' : []})
posibilities.append({'category_ls': ['obj'],
'arg' : u'advp(temp)',
'need_controll': False,
'preposition' : '',
'case' : '',
'pos_nps' : []})
posibilities.append({'category_ls': [],
'arg' : u'advp(dur)',
'need_controll': False,
'preposition' : '',
'case' : '',
'pos_nps' : []})
posibilities.append({'category_ls': ['subj'],
'arg' : u'advp(dur)',
'need_controll': False,
'preposition' : '',
'case' : '',
'pos_nps' : []})
posibilities.append({'category_ls': ['obj'],
'arg' : u'advp(dur)',
'need_controll': False,
'preposition' : '',
'case' : '',
'pos_nps' : []})
posibilities.append({'category_ls': [],
'arg' : u'advp(mod)',
'need_controll': False,
'preposition' : '',
'case' : '',
'pos_nps' : []})
posibilities.append({'category_ls': ['subj'],
'arg' : u'advp(mod)',
'need_controll': False,
'preposition' : '',
'case' : '',
'pos_nps' : []})
posibilities.append({'category_ls': ['obj'],
'arg' : u'advp(mod)',
'need_controll': False,
'preposition' : '',
'case' : '',
'pos_nps' : []})
posibilities.append({'category_ls': [],
'arg' : u'advp(pred)',
'need_controll': False,
'preposition' : '',
'case' : '',
'pos_nps' : []})
posibilities.append({'category_ls': ['subj'],
'arg' : u'advp(pred)',
'need_controll': False,
'preposition' : '',
'case' : '',
'pos_nps' : []})
posibilities.append({'category_ls': ['obj'],
'arg' : u'advp(pred)',
'need_controll': False,
'preposition' : '',
'case' : '',
'pos_nps' : []})
elif(arg == u'prepnp(przez,bier)'):
posibilities.append({'category_ls': [],
'arg' : arg,
'need_controll': False,
'preposition' : '',
'case' : '',
'pos_nps' : []})
posibilities.append({'category_ls': ['subj'],
'arg' : arg,
'need_controll': False,
'preposition' : '',
'case' : '',
'pos_nps' : []})
posibilities.append({'category_ls': ['obj'],
'arg' : arg,
'need_controll': False,
'preposition' : '',
'case' : '',
'pos_nps' : []})
if pos == 'ger' or pos == 'ppas':
posibilities.append({'category_ls': ['subj'],
'arg' : u'np(str)',
'need_controll': False,
'preposition' : '',
'case' : '',
'pos_nps' : []})
elif arg.startswith('infp('):
conv_arg = copy.deepcopy(arg)
conv_arg = conv_arg.replace('(nd)', '(imperf)')
conv_arg = conv_arg.replace('(dk)', '(perf)')
posibilities.append({'category_ls': [],
'arg' : conv_arg,
'need_controll': False,
'preposition' : '',
'case' : '',
'pos_nps' : []})
posibilities.append({'category_ls': ['subj'],
'arg' : conv_arg,
'need_controll': False,
'preposition' : '',
'case' : '',
'pos_nps' : []})
posibilities.append({'category_ls': ['obj'],
'arg' : conv_arg,
'need_controll': False,
'preposition' : '',
'case' : '',
'pos_nps' : []})
posibilities.append({'category_ls': [],
'arg' : 'infp(_)',
'need_controll': False,
'preposition' : '',
'case' : '',
'pos_nps' : []})
posibilities.append({'category_ls': ['subj'],
'arg' : 'infp(_)',
'need_controll': False,
'preposition' : '',
'case' : '',
'pos_nps' : []})
posibilities.append({'category_ls': ['obj'],
'arg' : 'infp(_)',
'need_controll': False,
'preposition' : '',
'case' : '',
'pos_nps' : []})
else:
posibilities.append({'category_ls': [],
'arg' : arg,
'need_controll': False,
'preposition' : '',
'case' : '',
'pos_nps' : []})
posibilities.append({'category_ls': ['subj'],
'arg' : arg,
'need_controll': False,
'preposition' : '',
'case' : '',
'pos_nps' : []})
posibilities.append({'category_ls': ['obj'],
'arg' : arg,
'need_controll': False,
'preposition' : '',
'case' : '',
'pos_nps' : []})
poss_to_add = []
for poss in posibilities:
poss['arg'] = poss['arg'].replace(', ', ',')
poss['arg'] = update_case(poss['arg'])
poss['case'] = update_case(poss['case'])
# dodawanie powiazanych argumentow np. przeciw/przeciwko
for atr in Atribute_Value.objects.filter(related=True):
for main_atr in atr.main_attr_values.all():
arg_str = poss['arg'].replace(u'(%s)' % atr.value, u'(%s)' % main_atr.value)
arg_str = arg_str.replace(u'(%s,' % atr.value, u'(%s,' % main_atr.value)
arg_str = arg_str.replace(u',%s)' % atr.value, u',%s)' % main_atr.value)
arg_str = arg_str.replace(u',%s,' % atr.value, u',%s,' % main_atr.value)
new_poss = copy.deepcopy(poss)
new_poss['arg'] = arg_str
poss_to_add.append(new_poss)
posibilities.extend(poss_to_add)
return posibilities
def check_frame(frame, conv_frame, preps, args_to_match, check_sie):
args_match = False
sie_match = True
not_this_frame = False
somelists = []
positions = frame.positions
not_categorized_positions = frame.positions.exclude(categories__control=False)
# jesli liczba argumentow jest wieksz niz liczba pozycji, pomin ramke
if positions.count() < args_to_match:
return False
for arg in conv_frame['args']:
arg['poss_positions'] = []
for poss in arg['poss_args']:
new_poss_positions = match_arg(poss, positions, preps, not_categorized_positions)
if new_poss_positions:
arg['poss_positions'].extend(new_poss_positions)
if not arg['poss_positions']:
not_this_frame = True
break
somelists.append(arg['poss_positions'])
if not_this_frame:
return False
for element in itertools.product(*somelists):
if not element:
continue
if len(element) == len(set(element)) and len(set(element)) >= args_to_match:
args_match = True
break
# sprawdzenie siennosci
if check_sie:
try:
frame.characteristics.get(value__value=u'się')
except Frame_Characteristic.DoesNotExist:
refl_exist = False
refl_list = []
refl_list.append({'category_ls': [],
'arg' : 'refl',
'need_controll': False,
'preposition' : '',
'case' : '',
'pos_nps' : []})
refl_list.append({'category_ls': ['subj'],
'arg' : 'refl',
'need_controll': False,
'preposition' : '',
'case' : '',
'pos_nps' : []})
refl_list.append({'category_ls': ['obj'],
'arg' : 'refl',
'need_controll': False,
'preposition' : '',
'case' : '',
'pos_nps' : []})
for refl in refl_list:
if len(match_arg(refl, positions, preps, not_categorized_positions)) > 0:
refl_exist = True
break
if not refl_exist:
sie_match = False
else:
try:
frame.characteristics.get(value__value=u'')
except Frame_Characteristic.DoesNotExist:
sie_match = False
# znaleziono ramke odpowiadajaca skladnicowej w Walentym
if (args_match or args_to_match == 0) and sie_match:
return True
else:
return False
def check_frames():
print 'Be patient, it can take a while.'
try:
f = codecs.open(DICT_PATH, "rt", 'utf-8')
badfile = codecs.open(BAD_PATH, 'wt', 'utf-8')
goodfile = codecs.open(GOOD_PATH, 'wt', 'utf-8')
nlemmafile = codecs.open(NLEMMA_PATH, 'wt', 'utf-8')
advp_pp_file = codecs.open(ADVP_PP_PATH, 'wt', 'utf-8')
try:
for line in f:
line_pattern = re.compile(ur'^([^\s]+)[\s]*([^\s]+)[\s]*(\[[^\]]*\])[\s]*(\[[^\]]*\])(.*)$')
m = line_pattern.match(line)
if not m:
print smart_str(line)
if m:
lemma_str = m.group(1).strip()
pos = m.group(2).strip()
frame_str = m.group(3).strip()
prep_str = m.group(4).strip()
try:
lemma = Lemma.objects.get(old=False, entry=lemma_str, status__status=u'sprawdzone')
except Lemma.DoesNotExist:
nlemmafile.write(line.strip() + u'\n')
continue
if frame_str == '[]' or frame_str == '_':
continue
tokens = frame_str.replace('[', '').replace(']', '').split(',')
preps = []
if not prep_str == '[]':
for prep in prep_str.replace('[', '').replace(']', '').split(';'):
if not prep.startswith('cat='):
preps.append({'arg': prep,
'poss_args': possible_args(prep, pos),
'poss_positions': []})
args_ls = []
arg_str = ''
for tok in tokens:
arg_str += tok.strip() + ','
if (('(' in arg_str and ')' in arg_str) or
(not ('(' in arg_str) and not (')' in arg_str))):
args_ls.append(arg_str.strip().rstrip(','))
arg_str = ''
conv_frame = {'args' : [],
'reflex' : u' '}
check_sie = False
args_to_match = len(args_ls)
for arg in args_ls:
possibilities = []
if arg == 'sie':
args_to_match -= 1
check_sie = True
conv_frame['reflex'] = u'się'
continue
else:
possibilities = possible_args(arg, pos)
conv_frame['args'].append({'arg': arg,
'poss_args': possibilities,
'poss_positions': []})
frame_exist = False
for frame in lemma.frames.all():
# znaleziono ramke odpowiadajaca skladnicowej w Walentym
if check_frame(frame, conv_frame, preps, args_to_match, check_sie):
print 'OK'
frame_exist = True
goodfile.write(line)
break
if not frame_exist:
advp_found = False
for conv_arg in conv_frame['args']:
if conv_arg['arg'] == 'advp':
advp_found = True
for prep in preps:
conv_arg['poss_args'].extend(prep['poss_args'])
if advp_found:
for frame in lemma.frames.all():
if check_frame(frame, conv_frame, preps, args_to_match, check_sie):
print 'OK-wkladka'
frame_exist = True
advp_pp_file.write(line)
break
if not frame_exist:
print 'BAD'
badfile.write(line.strip() + '\n')
finally:
f.close()
badfile.close()
goodfile.close()
nlemmafile.close()
advp_pp_file.close()
except IOError:
return 'Error: Can not work on file %s, check if it exists!' % DICT_PATH
def match_arg(arg, positions, preps, not_categorized_positions):
ret_positions = []
if len(arg['category_ls']) > 0:
category = arg['category_ls'][0]
if arg['arg'].startswith('xp'):
xp_positions = positions.filter(categories__category=category,
arguments__type='xp')
if xp_positions.count() > 0 and len(preps) == 0:
ret_positions = xp_positions.all()
else:
for position in xp_positions:
pos_cats = position.categories.exclude(control=True)
for xp_arg in position.arguments.filter(type='xp'):
match = False
for prep in preps:
for poss_prep in prep['poss_args']:
pos_cat_match = False
# badanie kontroli
if not poss_prep['need_controll']:
if ((pos_cats.count() == 0 and not poss_prep['category_ls']) or
(pos_cats.count() > 0 and pos_cats.all()[0] == poss_prep['category_ls'][0])):
pos_cat_match = True
else:
if ((pos_cats.count() == 0 and not poss_prep['category_ls']) or
(pos_cats.count() > 0 and pos_cats.all()[0] == poss_prep['category_ls'][0]) and
position.categories.filter(category__startswith='controllee').count() > 0): #and position.categories.filter(control=True, ).count() > 0:
controllee_cats = position.categories.filter(category__startswith='controllee').all()
found_controlling_np = False
for controllee in controllee_cats:
control_id = controllee.category.replace('controllee', 'controller')
for np in poss_prep['pos_nps']:
pos_control_positions = positions.filter(categories__category=control_id)
pos_control_positions = match_arg(np, pos_control_positions, preps, not_categorized_positions)
if len(pos_control_positions) > 0:
found_controlling_np = True
pos_cat_match = True
break
if found_controlling_np:
break
if pos_cat_match and xp_arg.realizations.filter(argument__text_rep=poss_prep['arg']).count() > 0:
match = True
break
if match:
break
if match:
ret_positions.append(position)
break
else:
if not arg['need_controll']:
ret_positions = positions.filter(categories__category=category,
arguments__text_rep=arg['arg']).all()
else:
pos_positions_ls = positions.filter(categories__category=category,
arguments__text_rep=arg['arg']).filter(categories__control__startswith='controllee').all()
ret_positions_q = positions.filter(categories__category=category,
arguments__text_rep=arg['arg']).filter(categories__control__startswith='controllee')
for position in pos_positions_ls:
controllee_cats = position.categories.filter(category__startswith='controllee').all()
found_controlling_np = False
for controllee in controllee_cats:
control_id = controllee.category.replace('controllee', 'controller')
for np in arg['pos_nps']:
pos_control_positions = positions.filter(categories__category=control_id)
pos_control_positions = match_arg(np, pos_control_positions, preps, not_categorized_positions)
if len(pos_control_positions) > 0:
found_controlling_np = True
break
if found_controlling_np:
break
if not found_controlling_np:
ret_positions_q = ret_positions_q.exclude(pk=position.pk)
ret_positions = ret_positions_q.all()
elif len(arg['category_ls']) == 0:
if arg['arg'].startswith('xp'):
xp_positions = not_categorized_positions.filter(arguments__type='xp')#.exclude(categories__control=False)
if xp_positions.count() > 0 and len(preps) == 0:
ret_positions = xp_positions
else:
for position in xp_positions:
pos_cats = position.categories.exclude(control=True)
for xp_arg in position.arguments.filter(type='xp'):
match = False
for prep in preps:
for poss_prep in prep['poss_args']:
pos_cat_match = False
if not poss_prep['need_controll']:
if ((pos_cats.count() == 0 and not poss_prep['category_ls']) or
(pos_cats.count() > 0 and pos_cats.all()[0] == poss_prep['category_ls'][0])):
pos_cat_match = True
else:
if ((pos_cats.count() == 0 and not poss_prep['category_ls']) or
(pos_cats.count() > 0 and pos_cats.all()[0] == poss_prep['category_ls'][0]) and
position.categories.filter(category__startswith='controllee').count() > 0):
controllee_cats = position.categories.filter(category__startswith='controllee').all()
found_controlling_np = False
for controllee in controllee_cats:
control_id = controllee.category.replace('controllee', 'controller')
for np in poss_prep['pos_nps']:
pos_control_positions = positions.filter(categories__category=control_id)
pos_control_positions = match_arg(np, pos_control_positions, preps, not_categorized_positions)
if len(pos_control_positions) > 0:
found_controlling_np = True
pos_cat_match = True
break
if found_controlling_np:
break
if pos_cat_match and xp_arg.realizations.filter(argument__text_rep=poss_prep['arg']).count() > 0:
match = True
break
if match:
break
if match:
ret_positions.append(position)
break
else:
if not arg['need_controll']:
ret_positions = not_categorized_positions.filter(arguments__text_rep=arg['arg']).all()#.exclude(categories__control=False).all()
else:
pos_positions_ls = not_categorized_positions.filter(arguments__text_rep=arg['arg']).filter(categories__control=True).filter(categories__control__startswith='controllee').all()
ret_positions_q = not_categorized_positions.filter(arguments__text_rep=arg['arg']).filter(categories__control=True).filter(categories__control__startswith='controllee')
for position in pos_positions_ls:
controllee_cats = position.categories.filter(category__startswith='controllee').all()
found_controlling_np = False
for controllee in controllee_cats:
control_id = controllee.category.replace('controllee', 'controller')
for np in arg['pos_nps']:
pos_control_positions = positions.filter(categories__category=control_id)
pos_control_positions = match_arg(np, pos_control_positions, preps, not_categorized_positions)
if len(pos_control_positions) > 0:
found_controlling_np = True
break
if found_controlling_np:
break
if not found_controlling_np:
ret_positions_q = ret_positions_q.exclude(pk=position.pk)
ret_positions = ret_positions_q.all()
return ret_positions