script/sval2plain.pl untested

filter: Statementstmt 0.0% 0 / 38 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 0.0% 0 / 4 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 62 CC 1 SCAR 6.9
CC
1
Cov
0%
showminimal
2.0
showhelp
2.0
showversion
2.0
CRAP 2.0
1 #!/usr/local/bin/perl -w
2  
3 =head1 NAME
4  
5 sval2plain.pl - Convert a Senseval-2 data file into plain text format
6  
7 =head1 SYNOPSIS
8  
9 sval2plain.pl [OPTIONS] SVAL2
10  
11 Note that there are 255 instances (contexts) in the Senseval-2 formatted
12 input file.
13  
14 frequency.pl begin.v-test.xml
15  
16 OUTPUT =>
17
18 <sense id="begin%2:30:00::" percent="64.31"/>
19 <sense id="begin%2:30:01::" percent="14.51"/>
20 <sense id="begin%2:42:04::" percent="21.18"/>
21 Total Instances = 255
22 Total Distinct Senses=3
23 Distribution={64.31,21.18,14.51}
24 % of Majority Sense = 64.31
25  
26 After converting to plain text, note that there are 255 lines in that
27 file, one per context.
28  
29 sval2plain.pl begin.v-test.xml > begin.v-test.txt
30  
31 wc begin.v-test.txt
32  
33 OUTPUT =>
34  
35 255 15049 92598 begin.v-test.txt
36  
37 You can find L<begin.v-test.xml> in samples/Data
38  
39 You can type C<sval2plain.pl --help> for a quick summary of options
40  
41 =head1 DESCRIPTION
42  
43 Converts a given file from Senseval-2 format into plain text format. Each
44 line of the plain text files contains a single context. This is useful
45 when you have Senseval-2 data that you would like to use as feature
46 extraction (training) data, which much be in plain text format.
47  
48 =head1 INPUT
49  
50 =head2 Required Arguments:
51  
52 =head3 SVAL2
53  
54 Input file in Senseval-2 format that is to be converted into plain text format.
55  
56 =head2 Optional Arguments:
57  
58 =head3 --help
59  
60 Displays the summary of command line options.
61  
62 =head3 --version
63  
64 Displays the version information.
65  
66 =head1 OUTPUT
67  
68 sval2plain displays the given SVAL2 file in plain text format with the
69 contextual data of each instance on a separate line. Specifically, each
70 i'th line displayed on STDOUT shows the context of the i'th instance in
71 the given SVAL2 file.
72  
73 =head1 AUTHOR
74  
75 Ted Pedersen, University of Minnesota, Duluth
76 tpederse at d.umn.edu
77  
78 Amruta Purandare, University of Pittsburgh
79  
80 =head1 COPYRIGHT
81  
82 Copyright (c) 2002-2008, Ted Pedersen and Amruta Purandare
83  
84 This program is free software; you can redistribute it and/or modify it under
85 the terms of the GNU General Public License as published by the Free Software
86 Foundation; either version 2 of the License, or (at your option) any later
87 version.
88  
89 This program is distributed in the hope that it will be useful, but WITHOUT
90 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
91 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
92  
93 You should have received a copy of the GNU General Public License along with
94 this program; if not, write to
95  
96 The Free Software Foundation, Inc.,
97 59 Temple Place - Suite 330,
98 Boston, MA 02111-1307, USA.
99  
100 =cut
101  
102 ###############################################################################
103  
104 # THE CODE STARTS HERE
105  
106 #$0 contains the program name along with
107 #the complete path. Extract just the program
108 #name and use in error messages
109 $0=~s/.*\/(.+)/$1/;
110  
111 ###############################################################################
112  
113 # ================================
114 # COMMAND LINE OPTIONS AND USAGE
115 # ================================
116  
117 # command line options
118 use Getopt::Long;
119 GetOptions ("help","version");
120 # show help option
121 if(defined $opt_help)
122 {
123 $opt_help=1;
124 &showhelp();
125 exit;
126 }
127  
128 # show version information
129 if(defined $opt_version)
130 {
131 $opt_version=1;
132 &showversion();
133 exit;
134 }
135  
136 # show minimal usage message if no arguments
137 if($#ARGV<0)
138 {
139 &showminimal();
140 exit;
141 }
142  
143 #############################################################################
144  
145 # ================================
146 # INITIALIZATION AND INPUT
147 # ================================
148  
149 #accept the input file name
150 $infile=$ARGV[0];
151 if(!-e $infile)
152 {
153 print STDERR "ERROR($0):
154 SVAL2 file <$infile> doesn't exist...\n";
155 exit;
156 }
157 open(IN,$infile) || die "Error($0):
158 Error(code=$!) in opening <$infile> file.\n";
159  
160 ##############################################################################
161  
162 $data_start=0;
163 $context="";
164 while(<IN>)
165 {
166 chomp;
167 if(/<\/context>/)
168 {
169 print $context . "\n";
170 $data_start=0;
171 $context="";
172 }
173 if($data_start==1)
174 {
175 $context.="$_ ";
176 }
177 if(/<context>/)
178 {
179 $data_start=1;
180 }
181 }
182  
183 ##############################################################################
184  
185 # ==========================
186 # SUBROUTINE SECTION
187 # ==========================
188  
189 #-----------------------------------------------------------------------------
190 #show minimal usage message
191 sub showminimal()
192 {
193 print "Usage: sval2plain.pl [OPTIONS] SVAL2";
194 print "\nTYPE sval2plain.pl --help for help\n";
195 }
196  
197 #-----------------------------------------------------------------------------
198 #show help
199 sub showhelp()
200 {
201 print "Usage: sval2plain.pl [OPTIONS] SVAL2
202  
203 Converts a given file in Senseval-2 format to plain text format.
204  
205 SVAL2
206 Input file in Senseval-2 format.
207  
208 OPTIONS:
209 --help
210 Displays this message.
211 --version
212 Displays the version information.
213  
214 Type 'perldoc sval2plain.pl' to view detailed documentation of sval2plain.\n";
215 }
216  
217 #------------------------------------------------------------------------------
218 #version information
219 sub showversion()
220 {
221 print '$Id: sval2plain.pl,v 1.9 2008/03/29 20:52:30 tpederse Exp $';
222 # print "Copyright (c) 2002-2006, Ted Pedersen & Amruta Purandare\n";
223 # print "sval2plain.pl - Version 0.01\n";
224 print "\nConvert a Senseval-2 file into plain text\n";
225 # print "Date of Last Update: 06/02/2004\n";
226 }
227  
228 #############################################################################
229