1 // Implementation of command-line argument processing functions
2 // Copyright © 2009 The University of Chicago
3 #include "CommandLine.h"
8 /// Requires: variables referred to by arguments pre-initialized with
9 /// their default values.
10 int processCommandLineArgs(int argc
, char** argv
,
11 QString
& corpus
, int& count
, QString
& logFile
,
12 QString
& goldStdFile
, QString
& outputDir
,
13 bool& mini
, bool& prefix
, bool& suffix
, bool& verbose
,
21 if( argv
[0] == QString("-h") ||
22 argv
[0] == QString("--help") ||
23 argv
[1] == QString("-h") ||
24 argv
[1] == QString("--help") )
31 for( i
=0; i
<argc
-1; i
++ )
33 arg
= QString( argv
[i
] );
35 if( arg
== "--help" || arg
== "-h" )
41 if( arg
.find("-") == 0 )
43 if( arg
.find("c") > 0 )
45 if( arg
.length() > 2 )
47 error
= "Illegal option combination : \'" + arg
+ "\'\n\n";
53 temp
= QString( argv
[i
+1] );
54 // Check each digit is number
55 for( j
=0; j
< static_cast <int> (temp
.length()); j
++ )
57 if( !temp
[j
].isNumber() )
59 error
= "Illegal string following \'-c\' option : \'temp\'\n\n";
67 error
= "Illegal use of \'-c\' option.\n\n";
71 else if( arg
.find("g") > 0 )
73 if( arg
.length() > 2 )
75 error
= "Illegal option combination : \'" + arg
+ "\'\n\n";
81 goldStdFile
= QString( argv
[i
+1] );
85 error
= "Illegal use of \'-g\' option.\n\n";
89 else if( arg
.find("l") > 0 )
91 if( arg
.length() > 2 )
93 error
= "Illegal option combination : \'" + arg
+ "\'\n\n";
99 logFile
= QString( argv
[i
+1] );
103 error
= "Illegal use of \'-l\' option.\n\n";
107 else if( arg
.find("o") > 0 )
109 if( arg
.length() > 2 )
111 error
= "Illegal option combination : \'" + arg
+ "\'\n\n";
117 outputDir
= QString( argv
[i
+1] );
121 error
= "Illegal use of \'-o\' option.\n\n";
127 for( j
= 1; j
< static_cast <int> ( arg
.length() ); j
++ )
129 if( QString("fmpsv").find( arg
[j
] ) < 0 )
131 error
= "Illegal option : \'" + QString( arg
[j
] ) + "\'\n\n";
136 if( arg
.find("m") > 0 ) mini
= true;
137 if( arg
.find("p") > 0 ) prefix
= true;
138 if( arg
.find("s") > 0 ) suffix
= true;
139 if( arg
.find("v") > 0 ) verbose
= true;
144 corpus
= QString( argv
[argc
-1] );
146 if( corpus
== "--help" || corpus
== "-h" )
159 printf( "Usage: linguistica [options] corpus\n" );
160 printf( "Options:\n" );
161 printf( " -c X\t\tX is an integer. Read X number of words from the corpus for the analysis. If omitted, default is 10000.\n" );
162 printf( " -g gold-std\tCompare results to this gold standard. File must be XML format created by Alchemist and readable.\n" );
163 printf( " -h\t\tHelp: void use of all other options and arguments and print option informations.\n" );
164 printf( " -l log-file\tStore log information to this file name. File must be writeable.\n" );
165 printf( " -m\t\tFind more than one level of morphology using mini-lexica.\n" );
166 printf( " -o output-dir\tOutput to this directory (default is same directory as corpus). Directory must be writeable.\n" );
167 printf( " -p\t\tFind prefixes.\n" );
168 printf( " -s\t\tFind suffixes.\n" );
169 printf( " -v\t\tVerbose: print the log to the screen.\n\n" );
171 printf( "Example:\n\n " );
173 printf( " linguistica -spm -l myLog.txt -c 50000 BrownCorpus.txt\n\n" );
175 printf( "Using the first 50,000 distinct words of the file \'BrownCorpus.txt\',\n" );
176 printf( "find more than one level of suffixes and prefixes using mini-lexica. Keep\n" );
177 printf( "a log of all actions in \'myLog.txt.\'\n\n" );