Debian Codegraph @

src/04-ngram/03-SplitterCorpus.pl

raw
1 #!/usr/bin/perl
2 # Copyright (C) 2009-2011 Antonio Bonafonte
3 # Universitat Politècnica de Catalunya, Barcelona, Spain
4 #
5 # This script is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation,
8 # version 2.1 of the License.
9 #
10 # This library is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # Lesser General Public License for more details.
14 #
15 # You should have received a copy of the GNU Lesser General Public
16 # License along with this library; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
19 open (TRAIN, ">work/corpus.train");
20 open (TEST, ">work/corpus.test");
21 open (TRAIN_SENTENCES, ">work/corpus_frases.train");
22 open (TEST_SENTENCES, ">work/corpus_frases.test");
23 open (FR, 'work/corpus-ca-frase.out');
24 open (AR, 'work/corpus-ca.out');
25
26 $cont=0;
27 while(<AR>)
28 {
29 if($cont%20 eq 0) {
30 print TEST $_;
31 $cont++;
32 }
33 else {
34 print TRAIN $_;
35 $cont++;
36 }
37 }
38 $cont=0;
39 while(<FR>)
40 {
41 if($cont%20 eq 0) {
42 print TEST_SENTENCES $_;
43 $cont++;
44 }
45 else {
46 print TRAIN_SENTENCES $_;
47 $cont++;
48 }
49 }
50
51 close(TRAIN_SENTENCES);
52 close(TEST_SENTENCES);
53 close(FR);
54 close(AR);
55 close(TEST);
56 close(TRAIN);