script/NanoB2BNER.pl untested

filter: Statementstmt 0.0% 0 / 125 Branchbran 0.0% 0 / 52 Conditioncond 0.0% 0 / 2 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 190 SCAR 6.9
CC
1
Cov
0%
showHelp
2.0
minimalUsageNotes
2.0
showVersion
2.0
CRAP 2.0
1 #!/usr/local/bin/perl
2  
3 =head1 NAME
4  
5 NanoB2BNER.pl - This program provides an example of using the
6 ner methods in NanoB2B::NER
7  
8 =head1 SYNOPSIS
9  
10 This program provides an example of using the ner methods in
11 NanoB2B::NER
12  
13 =head1 USAGE
14  
15 Usage: NanoB2BNER.pl [OPTIONS]
16  
17 =head1 OPTIONS
18  
19 Optional command line arguements
20  
21 =head2 Options (* = required):
22  
23 =head3 --help
24  
25 Displays a brief summary of program options.
26  
27 =head3 *--dir
28  
29 The name of the directory that contain the files
30  
31 =head3 *--features STR
32  
33 Get the list of features you want to use for the set
34 Ex. "ortho morph text pos cui sem"
35  
36 =head3 --debug
37  
38 Sets the debug flag on for testing
39  
40 =head3 --process STR
41  
42 Decide how to run NNER (by method or by file)
43 Ex/ "file" = each method processes the file before going to the next
44 Ex/ "method" = each file is run the the method before going to the next method
45  
46 =head3 --index NUM
47  
48 Starts the program at a certain index number in a directory
49  
50 =head3 --file STR
51  
52 Defines the file source of a single article
53  
54 =head3 --sort
55  
56 Option to sort the directory files by size
57  
58 =head3 --import_meta
59  
60 Runs the program with the pre-made meta data
61  
62 =head3 --stopwords
63  
64 Eliminates stop words from vectors in the ARFF files
65  
66 =head3 --buckets NUM
67  
68 The number of buckets for the k-fold cross validation
69  
70 =head3 --prefix NUM
71  
72 Sets the prefix character amount for morph features
73  
74 =head3 --suffix NUM
75  
76 Sets the suffix character amount for morph features
77  
78 =head3 --weka_type STR
79  
80 Sets the type of weka algorithm to use on the data
81  
82 =head3 --weka_size STR
83  
84 Sets the maximum memory value to run weka with
85  
86 =head1 SYSTEM REQUIREMENTS
87  
88 =over
89  
90 =item * Perl (version 5.8.5 or better) - http://www.perl.org
91  
92 =back
93  
94 =head1 CONTACT US
95
96 If you have any trouble installing and using NanoB2B-NER,
97 please contact us:
98  
99 Megan Charity : charityml at vcu.edu
100  
101 =head1 AUTHOR
102  
103 Megan Charity, Virginia Commonwealth University
104 Bridget T. McInnes, Virginia Commonwealth University
105  
106 =head1 COPYRIGHT
107  
108 Copyright (c) 2017
109  
110 Megan Charity, Virginia Commonwealth University
111 charityml at vcu.edu
112  
113 Bridget T. McInnes, Virginia Commonwealth University
114 btmcinnes at vcu.edu
115  
116 This program is free software; you can redistribute it and/or modify it under
117 the terms of the GNU General Public License as published by the Free Software
118 Foundation; either version 2 of the License, or (at your option) any later
119 version.
120  
121 This program is distributed in the hope that it will be useful, but WITHOUT
122 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
123 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
124  
125 You should have received a copy of the GNU General Public License along with
126 this program; if not, write to:
127  
128 The Free Software Foundation, Inc.,
129 59 Temple Place - Suite 330,
130 Boston, MA 02111-1307, USA.
131  
132 =cut
133  
134 #################### IMPORTS ###################
135  
136 use Getopt::Long; #options
137 use Getopt::Long qw(GetOptions); #shorten option length
138  
139 use NanoB2B::NER;
140  
141  
142 ################# OPTIONS #####################
143  
144 eval(GetOptions("help", "dir=s", "features=s", "debug", "process=s", "file=s", "sort", "import_meta", "stopwords=s", "is_cui", "sparse_matrix", "prefix=i", "suffix=i", "index=i", "wcs=s", "weka_type=s", "weka_size=s", "buckets=i", "mm_arg=s")) or die ("Check your options!\n");
145  
146 my %params = ();
147 my $process = "";
148  
149 # if help is defined, print out help
150 if( defined $opt_help ) {
151 $opt_help = 1;
152 &showHelp;
153 exit;
154 }
155  
156 #required parameters
157 if(defined $opt_dir){ #get the name of the directory to look in
158 $params{'dir'} = $opt_dir;
159 print "---Opening directory: \"$opt_dir\"---\n";
160 }
161 if(defined $opt_features){ #grab the features you want to use
162 $params{'features'} = $opt_features;
163 }
164  
165 #optional parameters
166 if(defined $opt_debug){ #have the debug print statements
167 $params{'debug'} = 1;
168 print("---DEBUG MODE---\n")
169 }
170  
171 if(defined $opt_process){
172 $process = $opt_process;
173 }else{
174 $process = "file";
175 }
176  
177 if(defined $opt_file){ #if using one file
178 $params{'file'} = $opt_file;
179 if(! (-e "$opt_dir/$opt_file")){
180 print "$opt_file DNE";
181 }else{
182 print "---Opening file: \"$opt_file\"---\n";
183 }
184 }
185  
186 if(defined $opt_sort){ #sort the directory to access the files by smallest first
187 $params{'sortBySize'} = $opt_sort;
188 print("---SORTING DIRECTORY FILES BY SIZE---\n");
189 }
190  
191 if(defined $opt_buckets){ #set the number of buckets to run
192 $params{'buckets'} = $opt_buckets;
193 }
194  
195 if(defined $opt_index){ #start at a certain file given an index
196 $params{'index'} = $opt_index;
197 }
198  
199 if(defined $opt_stopwords){
200 $params{'stopwords'} = $opt_stopwords;
201 print("---ELIMINATING STOP WORDS w/ $opt_stopwords file---\n"); #have the debug print statements
202 }
203  
204 if(defined $opt_is_cui){
205 $params{'is_cui'} = 1;
206 print("---EXCLUDING VECTORS FOR WORDS WITHOUT CUIS---");
207 }else{
208 $params{'is_cui'} = 0;
209 }
210  
211 if(defined $opt_sparse_matrix){
212 $params{'sparse_matrix'} = 1;
213 print("---USING SPARSE MATRIX GENERATION---");
214 }else{
215 $params{'sparse_matrix'} = 0;
216 }
217  
218 if(defined $opt_import_meta){
219 $params{'import_meta'} = 1;
220 print("---Importing MetaMap Data---\n"); #grab metamap file instead of make them
221 }else{
222 $params{'import_meta'} = 0;
223 print("---Creating MetaMap Data---\n");
224 }
225  
226 if(defined $opt_prefix){ #get the word prefix character count
227 $params{'prefix'} = $opt_prefix;
228 }
229 if(defined $opt_suffix){ #get the word suffix character count
230 $params{'suffix'} = $opt_suffix;
231 }
232  
233 if(defined $opt_wcs){
234 $params{'wcs'} = $opt_wcs;
235 print("---RUNNING WORSE CASE SCENARIO: $opt_wcs---\n");
236 }
237  
238 if(defined $opt_weka_type){
239 $params{'weka_type'} = $opt_weka_type;
240 print("---RUNNING $weka_type WEKA---\n"); #average the weka accuracies
241 }
242  
243 if(defined $opt_weka_size){
244 $params{'weka_size'} = $opt_weka_size;
245 print("---MAXIMUM WEKA MEMORY = $opt_weka_size---\n"); #average the weka accuracies
246 }
247 if(defined $opt_metamap_arguments){
248 $params{'mm_arg'} = $opt_metamap_arguments;
249 }
250 else{
251 $params{'mm_arg'} = "-q";
252 }
253  
254 #help screen
255 sub showHelp{
256 print("###### THIS PROGRAM TURNS NANOPARTICLE TEXTS ######\n");
257 print("###### INTO ARFF FILES AND WEKA ACCURACY FILES ######\n");
258 print("###### BASED ON THE NANOPARTICLE CHARACTERISTICS ######\n");
259 print("###### FOUND FROM THE PRE-ANNOTATED ARTICLES ######\n");
260 print("\n");
261 print("\n");
262 print("--help Opens this help screen\n");
263 print("\n");
264 print("*** REQUIRED PARAMETERS ***\n");
265 print("--dir STR Defines the directory of a set of articles\n");
266 print("--features STR[s] Get the list of features you want to use for the set\n");
267 print(" --> \"ortho morph text pos cui sem\"\n");
268 print("\n");
269 print("*** OPTIONAL PARAMETERS ***\n");
270 print("--debug Runs the program with debugging print statements\n");
271 print("--process STR Decide how to run NNER (by method or by file)\n");
272 print(" --> \"file\"=each method processes the file before going to the next\n");
273 print(" --> \"method\"=each file is run in the method before going to the next\n");
274 print(" --> \"meta\", \"arff\", \"weka\", or \"avg\"=run this process on the set\n");
275 print("--index NUM Starts the program at a certain index number in a directory\n");
276 print("--file STR Defines the file source of a single article\n");
277 print("--sort Option to sort the directory files by size\n");
278 print("--import_meta Runs the program with the pre-made meta data\n");
279 print("--mm_arg STR Runs MetaMap with specified arguments\n");
280 print("--stopwords STR Eliminates stop words from vectors in the ARFF files with the specified file\n");
281 print("--is_cui Creates a vector for a word only if it has a CUI associated with it\n");
282 print("--sparse_matrix Generates the vectors as a sparse matrix\n");
283 print("--buckets NUM The number of buckets for the k-fold cross validation\n");
284 print("--prefix NUM Sets the prefix character amount for morph features\n");
285 print("--suffix NUM Sets the suffix character amount for morph features\n");
286 print("--wcs STR Worst-case-scenario -- start from a set bucket and feature set\n");
287 print(" --> FORMAT: '(bucket #)-(feature abbreviation)\n");
288 print("--weka_type STR Sets the type of weka algorithm to use on the data\n");
289 print("--weka_size STR Sets the maximum memory value to run weka with\n");
290 print(" --> (ex. -Xmx2G, -Xmx6G, -Xmx64G)\n");
291 print("\n");
292 print("*** Example command: ***\n");
293 print("perl NanoB2BNER.pl --dir my_directory --features=\"ortho morph text pos cui sem\" --debug --process=\"file\" --buckets=5 --import --index=18 --weka_type weka.classifiers.functions.SMO --weka_size=\"-Xmx6G\" --wcs=\"5-tpc\"\n");
294 }
295  
296  
297 # function to output minimal usage notes
298 sub minimalUsageNotes {
299
300 print "Usage: NanoB2BNER.pl --dir DIRECTORYNAME --features FEATURESET [OPTIONS]\n";
301 &askHelp();
302 exit;
303 }
304  
305 # function to output the version number
306 sub showVersion {
307 print '$Id: NanoB2BNER.pl,v 1.00 2017/02/22 13:47:05 btmcinnes Exp $';
308 print "\nCopyright (c) 2017, Megan Charity & Bridget McInnes\n";
309 }
310  
311 # function to output "ask for help" message when user's goofed
312 sub askHelp {
313 print STDERR "Type MetaMapDataStructures.pl --help for help.\n";
314 }
315
316  
317 ######################### test code ######################
318  
319 my $nner = NanoB2B::NER->new(\%params);
320 if($process eq "file"){
321 $nner->nerByFile();
322 }elsif($process eq "method"){
323 $nner->nerByMethod();
324 }elsif($process eq "meta"){
325 $nner->metaSet();
326 }elsif($process eq "arff"){
327 $nner->arffSet();
328 }elsif($process eq "weka"){
329 $nner->wekaSet();
330 }elsif($process eq "avg"){
331 $nner->avgSet();
332 }else{
333 print("***ERROR: INVALID PROCESS METHOD FOR NNER!***\n");
334 exit;
335 }