blib/lib/Text/Statistics/Latin.pm

filter: Statementstmt 12.1% 27 / 222 Branchbran 0.0% 0 / 76 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 85.7% 6 / 7 Podpod 0.0% 0 / 1 totaltotal 10.7% 33 / 306 CC 52 SCAR 78.1
CC
52
Cov
9%
LATIN
2756.0
BEGIN
1.0
BEGIN
1.0
CRAP 2471.0
↑ Summary
1 package Text::Statistics::Latin;
2
3
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶no warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6
7 1 require Exporter;
8
9 1 our @ISA = qw(Exporter);
10
11 =head1 NAME
12
13 Text::Statistics::Latin - Performs statistical analysis of corpora
14
15 =head1 VERSION
16
17 Version 0.06
18
19 =cut
20
21 1 our $VERSION = '0.06';
22 1 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 1 ▶use Text::ParseWords;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 1 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 1 ▶use base 'Exporter';
Subroutine BEGIN: called CC=1 SCAR=0.0
26
27 1 our @EXPORT = qw(LATIN);
28 1 our @words;
29 1 our $tokens;
30 1 our @out11;
31 1 our @outtott;
32 1 our $tokensgeral;
33
34 =head1 SYNOPSIS
35 use CText::CStatiBR;
36 &Text::CStatiBR::CSTATIBR();
37
38 DESCRIPTION
39
40 Given a copus as input, Text::Statistics::Latin creates a seven column
41 CSV file as output, with one line for each token per text. Names of
42 input files need match the following pattern:
43
44 1 (1). txt', '1 (2). txt', ..., '1 (n).txt'
45
46 or
47
48 1 \(([1-9]|[1-9][0-9]+)\)\.txt
49
50 Columns store statistical information:
51
52 (1) number of word forms in document d;
53 (2) number of tokens in d;
54 (3) Id number of d, ie., n;
55 (4) frequency of term t in d;
56 (5) corpus frequency of t ;
57 (6) document frequency of t (number of documents where t occurs at
58 + least once);
59 (7) t, UTF8 latin coded token-string delimited by C<< /[ -@]|[\[-`
60 +]|[{-¿]|[&#592;-&#745;]|[&#884;-&#65533;]/ >>
61
62 Main output file name is '1 (n + 5).txt' and it is stored in the s
63 +ame directory as
64 the corpus, together with residual files on each input file with .
65 +txu and .txv ad hoc extensions.
66
67 This code was written under CAPES BEX-09323-5
68
69 Example:
70
71 #!/usr/bin/perl
72 use strict;
73 use Text::CStatiBR;
74
75 &Text::CStatiBR::CSTATIBR("5"); #5 files are analised.
76 #Main output
77 #file created is
78 #1 (10).txt
79
80 =head1 EXPORT
81
82 &LATIN();
83
84 =cut
85
86 0 ▶sub LATIN{
Subroutine LATIN: not called CC=52 SCAR=79.2
Pod undocumented
87
88 0 print "inicio de programa, aguardes", "\n";
89 0 my $min = 1; #number of start file
90 0 our $max=shift;
91
92 0 my $dif = $max - $min;
93 0 my $tempo = 1;
94
95 0 ▶ while ($tempo < 3){ #start and meta procedures limitation
Branch: 1 branch
BranchTrueFalseTotal
if ($tempo < 3) 0 0 0
96 0 my $nome4 = "1 ($max).txt"; #file of sharing for document frrequency calculation
97 0 my $nome5 = "registro1 ($max).txt"; #log file for data and metadata
98 0 ▶ open (our $result, ">", $nome4) || die "Não posso escrever $nome4: $!";
Branch: 1 branch
BranchTrueFalseTotal
open our $result, ">", $nome4 or die "N\343o posso escrever ${nome4}: $!" 0 0 0
99 0 ▶ open (my $registro, ">", $nome5) || die "Não posso escrever $nome5: $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $registro, ">", $nome5 or die "N\343o posso escrever ${nome5}: $!" 0 0 0
100 0 my $num = $min; #number of start file
101 0 my $maximo = $max; #number of final file + 1
102 0 ▶ while ($num < $maximo){
Branch: 1 branch
BranchTrueFalseTotal
if ($num < $maximo) 0 0 0
103
104 0 my $nome1 = "1 ($num).txt"; #text file
105 0 my $nome2 = "1 ($num).txu"; #\sToken\n
106 0 my $nome3 = "1 ($num).txv"; #file number,frequency,\sType
107
108 0 my $i = 1; #fisrt string
109 0 my $reg = /\r\n/; #needed for UTF-8 cleaning
110 0 my $reg2 = /\s/; #see http://unicode.org/reports/tr13/tr13-5.html
111
112 ###start of tokens
113
114 0 ▶ open (my $in, "<", $nome1) || die "Can not open", $nome1, ": $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $in, "<", $nome1 or die "Can not open", $nome1, ": $!" 0 0 0
115 0 ▶ open (my $out, ">", $nome2) || die "Can not write", $nome2, ": $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $out, ">", $nome2 or die "Can not write", $nome2, ": $!" 0 0 0
116 0 print "inicio de tokenização, aguardes", "\n";
117
118 0 while (1) {
119 0 my $line = <$in>;
120 0 our $tokens = $i;
121 0 ▶ last unless $line;
Branch: 1 branch
BranchTrueFalseTotal
unless $line 0 0 0
122 0 for ($line) {
123 0 s/[-@]|[\[-`]|[{-¿]|[ɐ-˩]|[ʹ-�]/ /g; #delimiters of latin coded texts
124 }
125 0 @words = &shellwords(' ', 0, $line); #previous delimiter: \s+
126 0 foreach (@words) {
127 0 ▶ unless ($_ eq "s+"|$_ eq "0"|$_ eq $reg|$_ eq $reg2){ #last cleaning
Branch: 1 branch
BranchTrueFalseTotal
unless ($_ eq "s+" | $_ eq 0 | $_ eq $reg | $_ eq $reg2) 0 0 0
128 0 print $out " $_\n";
129 0 $i++;
130 }
131 }
132 }
133 0 close $in;
134
135 0 ▶ if ($tempo < 2){
Branch: 1 branch
BranchTrueFalseTotal
if ($tempo < 2) 0 0 0
136 0 our $tokensgeral = $tokensgeral + $tokens;
137 }
138 0 close $out;
139 0 print "fim de tokenização", "\n";
140 0 print "início de typeficação, aguardes", "\n";
141
142 # start of types
143
144 0 my $ii = ($i - 1); #last string processed in the previous procedure - 1
145 0 ▶ open (my $in2, "<", $nome2) || die "Can not open $nome2: $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $in2, "<", $nome2 or die "Can not open ${nome2}: $!" 0 0 0
146 0 ▶ open (my $out2, ">", $nome3) || die "Can not write $nome3: $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $out2, ">", $nome3 or die "Can not write ${nome3}: $!" 0 0 0
147 0 our @lista = <$in2>;
148 0 my $controle2 = 0;
149 0 my $types = 0;
150 0 ▶ while ($controle2 < $ii){
Branch: 1 branch
BranchTrueFalseTotal
if ($controle2 < $ii) 0 0 0
151 0 our $inicio = -1;
152 0 my $controle = 0; #term frequency
153 0 my $pesquisa = $lista[$controle2]; #searched terms
154 0 while (1){
155 0 ▶ last unless ($lista[$inicio]);
Branch: 1 branch
BranchTrueFalseTotal
unless $Text::Statistics::Latin::lista[$Text::Statistics::Latin::inicio] 0 0 0
156 0 foreach ($lista[$inicio]){
157 0 $inicio++;
158 0 ▶ if ($lista[$inicio] =~ /$pesquisa/i){ #finds the word
Branch: 1 branch
BranchTrueFalseTotal
if ($Text::Statistics::Latin::lista[$Text::Statistics::Latin::inicio] =~ /$pesquisa/i) 0 0 0
159 0 $controle++; #increases a "bean"
160 }
161 }
162 }
163 0 ▶ if ($controle < $ii){
Branch: 1 branch
BranchTrueFalseTotal
if ($controle < $ii) 0 0 0
164 0 $types++;
165 0 print $out2 "$num,$controle,$pesquisa";
166 0 print $result $num, ",", $controle, ",", $pesquisa; #not yet...
167 }
168 0 for (@lista){
169 0 s/$pesquisa/\n/i; #cleans previous data
170 }
171 0 $controle2++;
172 }
173 0 print "Foram encontrados ", $types, " types no arquivo ", $nome1, "!", "\n";
174 0 print $registro $types, ",", $ii, ",", $nome1, "\n";
175 0 close $in2;
176 0 close $out2;
177 0 $num++;
178 }
179 0 close $result;
180 0 $tempo++; #increases a been in time
181 0 $min = $max; #changes target intervalls
182 0 $max++; #for meta-data extraction
183 0 print "fim de typeficação", "\n";
184 0 print "início de primeira contagem, aguardes", "\n";
185
186 #start of collection frequency
187
188 0 ▶ if ($tempo == 3){
Branch: 1 branch
BranchTrueFalseTotal
if ($tempo == 3) 0 0 0
189 0 do{
190 0 $num = $num - 1;
191 0 my $nome1 = "1 ($num).txv";
192 0 my $nome2 = "1 ($num).txt";
193
194 0 $num = $num + 2;
195 0 my $nome3 = "1 ($num).txt";
196
197 0 ▶ open (my $in1, "<", $nome1) || die "Não posso abrir $nome1: $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $in1, "<", $nome1 or die "N\343o posso abrir ${nome1}: $!" 0 0 0
198 0 ▶ open (my $in2, "<", $nome2) || die "Não posso abrir $nome2: $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $in2, "<", $nome2 or die "N\343o posso abrir ${nome2}: $!" 0 0 0
199 0 ▶ open (my $out1, ">", $nome3) || die "Não posso escrever $nome3: $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $out1, ">", $nome3 or die "N\343o posso escrever ${nome3}: $!" 0 0 0
200
201 0 my @in1 = <$in1>;
202 0 my @in2 = <$in2>;
203
204 0 my $tempo1 = 0;
205
206 0 ▶ while ($in1[$tempo1]){
Branch: 1 branch
BranchTrueFalseTotal
if ($in1[$tempo1]) 0 0 0
207 0 my $linha1 = $in1[$tempo1];
208 0 for ($linha1){
209 0 s/.+,.+, / /g;
210 }
211 0 my $tempo2 = 0;
212 0 my $cont = 0;
213 0 ▶ while ($in2[$tempo2]){
Branch: 1 branch
BranchTrueFalseTotal
if ($in2[$tempo2]) 0 0 0
214 0 my $linha2 = $in2[$tempo2];
215 0 ▶ if ($linha2 =~ /.+,.+,$linha1/i){
Branch: 1 branch
BranchTrueFalseTotal
if ($linha2 =~ /.+,.+,$linha1/i) 0 0 0
216 0 for ($linha2){
217 0 s/[^0-9]/ /ig;
218 0 s/[0-9]+\s//;
219 }
220 0 for ($linha2){
221 0 $cont = $cont + $linha2;
222 }
223 }
224 0 $tempo2++;
225 }
226 0 $out11[$tempo1] = "$cont,$linha1"; #ok
227 0 $tempo1++;
228 }
229 0 close $in1;
230 0 close $in2;
231 0 print $out1 @out11;
232 0 close $out1;
233 0 print "fim de primeira contagem", "\n"; };
234
235 #start of unification: tf df cf
236 #cf,df, termo, file
237
238 0 do{
239 0 print "início de terceira contagem, aguardes", "\n";
240 0 my $numm = $num - 2;
241 0 my $nome2 = "1 ($num).txt";
242 0 ▶ open (my $incf, "<", $nome2) || die "Não posso abrir $nome2: $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $incf, "<", $nome2 or die "N\343o posso abrir ${nome2}: $!" 0 0 0
243 0 $num = $num - 1;
244 0 $nome2 = "1 ($num).txt";
245 0 ▶ open (my $indf, "<", $nome2) || die "Não posso abrir $nome2: $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $indf, "<", $nome2 or die "N\343o posso abrir ${nome2}: $!" 0 0 0
246 0 $num = $num + 2;
247 0 $nome2 = "1 ($num).txt";
248 0 ▶ open (my $out, ">", $nome2) || die "Não posso abrir $nome2: $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $out, ">", $nome2 or die "N\343o posso abrir ${nome2}: $!" 0 0 0
249
250 0 my @lista1 = <$indf>;
251 0 my @lista2 = <$incf>;
252 0 my $linha = 0;
253
254 0 while(1){
255 0 ▶ last unless ($lista1[$linha]);
Branch: 1 branch
BranchTrueFalseTotal
unless $lista1[$linha] 0 0 0
256 0 for ($lista1[$linha]){
257 0 s/$numm,//i;
258 }
259 0 for ($lista2[$linha]){
260 0 s/, .+//;
261 0 s/\n//;
262 }
263 0 print $out "$lista2[$linha],$lista1[$linha]";
264 0 $linha = $linha + 1;
265 }
266 0 close $out;
267 0 close $incf;
268 0 close $indf;
269 0 print "fim de terceira contagem", "\n";
270
271 #last unification: doc, tf, cf, df, termo, last txt
272
273 0 print "inicio de unificação, aguardes", "\n";
274 0 ▶ open (my $incfdf, "<", $nome2) || die "Não posso abrir $nome2: $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $incfdf, "<", $nome2 or die "N\343o posso abrir ${nome2}: $!" 0 0 0
275 0 $num = $num - 3;
276 0 $nome2 = "1 ($num).txt";
277 0 ▶ open (my $intf, "<", $nome2) || die "Não posso abrir $nome2: $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $intf, "<", $nome2 or die "N\343o posso abrir ${nome2}: $!" 0 0 0
278 0 $num = $num + 4;
279 0 $nome2 = "1 ($num).txt";
280 0 ▶ open (my $outtot, ">", $nome2) || die "Não posso abrir $nome2: $!"; #file of last unification
Branch: 1 branch
BranchTrueFalseTotal
open my $outtot, ">", $nome2 or die "N\343o posso abrir ${nome2}: $!" 0 0 0
281 #text, tf, cf, df, term
282 0 my @listatf = <$intf>;
283 0 my @listadf = <$incfdf>;
284 0 my @listadf1 = @listadf;
285 0 my $linhatf = 0;
286
287 0 while (1){
288 0 ▶ last unless ($listatf[$linhatf]);
Branch: 1 branch
BranchTrueFalseTotal
unless $listatf[$linhatf] 0 0 0
289 0 my $linhadf = 0;
290 0 while (1){
291 0 ▶ last unless ($listadf[$linhadf]);
Branch: 1 branch
BranchTrueFalseTotal
unless $listadf[$linhadf] 0 0 0
292 0 for ($listadf[$linhadf]){
293 0 s/.+,.+,//;
294 }
295 0 ▶ if ($listatf[$linhatf] =~ /.+,.+,$listadf[$linhadf]/i){ #finds the line where df occurs
Branch: 1 branch
BranchTrueFalseTotal
if ($listatf[$linhatf] =~ /.+,.+,$listadf[$linhadf]/i) 0 0 0
296 #the term of each line of tf
297 0 for ($listatf[$linhatf]){
298 0 s/, .+\n/,/i;
299 }
300 0 $outtott[$listadf[$linhatf]] = "$listatf[$linhatf]$listadf1[$linhadf]";
301 }
302 0 $linhadf++;
303 }
304 0 print $outtot @outtott;
305 0 $linhatf++;
306 }
307 0 print "fim de unificação", "\n";
308 0 close $outtot;
309 0 close $intf;
310 0 close $incfdf;
311 0 print "inicio de unificação para Okapi BM 25", "\n";
312
313 #unification for Okapi data
314
315 0 my $znum = $num;
316 0 ▶ open (my $zincinco, "<", "1 ($znum).txt") || die "Não posso escrever registro1 ($znum).txt: $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $zincinco, "<", "1 ($znum).txt" or die "N\343o posso escrever registro1 ($znum).txt: $!" 0 0 0
317 0 my @zin2 = <$zincinco>;
318 0 my @zin3 = @zin2;
319 0 $znum++;
320 0 ▶ open (my $zoutx, ">", "1 ($znum).txt") || die "Não posso escrever 1 ($znum).txt: $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $zoutx, ">", "1 ($znum).txt" or die "N\343o posso escrever 1 ($znum).txt: $!" 0 0 0
321 0 $znum = $znum - 5;
322 0 ▶ open (my $zregistro, "<", "registro1 ($znum).txt") || die "Não posso escrever registro1 ($znum).txt: $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $zregistro, "<", "registro1 ($znum).txt" or die "N\343o posso escrever registro1 ($znum).txt: $!" 0 0 0
323 0 my @zin1 = <$zregistro>;
324 0 my $zindex = 0;
325 0 my $zinic = 0;
326 0 while (1){
327 0 ▶ last unless ($zin1[$zinic]);
Branch: 1 branch
BranchTrueFalseTotal
unless $zin1[$zinic] 0 0 0
328 0 my $zlinhac = 0;
329 0 for ($zin1[$zinic]){
330 0 s/1 .+\n//;
331 }
332 0 my $zinicc = $zinic + 1;
333 0 while (1){
334 0 ▶ last unless ($zin2[$zlinhac]);
Branch: 1 branch
BranchTrueFalseTotal
unless $zin2[$zlinhac] 0 0 0
335 0 for ($zin3[$zlinhac]){
336 0 s/,.+\n//;
337 }
338 0 ▶ if ("$zin3[$zlinhac]\n" =~ /$zinicc\n/){
Branch: 1 branch
BranchTrueFalseTotal
if (("$zin3[$zlinhac]\n") =~ /$zinicc\n/) 0 0 0
339 0 print $zoutx "$zin1[$zinic]$zin2[$zlinhac]";
340 0 $zindex++;
341 }
342 0 $zlinhac++;
343 }
344 0 $zinic++;
345 }
346 };
347 0 $tokensgeral = $tokensgeral - $dif;
348 0 print "Neste corpus há ", $tokensgeral, " tokens!", "\n"; #export this information for the last registry
349 }
350 }
351 0 print "\n", "fim de programa";
352 }
353 =head1 AUTHOR
354
355 Rodrigo Panchiniak Fernandes, C<< <fernandes at cpan.org> >>
356
357 =head1 BUGS
358
359 Please report any bugs or feature requests to
360 C<bug-text-statistics-latin at rt.cpan.org>, or through the web interface at
361 L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Text-Statistics-Latin>.
362 I will be notified, and then you'll automatically be notified of progress on
363 your bug as I make changes.
364
365 =head1 SUPPORT
366
367 You can find documentation for this module with the perldoc command.
368
369 perldoc Text::Statistics::Latin
370
371 You can also look for information at:
372
373 =over 4
374
375 =item * AnnoCPAN: Annotated CPAN documentation
376
377 L<http://annocpan.org/dist/Text-Statistics-Latin>
378
379 =item * CPAN Ratings
380
381 L<http://cpanratings.perl.org/d/Text-Statistics-Latin>
382
383 =item * RT: CPAN's request tracker
384
385 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Text-Statistics-Latin>
386
387 =item * Search CPAN
388
389 L<http://search.cpan.org/dist/Text-Statistics-Latin>
390
391 =back
392
393
394 =head1 COPYRIGHT & LICENSE
395
396 Copyright 2007 Rodrigo Panchiniak Fernandes, all rights reserved.
397
398 This program is free software; you can redistribute it and/or modify it
399 under the same terms as Perl itself.
400
401 Written under CAPES BEX-09323-5
402 =cut
403
404 1 1; # End of Text::Statistics::Latin
405 __END__
↑ Summary