1: #!/usr/bin/perl -w
2:
3: =head1 NAME
4:
5: updateRS.pl - Скрипт для занесения в таблицы русского поиска базы
6: B<$base> информации о вопросах
7:
8: =head1 SYNOPSIS
9:
10: updateRS1.pl Questions_per_cicle cicles_number
11:
12: updateRS.pl Questions_per_cicle
13:
14: updateRS.pl
15:
16:
17: =head1 DESCRIPTION
18:
19: Скрипт ищет в таблице Questions вопросы с нулевым ProcessedBySearch,
20: добавляет информацию в таблицы word2question, nests, nf. Поле
21: ProcessedBySearch устанавливается в 1. Обрабатывает
22: Questions_per_cicle*cicles_number вопросов, сбрасывая
23: информацию в базу каждые Questions_per_cicle вопросов.
24: Значения по умолчанию:
25: Questions_per_cicle=500;
26: cicles_number=1.
27:
28:
29: =head1 AUTHOR
30:
31: Роман Семизаров
32:
33:
34: =cut
35:
36:
37: use locale;
38: use DBI;
39: use POSIX qw (locale_h);
40: use lib "../lib";
41: use chgkfiles;
42: use dbchgk;
43: open (STDERR,">errors");
44: my $initime=time;
45: open TIME, ">time";
46: do "common.pl";
47: do "chgk.cnf";
48:
49: $qlimit=shift||500;
50: $times=shift||1;
51:
52: die "Undefined \$maxwsize! check your chgk.cnf" unless $maxwsize;
53:
54: require "check.pl";
55:
56: open (STDERR,">$stderr") if $stderr;
57:
58:
59: open (UNKNOWN,">$unknown");
60:
61:
62:
63: my $nf;
64:
65: #open WARN, ">$warnings";
66:
67: #%forbidden=checktable('equalto')? getequalto : ();
68:
69:
70: if ((uc 'а') ne 'А') {die "!Koi8-r locale not installed!\n"};
71:
72: getquestions(QuestionId, Question, Answer, Comments, Authors, Sources,"ProcessedBySearch IS NULL");
73:
74:
75:
76: print "Loading dictionaries\n";
77:
78: die "No dictionaries! Check your chgk.cnf" unless scalar @dictionaries;
79:
80: foreach $d(@dictionaries)
81: {
82: print "Loading $d\n";
83: open (DICT, $d) || print " Not found\n";
84: while ( <DICT> )
85: {
86: chomp;
87: s/\s*$//;
88: ($aa,$b)=split(/\//);
89: $aa=~tr/ёЁ/еЕ/;
90: $a= uc $aa;
91: $words{$a}.=$b || "!";
92: }
93: close(DICT);
94: }
95:
96: die "No dictionaries found! Check your chgk.cnf" unless scalar keys %words;
97:
98:
99: print "Getting words...\n";
100:
101: print TIME "\t\t".(time-$initime)."\n";
102: my $broken=0;
103:
104: for my $commonI(1..$times)
105: {
106: last if $broken;
107:
108: print "loading nests\n";
109:
110: %nf=getnests;
111:
112: %nfnumber=getnfnumbers;
113:
114: print "Getting words...\n";
115:
116: getquestions(QuestionId, Question, Answer, Comments, Authors, Sources,"ProcessedBySearch IS NULL");
117: $sch=0;
118: while ((++$sch<=$qlimit) && (($id, @ss) = getrow, $id))
119: # берём по одному вопросу
120: # и вешаем в массив, индексы которого -- словоформы,
121: # а значения -- списки вопросов.
122: {
123: if (-e "RS_stop") {unlink("RS_stop"); $broken=1;last}
124: print "$sch $id\n" unless ($sch % 10);#unless (++$sch % 1);
125: searchmark($id);
126: if ($forbidden{$id}) {next};
127: foreach $fieldnumber (0..$#ss) #перебираем поля
128: {
129: $text=$ss[$fieldnumber];
130: next unless $text;
131: $text=~tr/ёЁ/еЕ/;
132: $text=~s/(${RLrl})p(${RLrl})/$1p$2/gom;
133: $text=~s/p(${RLrl})/р$1/gom;
134: $text=~s/(${RLrl})p/$1р/gom;
135: $text=~s/\s+/ /gmo;
136: @list= $text=~m/(?:(?:${RLrl})+)|(?:[A-Za-z0-9]+)/gom;
137:
138: foreach $wordnumber(0..$#list)
139: {
140: $word=uc $list[$wordnumber];
141: next if length $word>$maxwsize;
142: if (my $n=$nf{$word}||$newnf{$word})
143: {
144: @n= split ' ',$n;
145: $nfkvo{$_}++ foreach @n;
146: my $r=packword($fieldnumber, $id,$wordnumber%256);
147: $neww2k{$_}.=$r foreach (@n);
148: }
149: else {
150: if ($word=~/^${RLrl}+$/o){ # Русское слово
151: # проанализировать по таблице аффиксов,
152: # проверить наличие начальных форм в
153: # nf, а если таких нет, то
154: # и по словарю.
155:
156: $nf=&checkit(uc $word,\%words);
157: if (!$nf) {
158: $nf=(uc $word)."/!";
159: print UNKNOWN "$nf\n" if $unknown;
160: }
161:
162: } else {# нерусское слово
163: $nf=(uc $word)."/!";
164: print UNKNOWN "$nf\n" if $unknown;
165: }
166:
167: foreach $n (split ' ', $nf)
168: {
169: ($f,$flag)=split '/', $n;
170: if ($nfnumber=$nfnumber{$f})
171: {
172: $newnf{$word}.=" $nfnumber";
173: $nfkvo{$nfnumber}++;
174: $a=\$neww2k{$nfnumber};
175: my $r=packword($fieldnumber, $id,$wordnumber);
176: $$a.=$r;
177: if (length $$a>100) {flushw2k($nfnumber)}
178: }
179: else
180: {
181: $nfnumber=addnf(0, $f, $flag,1);
182: $newnf{uc $word}.=" $nfnumber";
183: my $r=packword($fieldnumber, $id,$wordnumber);
184: $neww2k{$nfnumber}.=$r;
185: }
186: }
187: }
188:
189: }
190: }
191:
192: }
193:
194:
195: print "Filling word2question...\n";
196:
197: foreach (keys %neww2k)
198: {
199: updateword2question($_,$neww2k{$_});
200: delete $neww2k{$_};
201: }
202:
203: %neww2k=();
204:
205: print "Filling nf...\n";
206: $sch=0;
207:
208: incnf($_,$nfkvo{$_}) foreach (keys %nfkvo);
209:
210: %nfkvo=();
211:
212: print "Filling nests...\n";
213: $sch=0;
214:
215:
216: foreach $w (keys %newnf)
217: {
218: print "$sch\n" unless (++$sch % 1000);
219: @nf=split ' ',$newnf{$w};
220: addnest($w,$_) foreach @nf;
221: }
222: print "$sch nests added\n";
223:
224: print TIME "$commonI: \t$sch ";
225: print TIME "\t".(time-$initime)."\n";
226: %newnf=();
227:
228: }
229:
230: sub flushw2k
231: {
232: my ($n)=@_;
233: updateword2question($n,$neww2k{$n});
234: delete $neww2k{$_};
235: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>