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: $a= uc $aa;
90: $words{$a}.=$b || "!";
91: }
92: close(DICT);
93: }
94:
95: die "No dictionaries found! Check your chgk.cnf" unless scalar keys %words;
96:
97:
98: print "Getting words...\n";
99:
100: print TIME "\t\t".(time-$initime)."\n";
101:
102: for my $commonI(1..$times)
103: {
104:
105:
106: print "loading nests\n";
107:
108: %nf=getnests;
109:
110: %nfnumber=getnfnumbers;
111:
112: print "Getting words...\n";
113:
114: getquestions(QuestionId, Question, Answer, Comments, Authors, Sources,"ProcessedBySearch IS NULL");
115: $sch=0;
116: while ((++$sch<=$qlimit) && (($id, @ss) = getrow, $id))
117: # берём по одному вопросу
118: # и вешаем в массив, индексы которого -- словоформы,
119: # а значения -- списки вопросов.
120: {
121:
122: print "$sch $id\n" ;#unless (++$sch % 1);
123: searchmark($id);
124: if ($forbidden{$id}) {next};
125: foreach $fieldnumber (0..$#ss) #перебираем поля
126: {
127: $text=$ss[$fieldnumber];
128: next unless $text;
129: $text=~tr/ёЁ/еЕ/;
130: $text=~s/(${RLrl})p(${RLrl})/$1p$2/gom;
131: $text=~s/p(${RLrl})/р$1/gom;
132: $text=~s/(${RLrl})p/$1р/gom;
133: $text=~s/\s+/ /gmo;
134: @list= $text=~m/(?:(?:${RLrl})+)|(?:[A-Za-z0-9]+)/gom;
135:
136: foreach $wordnumber(0..$#list)
137: {
138: $word=uc $list[$wordnumber];
139: next if length $word>$maxwsize;
140: if (my $n=$nf{$word}||$newnf{$word})
141: {
142: @n= split ' ',$n;
143: $nfkvo{$_}++ foreach @n;
144: $neww2k{$_}.=packword($fieldnumber, $id,$wordnumber%256)
145: foreach (@n);
146: }
147: else {
148: if ($word=~/^${RLrl}+$/o){ # Русское слово
149: # проанализировать по таблице аффиксов,
150: # проверить наличие начальных форм в
151: # nf, а если таких нет, то
152: # и по словарю.
153:
154: $nf=&checkit(uc $word,\%words);
155: if (!$nf) {
156: $nf=(uc $word)."/!";
157: print UNKNOWN "$nf\n" if $unknown;
158: }
159:
160: } else {# нерусское слово
161: $nf=(uc $word)."/!";
162: print UNKNOWN "$nf\n" if $unknown;
163: }
164:
165: foreach $n (split ' ', $nf)
166: {
167: ($f,$flag)=split '/', $n;
168: if ($nfnumber=$nfnumber{$f})
169: {
170: $newnf{$word}.=" $nfnumber";
171: $nfkvo{$nfnumber}++;
172: $a=\$neww2k{$nfnumber};
173: $$a.=packword($fieldnumber, $id,$wordnumber);
174: if (length $$a>100) {flushw2k($nfnumber)}
175: }
176: else
177: {
178: $nfnumber=addnf(0, $f, $flag,1);
179: $newnf{uc $word}.=" $nfnumber";
180: $neww2k{$nfnumber}.=packword($fieldnumber, $id,$wordnumber);
181: }
182: }
183: }
184:
185: }
186: }
187:
188: }
189:
190:
191: print "Filling word2question...\n";
192:
193: foreach (keys %neww2k)
194: {
195: updateword2question($_,$neww2k{$_});
196: delete $neww2k{$_};
197: }
198:
199: %neww2k=();
200:
201: print "Filling nf...\n";
202: $sch=0;
203:
204: incnf($_,$nfkvo{$_}) foreach (keys %nfkvo);
205:
206: %nfkvo=();
207:
208: print "Filling nests...\n";
209: $sch=0;
210:
211:
212: foreach $w (keys %newnf)
213: {
214: print "$sch\n" unless (++$sch % 1000);
215: @nf=split ' ',$newnf{$w};
216: addnest($w,$_) foreach @nf;
217: }
218: print "$sch nests added\n";
219:
220: print TIME "$commonI: \t$sch ";
221: print TIME "\t".(time-$initime)."\n";
222: %newnf=();
223:
224: }
225:
226: sub flushw2k
227: {
228: my ($n)=@_;
229: updateword2question($n,$neww2k{$n});
230: delete $neww2k{$_};
231: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>