script/NanoB2BNER.pl untested

filter: Statementstmt 0.0% 0 / 134 Branchbran 0.0% 0 / 56 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 204 CC 1 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", "model")) 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---\n");
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---\n");
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 if(defined $opt_model){
255 $params{'model'} = 1;
256 print("---MAKING MODELS WITH ARFF TRAIN DATA--\n");
257 }else{
258 $params{'model'} = 0;
259 }
260  
261 #help screen
262 sub showHelp{
263 print(" NanoB2B-NER -- Version 2.0 \n");
264 print(" ============================== \n");
265 print("\n");
266 print("###### THIS PROGRAM TURNS NANOPARTICLE TEXTS ######\n");
267 print("###### INTO ARFF FILES AND WEKA ACCURACY FILES ######\n");
268 print("###### BASED ON THE NANOPARTICLE CHARACTERISTICS ######\n");
269 print("###### FOUND FROM THE PRE-ANNOTATED ARTICLES ######\n");
270 print("\n");
271 print("\n");
272 print("--help Opens this help screen\n");
273 print("\n");
274 print("*** REQUIRED PARAMETERS ***\n");
275 print("--dir STR Defines the directory of a set of articles\n");
276 print("--features STR[s] Get the list of features you want to use for the set\n");
277 print(" --> \"ortho morph text pos cui sem\"\n");
278 print("\n");
279 print("*** OPTIONAL PARAMETERS ***\n");
280 print("--debug Runs the program with debugging print statements\n");
281 print("--process STR Decide how to run NNER (by method or by file)\n");
282 print(" --> \"file\"=each method processes the file before going to the next\n");
283 print(" --> \"method\"=each file is run in the method before going to the next\n");
284 print(" --> \"meta\", \"arff\", \"weka\", or \"avg\"=run this process on the set\n");
285 print("--index NUM Starts the program at a certain index number in a directory\n");
286 print("--file STR Defines the file source of a single article\n");
287 print("--sort Option to sort the directory files by size\n");
288 print("--import_meta Runs the program with the pre-made meta data\n");
289 print("--mm_arg STR Runs MetaMap with specified arguments\n");
290 print("--stopwords STR Eliminates stop words from vectors in the ARFF files with the specified file\n");
291 print("--is_cui Creates a vector for a word only if it has a CUI associated with it\n");
292 print("--sparse_matrix Generates the vectors as a sparse matrix\n");
293 print("--buckets NUM The number of buckets for the k-fold cross validation\n");
294 print("--prefix NUM Sets the prefix character amount for morph features\n");
295 print("--suffix NUM Sets the suffix character amount for morph features\n");
296 print("--wcs STR Worst-case-scenario -- start from a set bucket and feature set\n");
297 print(" --> FORMAT: '(bucket #)-(feature abbreviation)\n");
298 print("--weka_type STR Sets the type of weka algorithm to use on the data\n");
299 print("--weka_size STR Sets the maximum memory value to run weka with\n");
300 print(" --> (ex. -Xmx2G, -Xmx6G, -Xmx64G)\n");
301 print("--model Create models in WEKA using the train files\n");
302 print("\n");
303 print("*** Example command: ***\n");
304 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-omt\"\n");
305 }
306  
307  
308 # function to output minimal usage notes
309 sub minimalUsageNotes {
310
311 print "Usage: NanoB2BNER.pl --dir DIRECTORYNAME --features FEATURESET [OPTIONS]\n";
312 &askHelp();
313 exit;
314 }
315  
316 # function to output the version number
317 sub showVersion {
318 print '$Id: NanoB2BNER.pl,v 1.00 2017/02/22 13:47:05 btmcinnes Exp $';
319 print "\nCopyright (c) 2017, Megan Charity & Bridget McInnes\n";
320 }
321  
322 # function to output "ask for help" message when user's goofed
323 sub askHelp {
324 print STDERR "Type MetaMapDataStructures.pl --help for help.\n";
325 }
326
327  
328 ######################### test code ######################
329  
330 my $nner = NanoB2B::NER->new(\%params);
331 if($process eq "file"){
332 $nner->nerByFile();
333 }elsif($process eq "method"){
334 $nner->nerByMethod();
335 }elsif($process eq "meta"){
336 $nner->metaSet();
337 }elsif($process eq "arff"){
338 $nner->arffSet();
339 }elsif($process eq "weka"){
340 $nner->wekaSet();
341 }elsif($process eq "model"){
342 $nner->modelSet();
343 }elsif($process eq "avg"){
344 $nner->avgSet();
345 }else{
346 print("***ERROR: INVALID PROCESS METHOD FOR NNER!***\n");
347 exit;
348 }