本文整理汇总了C++中UnitexGetOpt类的典型用法代码示例。如果您正苦于以下问题:C++ UnitexGetOpt类的具体用法?C++ UnitexGetOpt怎么用?C++ UnitexGetOpt使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了UnitexGetOpt类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: main_SpellCheck
int main_SpellCheck(int argc,char* const argv[]) {
if (argc==1) {
usage();
return SUCCESS_RETURN_CODE;
}
VersatileEncodingConfig vec=VEC_DEFAULT;
int val,index=-1;
char mode=0;
char snt[FILENAME_MAX]="";
char txt[FILENAME_MAX]="";
char output[FILENAME_MAX]="";
char output_set=0;
char output_op='A';
SpellCheckConfig config;
config.max_errors=1;
config.max_SP_INSERT=1;
config.max_SP_SUPPR=1;
config.max_SP_SWAP=1;
config.max_SP_CHANGE=1;
for (int i=0;i<N_SPSubOp;i++) {
config.score[i]=default_scores[i];
}
config.min_length1=4;
config.min_length2=6;
config.min_length3=12;
config.input_op='D';
config.keyboard=NULL;
config.allow_uppercase_initial=0;
char foo;
bool only_verify_arguments = false;
UnitexGetOpt options;
while (EOF!=(val=options.parse_long(argc,argv,optstring_SpellCheck,lopts_SpellCheck,&index))) {
switch(val) {
case 's': {
strcpy(snt,options.vars()->optarg);
mode='s';
break;
}
case 'f': {
strcpy(txt,options.vars()->optarg);
mode='f';
break;
}
case 'o': {
if (options.vars()->optarg!=NULL) {
strcpy(output,options.vars()->optarg);
}
output_set=1;
break;
}
case 'I': {
if (!strcmp(options.vars()->optarg,"D") || !strcmp(options.vars()->optarg,"M") || !strcmp(options.vars()->optarg,"U")) {
config.input_op=options.vars()->optarg[0];
} else {
error("Invalid argument %s for option --input-op: should in [DMU]\n",options.vars()->optarg);
return USAGE_ERROR_CODE;
}
break;
}
case 'O': {
if (!strcmp(options.vars()->optarg,"O") || !strcmp(options.vars()->optarg,"A")) {
output_op=options.vars()->optarg[0];
} else {
error("Invalid argument %s for option --output-op: should in [OA]\n",options.vars()->optarg);
return USAGE_ERROR_CODE;
}
break;
}
case 1: {
config.keyboard=get_Keyboard(options.vars()->optarg);
if (config.keyboard==NULL) {
error("Invalid argument %s for option --keyboard:\nUse --show-keyboards to see possible values\n",options.vars()->optarg);
return USAGE_ERROR_CODE;
}
break;
}
case 2: {
print_available_keyboards(U_STDOUT);
return SUCCESS_RETURN_CODE;
}
case 10: {
if (1!=sscanf(options.vars()->optarg,"%u%c",&config.max_errors,&foo)) {
error("Invalid argument %s for --max-errors: should be an integer >=0\n",options.vars()->optarg);
return USAGE_ERROR_CODE;
}
break;
}
case 11: {
if (1!=sscanf(options.vars()->optarg,"%u%c",&config.max_SP_INSERT,&foo)) {
error("Invalid argument %s for --max-insert: should be an integer >=0\n",options.vars()->optarg);
return USAGE_ERROR_CODE;
}
break;
}
case 12: {
if (1!=sscanf(options.vars()->optarg,"%u%c",&config.max_SP_SUPPR,&foo)) {
error("Invalid argument %s for --max-suppr: should be an integer >=0\n",options.vars()->optarg);
return USAGE_ERROR_CODE;
}
//.........这里部分代码省略.........
开发者ID:UnitexGramLab,项目名称:unitex-core,代码行数:101,代码来源:SpellCheck.cpp
示例2: main_Evamb
int main_Evamb(int argc,char* const argv[]) {
if (argc==1) {
usage();
return SUCCESS_RETURN_CODE;
}
int val,index=-1;
int sentence_number=-1;
const char* outfilename=NULL;
char output_name_buffer[FILENAME_MAX]="";
VersatileEncodingConfig vec=VEC_DEFAULT;
bool only_verify_arguments = false;
UnitexGetOpt options;
while (EOF!=(val=options.parse_long(argc,argv,optstring_Evamb,lopts_Evamb,&index))) {
switch(val) {
case 's': { char c_foo;
if (1!=sscanf(options.vars()->optarg,"%d%c",&sentence_number,&c_foo) || sentence_number<=0) {
/* foo is used to check that the sentence number is not like "45gjh" */
error("Invalid sentence number: %s\n",options.vars()->optarg);
return USAGE_ERROR_CODE;
}
}
break;
case 'o': if (options.vars()->optarg[0]=='\0') {
error("You must specify a non empty output file name\n");
return USAGE_ERROR_CODE;
}
strcpy(output_name_buffer,options.vars()->optarg);
outfilename=output_name_buffer;
break;
case 'k': if (options.vars()->optarg[0]=='\0') {
error("Empty input_encoding argument\n");
return USAGE_ERROR_CODE;
}
decode_reading_encoding_parameter(&(vec.mask_encoding_compatibility_input),options.vars()->optarg);
break;
case 'q': if (options.vars()->optarg[0]=='\0') {
error("Empty output_encoding argument\n");
return USAGE_ERROR_CODE;
}
decode_writing_encoding_parameter(&(vec.encoding_output),&(vec.bom_output),options.vars()->optarg);
break;
case 'V': only_verify_arguments = true;
break;
case 'h': usage();
return SUCCESS_RETURN_CODE;
case ':': index==-1 ? error("Missing argument for option -%c\n",options.vars()->optopt) :
error("Missing argument for option --%s\n",lopts_Evamb[index].name);
return USAGE_ERROR_CODE;
case '?': index==-1 ? error("Invalid option -%c\n",options.vars()->optopt) :
error("Invalid option --%s\n",options.vars()->optarg);
return USAGE_ERROR_CODE;
}
index=-1;
}
if (options.vars()->optind!=argc-1) {
error("Invalid arguments: rerun with --help\n");
return USAGE_ERROR_CODE;
}
if (only_verify_arguments) {
// freeing all allocated memory
return SUCCESS_RETURN_CODE;
}
u_printf("Loading '%s'...\n",argv[options.vars()->optind]);
Tfst* tfst=open_text_automaton(&vec,argv[options.vars()->optind]);
if (tfst==NULL) {
error("Unable to load '%s'\n",argv[options.vars()->optind]);
return DEFAULT_ERROR_CODE;
}
if (sentence_number>tfst->N) {
error("Invalid sentence number %d: should be in [1;%d]\n",sentence_number,tfst->N);
close_text_automaton(tfst);
return DEFAULT_ERROR_CODE;
}
U_FILE* outfile = (outfilename == NULL) ? U_STDOUT : u_fopen(&vec,outfilename,U_WRITE);
if (outfile==NULL) {
error("Cannot create file %s\n",outfilename);
close_text_automaton(tfst);
return DEFAULT_ERROR_CODE;
}
if (sentence_number==-1) {
/* If we have to evaluate the ambiguity rate of the whole automaton */
double lognp_total=0.0;
double lmoy_total=0.0;
double maxlogamb=0.0;
double minlogamb=(double)INT_MAX;
/* This is the number of bad automata in the text .fst2 */
int n_bad_automata=0;
int maxambno=-1;
int minambno=-1;
for (sentence_number=1;sentence_number<=tfst->N;sentence_number++) {
load_sentence(tfst,sentence_number);
SingleGraph graph=tfst->automaton;
if (graph->number_of_states==0 || graph->states[0]->outgoing_transitions==NULL) {
n_bad_automata++;
error("Sentence %d: empty automaton\n",sentence_number);
//.........这里部分代码省略.........
开发者ID:anukat2015,项目名称:unitex-core,代码行数:101,代码来源:Evamb.cpp
示例3: main_Fst2Txt
int main_Fst2Txt(int argc,char* const argv[]) {
if (argc==1) {
usage();
return SUCCESS_RETURN_CODE;
}
struct fst2txt_parameters* p=new_fst2txt_parameters();
char in_offsets[FILENAME_MAX]="";
char out_offsets[FILENAME_MAX]="";
int val,index=-1;
bool only_verify_arguments = false;
UnitexGetOpt options;
while (EOF!=(val=options.parse_long(argc,argv,optstring_Fst2Txt,lopts_Fst2Txt,&index))) {
switch(val) {
case 't': if (options.vars()->optarg[0]=='\0') {
error("You must specify a non empty text file name\n");
free_fst2txt_parameters(p);
return USAGE_ERROR_CODE;
}
p->input_text_file=strdup(options.vars()->optarg);
if (p->input_text_file==NULL) {
alloc_error("main_Fst2Txt");
free_fst2txt_parameters(p);
return ALLOC_ERROR_CODE;
}
break;
case 'o': if (options.vars()->optarg[0]=='\0') {
error("You must specify a non empty text output file name\n");
free_fst2txt_parameters(p);
return USAGE_ERROR_CODE;
}
p->output_text_file=strdup(options.vars()->optarg);
p->output_text_file_is_temp=0;
if (p->output_text_file==NULL) {
alloc_error("main_Fst2Txt");
free_fst2txt_parameters(p);
return ALLOC_ERROR_CODE;
}
break;
case 'a': if (options.vars()->optarg[0]=='\0') {
error("You must specify a non empty alphabet file name\n");
free_fst2txt_parameters(p);
return USAGE_ERROR_CODE;
}
p->alphabet_file=strdup(options.vars()->optarg);
if (p->alphabet_file==NULL) {
alloc_error("main_Fst2Txt");
free_fst2txt_parameters(p);
return ALLOC_ERROR_CODE;
}
break;
case 'M': p->output_policy=MERGE_OUTPUTS; break;
case 'R': p->output_policy=REPLACE_OUTPUTS; break;
case 'c': p->tokenization_policy=CHAR_BY_CHAR_TOKENIZATION; break;
case 'w': p->tokenization_policy=WORD_BY_WORD_TOKENIZATION; break;
case 's': p->space_policy=START_WITH_SPACE; break;
case 'x': p->space_policy=DONT_START_WITH_SPACE; break;
case 'V': only_verify_arguments = true;
break;
case 'h': usage();
free_fst2txt_parameters(p);
return SUCCESS_RETURN_CODE;
case ':': index==-1 ? error("Missing argument for option -%c\n",options.vars()->optopt) :
error("Missing argument for option --%s\n",lopts_Fst2Txt[index].name);
free_fst2txt_parameters(p);
return USAGE_ERROR_CODE;
case 'k': if (options.vars()->optarg[0]=='\0') {
error("Empty input_encoding argument\n");
free_fst2txt_parameters(p);
return USAGE_ERROR_CODE;
}
decode_reading_encoding_parameter(&(p->vec.mask_encoding_compatibility_input),options.vars()->optarg);
break;
case 'q': if (options.vars()->optarg[0]=='\0') {
error("Empty output_encoding argument\n");
free_fst2txt_parameters(p);
return USAGE_ERROR_CODE;
}
decode_writing_encoding_parameter(&(p->vec.encoding_output),&(p->vec.bom_output),options.vars()->optarg);
break;
case '$': if (options.vars()->optarg[0]=='\0') {
error("Empty input_offsets argument\n");
free_fst2txt_parameters(p);
return USAGE_ERROR_CODE;
}
strcpy(in_offsets,options.vars()->optarg);
break;
case '@': if (options.vars()->optarg[0]=='\0') {
error("Empty output_offsets argument\n");
free_fst2txt_parameters(p);
return USAGE_ERROR_CODE;
}
strcpy(out_offsets,options.vars()->optarg);
break;
case 'l': p->convLFtoCRLF=0; break;
case 'r': p->keepCR = 1; break;
case '?': index==-1 ? error("Invalid option -%c\n",options.vars()->optopt) :
error("Invalid option --%s\n",options.vars()->optarg);
free_fst2txt_parameters(p);
//.........这里部分代码省略.........
开发者ID:anukat2015,项目名称:unitex-core,代码行数:101,代码来源:Fst2Txt.cpp
示例4: ule
InstallLogger::InstallLogger(int argc,char* const argv[]) :
ule(ule_default_init), init_done(0) {
ClearUniLoggerSpaceStruct(0);
if (argc==1) {
usage();
return;
}
Encoding encoding_output = DEFAULT_ENCODING_OUTPUT;
int bom_output = DEFAULT_BOM_OUTPUT;
int mask_encoding_compatibility_input = DEFAULT_MASK_ENCODING_COMPATIBILITY_INPUT;
int val,index=-1;
bool only_verify_arguments = false;
UnitexGetOpt options;
while (EOF!=(val=options.parse_long(argc,argv,optstring_CreateLog,lopts_CreateLog,&index))) {
switch(val) {
case 'V': only_verify_arguments = true;
break;
case 'h': usage();
return;
case 'n': ule.store_file_in_content = 0;
break;
case 'i': ule.store_file_in_content = 1;
break;
case 'o': ule.store_file_out_content = 1;
break;
case 'u': ule.store_file_out_content = 0;
break;
case 's': ule.store_list_file_in_content = 1;
break;
case 't': ule.store_list_file_in_content = 0;
break;
case 'r': ule.store_list_file_out_content = 1;
break;
case 'f': ule.store_list_file_out_content = 0;
break;
case ':': index==-1 ? error("Missing argument for option -%c\n",options.vars()->optopt) :
error("Missing argument for option --%s\n",lopts_CreateLog[index].name);
return;
case 'k': if (options.vars()->optarg[0]=='\0') {
error("Empty input_encoding argument\n");
return;
}
decode_reading_encoding_parameter(&mask_encoding_compatibility_input,options.vars()->optarg);
break;
case 'q': if (options.vars()->optarg[0]=='\0') {
error("Empty output_encoding argument\n");
return;
}
decode_writing_encoding_parameter(&encoding_output,&bom_output,options.vars()->optarg);
break;
case 'g': ClearUniLoggerSpaceStruct(1);
return;
case 'p': if (options.vars()->optarg[0]=='\0') {
error("You must specify a non empty param file\n");
return;
}
ClearUniLoggerSpaceStruct(1);
LoadParamFile(options.vars()->optarg);
return;
case 'l': if (options.vars()->optarg[0]=='\0') {
error("You must specify a non empty log filename\n");
return;
}
if (ule.szNameLog != NULL) {
free((void*)ule.szNameLog);
}
ule.szNameLog = strdup(options.vars()->optarg);
break;
case 'd': if (options.vars()->optarg[0]=='\0') {
error("You must specify a non empty directory\n");
return;
}
if (ule.szPathLog != NULL) {
free((void*)ule.szPathLog);
}
ule.szPathLog = strdup(options.vars()->optarg);
break;
case '?': index==-1 ? error("Invalid option -%c\n",options.vars()->optopt) :
error("Invalid option --%s\n",options.vars()->optarg);
return;
}
index=-1;
}
if (options.vars()->optind!=argc-1) {
}
if (only_verify_arguments) {
// freeing all allocated memory
return;
}
if (AddActivityLogger(&ule) != 0) {
init_done = 1;
} else {
ClearUniLoggerSpaceStruct(1);
}
//.........这里部分代码省略.........
开发者ID:Rajat-dhyani,项目名称:UnitexGramLab,代码行数:101,代码来源:UniLoggerAutoInstall.cpp
示例5: main_Normalize
int main_Normalize(int argc,char* const argv[]) {
if (argc==1) {
usage();
return SUCCESS_RETURN_CODE;
}
int mode=KEEP_CARRIAGE_RETURN;
int separator_normalization=1;
char rules[FILENAME_MAX]="";
char input_offsets[FILENAME_MAX]="";
char output_offsets[FILENAME_MAX]="";
VersatileEncodingConfig vec=VEC_DEFAULT;
int convLFtoCRLF=1;
int val,index=-1;
bool only_verify_arguments = false;
UnitexGetOpt options;
while (EOF!=(val=options.parse_long(argc,argv,optstring_Normalize,lopts_Normalize,&index))) {
switch(val) {
case 'l': convLFtoCRLF=0; break;
case 'n': mode=REMOVE_CARRIAGE_RETURN; break;
case 'r': if (options.vars()->optarg[0]=='\0') {
error("You must specify a non empty replacement rule file name\n");
return USAGE_ERROR_CODE;
}
strcpy(rules,options.vars()->optarg);
break;
case 1: separator_normalization=0; break;
case 'k': if (options.vars()->optarg[0]=='\0') {
error("Empty input_encoding argument\n");
return USAGE_ERROR_CODE;
}
decode_reading_encoding_parameter(&(vec.mask_encoding_compatibility_input),options.vars()->optarg);
break;
case 'q': if (options.vars()->optarg[0]=='\0') {
error("Empty output_encoding argument\n");
return USAGE_ERROR_CODE;
}
decode_writing_encoding_parameter(&(vec.encoding_output),&(vec.bom_output),options.vars()->optarg);
break;
case '$': if (options.vars()->optarg[0]=='\0') {
error("You must specify a non empty input offset file name\n");
return USAGE_ERROR_CODE;
}
strcpy(input_offsets,options.vars()->optarg);
break;
case '@': if (options.vars()->optarg[0]=='\0') {
error("You must specify a non empty output offset file name\n");
return USAGE_ERROR_CODE;
}
strcpy(output_offsets,options.vars()->optarg);
break;
case 'V': only_verify_arguments = true;
break;
case 'h': usage();
return SUCCESS_RETURN_CODE;
case ':': index==-1 ? error("Missing argument for option -%c\n",options.vars()->optopt) :
error("Missing argument for option --%s\n",lopts_Normalize[index].name);
return USAGE_ERROR_CODE;
break;
case '?': index==-1 ? error("Invalid option -%c\n",options.vars()->optopt) :
error("Invalid option --%s\n",options.vars()->optarg);
return USAGE_ERROR_CODE;
break;
}
index=-1;
}
if (options.vars()->optind!=argc-1) {
error("Invalid arguments: rerun with --help\n");
return USAGE_ERROR_CODE;
}
if (only_verify_arguments) {
// freeing all allocated memory
return SUCCESS_RETURN_CODE;
}
vector_offset* v_input_offsets=NULL;
vector_offset* v_output_offsets=NULL;
U_FILE* f_output_offsets=NULL;
if (output_offsets[0]!='\0') {
/* We deal with offsets only if we have to produce output offsets */
if (input_offsets[0]!='\0') {
v_input_offsets=load_offsets(&vec,input_offsets);
}
f_output_offsets=u_fopen(&vec, output_offsets, U_WRITE);
if (f_output_offsets==NULL) {
error("Cannot create offset file %s\n",output_offsets);
return DEFAULT_ERROR_CODE;
}
v_output_offsets=new_vector_offset();
}
char tmp_file[FILENAME_MAX];
get_extension(argv[options.vars()->optind],tmp_file);
if (!strcmp(tmp_file, ".snt")) {
/* If the file to process has already the .snt extension, we temporary rename it to
* .snt.normalizing */
strcpy(tmp_file,argv[options.vars()->optind]);
strcat(tmp_file,".normalizing");
af_rename(argv[options.vars()->optind],tmp_file);
//.........这里部分代码省略.........
开发者ID:UnitexGramLab,项目名称:unitex-core,代码行数:101,代码来源:Normalize.cpp
示例6: main_MultiFlex
int main_MultiFlex(int argc,char* const argv[]) {
if (argc==1) {
usage();
return SUCCESS_RETURN_CODE;
}
char output[FILENAME_MAX]="";
char config_dir[FILENAME_MAX]="";
char alphabet[FILENAME_MAX]="";
char pkgdir[FILENAME_MAX]="";
char* named=NULL;
int is_korean=0;
// default policy is to compile only out of date graphs
GraphRecompilationPolicy graph_recompilation_policy = ONLY_OUT_OF_DATE;
//Current language's alphabet
int error_check_status=SIMPLE_AND_COMPOUND_WORDS;
VersatileEncodingConfig vec=VEC_DEFAULT;
int val,index=-1;
bool only_verify_arguments = false;
UnitexGetOpt options;
while (EOF!=(val=options.parse_long(argc,argv,optstring_MultiFlex,lopts_MultiFlex,&index))) {
switch(val) {
case 'o': if (options.vars()->optarg[0]=='\0') {
error("You must specify a non empty DELAF file name\n");
free(named);
return USAGE_ERROR_CODE;
}
strcpy(output,options.vars()->optarg);
break;
case 'a': if (options.vars()->optarg[0]=='\0') {
error("You must specify a non empty alphabet file name\n");
free(named);
return USAGE_ERROR_CODE;
}
strcpy(alphabet,options.vars()->optarg);
break;
case 'd': strcpy(config_dir,options.vars()->optarg); break;
case 'K': is_korean=1;
break;
case 's': error_check_status=ONLY_SIMPLE_WORDS; break;
case 'c': error_check_status=ONLY_COMPOUND_WORDS; break;
case 'f': graph_recompilation_policy = ALWAYS_RECOMPILE; break;
case 'n': graph_recompilation_policy = NEVER_RECOMPILE; break;
case 't': graph_recompilation_policy = ONLY_OUT_OF_DATE; break;
case 'k': if (options.vars()->optarg[0]=='\0') {
error("Empty input_encoding argument\n");
free(named);
return USAGE_ERROR_CODE;
}
decode_reading_encoding_parameter(&(vec.mask_encoding_compatibility_input),options.vars()->optarg);
break;
case 'q': if (options.vars()->optarg[0]=='\0') {
error("Empty output_encoding argument\n");
free(named);
return USAGE_ERROR_CODE;
}
decode_writing_encoding_parameter(&(vec.encoding_output),&(vec.bom_output),options.vars()->optarg);
break;
case 'p': if (options.vars()->optarg[0]=='\0') {
error("You must specify a non empty package directory name\n");
free(named);
return USAGE_ERROR_CODE;
}
strcpy(pkgdir,options.vars()->optarg);
break;
case 'r': if (named==NULL) {
named=strdup(options.vars()->optarg);
if (named==NULL) {
alloc_error("main_Grf2Fst2");
return ALLOC_ERROR_CODE;
}
} else {
char* more_names = (char*)realloc((void*)named,strlen(named)+strlen(options.vars()->optarg)+2);
if (more_names) {
named = more_names;
} else {
alloc_error("main_MultiFlex");
free(named);
return ALLOC_ERROR_CODE;
}
strcat(named,";");
strcat(named,options.vars()->optarg);
}
break;
case 'V': only_verify_arguments = true;
break;
case 'h': usage();
free(named);
return SUCCESS_RETURN_CODE;
case ':': index==-1 ? error("Missing argument for option -%c\n",options.vars()->optopt) :
error("Missing argument for option --%s\n",lopts_MultiFlex[index].name);
free(named);
return USAGE_ERROR_CODE;
case '?': index==-1 ? error("Invalid option -%c\n",options.vars()->optopt) :
error("Invalid option --%s\n",options.vars()->optarg);
free(named);
return USAGE_ERROR_CODE;
}
index=-1;
}
//.........这里部分代码省略.........
开发者ID:UnitexGramLab,项目名称:unitex-core,代码行数:101,代码来源:MultiFlex.cpp
示例7: main_PolyLex
int main_PolyLex(int argc,char* const argv[]) {
if (argc==1) {
usage();
return SUCCESS_RETURN_CODE;
}
int language=-1;
char alphabet[FILENAME_MAX]="";
char name_bin[FILENAME_MAX]="";
char output[FILENAME_MAX]="";
char info[FILENAME_MAX]="";
VersatileEncodingConfig vec=VEC_DEFAULT;
int val,index=-1;
bool only_verify_arguments = false;
UnitexGetOpt options;
while (EOF!=(val=options.parse_long(argc,argv,optstring_PolyLex,lopts_PolyLex,&index))) {
switch(val) {
case 'D': language=DUTCH; break;
case 'G': language=GERMAN; break;
case 'N': language=NORWEGIAN; break;
case 'R': language=RUSSIAN; break;
case 'a': if (options.vars()->optarg[0]=='\0') {
error("You must specify a non empty alphabet file name\n");
return USAGE_ERROR_CODE;
}
strcpy(alphabet,options.vars()->optarg);
break;
case 'd': if (options.vars()->optarg[0]=='\0') {
error("You must specify a non empty dictionary file name\n");
return USAGE_ERROR_CODE;
}
strcpy(name_bin,options.vars()->optarg);
break;
case 'o': if (options.vars()->optarg[0]=='\0') {
error("You must specify a non empty output file name\n");
return USAGE_ERROR_CODE;
}
strcpy(output,options.vars()->optarg);
break;
case 'i': if (options.vars()->optarg[0]=='\0') {
error("You must specify a non empty information file name\n");
return USAGE_ERROR_CODE;
}
strcpy(info,options.vars()->optarg);
break;
case 'k': if (options.vars()->optarg[0]=='\0') {
error("Empty input_encoding argument\n");
return USAGE_ERROR_CODE;
}
decode_reading_encoding_parameter(&(vec.mask_encoding_compatibility_input),options.vars()->optarg);
break;
case 'q': if (options.vars()->optarg[0]=='\0') {
error("Empty output_encoding argument\n");
return USAGE_ERROR_CODE;
}
decode_writing_encoding_parameter(&(vec.encoding_output),&(vec.bom_output),options.vars()->optarg);
break;
case 'V': only_verify_arguments = true;
break;
case 'h': usage();
return SUCCESS_RETURN_CODE;
case ':': index==-1 ? error("Missing argument for option -%c\n",options.vars()->optopt) :
error("Missing argument for option --%s\n",lopts_PolyLex[index].name);
return USAGE_ERROR_CODE;
case '?': index==-1 ? error("Invalid option -%c\n",options.vars()->optopt) :
error("Invalid option --%s\n",options.vars()->optarg);
return USAGE_ERROR_CODE;
}
index=-1;
}
if (options.vars()->optind!=argc-1) {
error("Invalid arguments: rerun with --help\n");
return USAGE_ERROR_CODE;
}
if (name_bin[0]=='\0') {
error("You must specify the .bin dictionary to use\n");
return USAGE_ERROR_CODE;
}
if (output[0]=='\0') {
error("You must specify the output dictionary file name\n");
return USAGE_ERROR_CODE;
}
if (language==-1) {
error("You must specify the language\n");
return USAGE_ERROR_CODE;
}
if (only_verify_arguments) {
// freeing all allocated memory
return SUCCESS_RETURN_CODE;
}
Alphabet* alph=NULL;
if (alphabet[0]!='\0') {
u_printf("Loading alphabet...\n");
alph=load_alphabet(&vec,alphabet);
//.........这里部分代码省略.........
开发者ID:UnitexGramLab,项目名称:unitex-core,代码行数:101,代码来源:PolyLex.cpp
示例8: main_PackFile
int main_PackFile(int argc,char* const argv[]) {
if (argc==1) {
usage();
return SUCCESS_RETURN_CODE;
}
char junk_prefix[FILENAME_MAX+0x20]="";
char include_filename[FILENAME_MAX+0x20]="";
char global_comment[FILENAME_MAX+0x20]="";
Encoding encoding_output = DEFAULT_ENCODING_OUTPUT;
int bom_output = DEFAULT_BOM_OUTPUT;
int mask_encoding_compatibility_input = DEFAULT_MASK_ENCODING_COMPATIBILITY_INPUT;
int val,index=-1;
int quiet=0;
int add_one_file_only=1;
int append=0;
bool only_verify_arguments = false;
UnitexGetOpt options;
while (EOF!=(val=options.parse_long(argc,argv,optstring_PackFile,lopts_PackFile,&index))) {
switch(val) {
case 'm': quiet=1; break;
case 'p': add_one_file_only=0; break;
case 'a': append=1; break;
case 'i': if (options.vars()->optarg[0]=='\0') {
error("You must specify a non empty include file name\n");
return USAGE_ERROR_CODE;
}
strcpy(include_filename,options.vars()->optarg);
break;
case 'j': if (options.vars()->optarg[0]=='\0') {
error("You must specify a non empty junk prefix file name\n");
return USAGE_ERROR_CODE;
}
strcpy(junk_prefix,options.vars()->optarg);
break;
case 'g': if (options.vars()->optarg[0]=='\0') {
error("You must specify a non empty global comment\n");
return USAGE_ERROR_CODE;
}
strcpy(global_comment,options.vars()->optarg);
break;
case 'k': if (options.vars()->optarg[0]=='\0') {
error("Empty input_encoding argument\n");
return USAGE_ERROR_CODE;
}
decode_reading_encoding_parameter(&mask_encoding_compatibility_input,options.vars()->optarg);
break;
case 'q': if (options.vars()->optarg[0]=='\0') {
error("Empty output_encoding argument\n");
return USAGE_ERROR_CODE;
}
decode_writing_encoding_parameter(&encoding_output,&bom_output,options.vars()->optarg);
break;
case 'V': only_verify_arguments = true;
break;
case 'h': usage();
return SUCCESS_RETURN_CODE;
case ':': index==-1 ? error("Missing argument for option -%c\n",options.vars()->optopt) :
error("Missing argument for option --%s\n",lopts_PackFile[index].name);
return USAGE_ERROR_CODE;
case '?': index==-1 ? error("Invalid option -%c\n",options.vars()->optopt) :
error("Invalid option --%s\n",options.vars()->optarg);
return USAGE_ERROR_CODE;
}
index=-1;
}
if (options.vars()->optind!=argc-1) {
error("Invalid arguments: rerun with --help\n");
return USAGE_ERROR_CODE;
}
const char* ulpFile=argv[options.vars()->optind];
if (ulpFile == NULL) {
error("Invalid arguments: rerun with --help\n");
return USAGE_ERROR_CODE;
}
if ((*ulpFile)=='\0') {
error("Invalid arguments: rerun with --help\n");
return USAGE_ERROR_CODE;
}
if (only_verify_arguments) {
// freeing all allocated memory
return SUCCESS_RETURN_CODE;
}
int retValue = buildPackFile(ulpFile,append,
global_comment,
include_filename,
add_one_file_only,
junk_prefix,
quiet);
if (retValue == 0) {
error("Error creating %s\n", ulpFile);
return DEFAULT_ERROR_CODE;
//.........这里部分代码省略.........
开发者ID:Rajat-dhyani,项目名称:UnitexGramLab,代码行数:101,代码来源:PackFile.cpp
示例9: main_KeyWords
/**
* The same than main, but no call to setBufferMode.
*/
int main_KeyWords(int argc,char* const argv[]) {
if (argc==1) {
usage();
return SUCCESS_RETURN_CODE;
}
VersatileEncodingConfig vec=VEC_DEFAULT;
char tokens[FILENAME_MAX];
char output[FILENAME_MAX]="";
char alph[FILENAME_MAX]="";
char cdic[FILENAME_MAX]="";
unichar* code=u_strdup("XXX");
int val,index=-1;
bool only_verify_arguments = false;
UnitexGetOpt options;
while (EOF!=(val=options.parse_long(argc,argv,optstring_KeyWords,lopts_KeyWords,&index))) {
switch(val) {
case 'o': if (options.vars()->optarg[0]=='\0') {
error("You must specify a non empty output\n");
free(code);
return USAGE_ERROR_CODE;
}
strcpy(output,options.vars()->optarg);
break;
case 'a': if (options.vars()->optarg[0]=='\0') {
error("You must specify a non empty alphabet file name\n");
free(code);
return USAGE_ERROR_CODE;
}
strcpy(alph,options.vars()->optarg);
break;
case 'f': if (options.vars()->optarg[0]=='\0') {
error("You must specify a non empty forbidden code\n");
free(code);
return USAGE_ERROR_CODE;
}
free(code);
code=u_strdup(options.vars()->optarg);
break;
case 'c': if (options.vars()->optarg[0]=='\0') {
error("You must specify a non empty file name\n");
free(code);
return USAGE_ERROR_CODE;
}
strcpy(cdic,options.vars()->optarg);
break;
case 'V': only_verify_arguments = true;
break;
case 'h': usage();
free(code);
return SUCCESS_RETURN_CODE;
case 'k': if (options.vars()->optarg[0]=='\0') {
error("Empty input_encoding argument\n");
free(code);
return USAGE_ERROR_CODE;
}
decode_reading_encoding_parameter(&(vec.mask_encoding_compatibility_input),options.vars()->optarg);
break;
case 'q': if (options.vars()->optarg[0]=='\0') {
error("Empty output_encoding argument\n");
free(code);
return USAGE_ERROR_CODE;
}
decode_writing_encoding_parameter(&(vec.encoding_output),&(vec.bom_output),options.vars()->optarg);
break;
case ':': index==-1 ? error("Missing argument for option -%c\n",options.vars()->optopt) :
error("Missing argument for option --%s\n",lopts_KeyWords[index].name);
free(code);
return USAGE_ERROR_CODE;
break;
case '?': index==-1 ? error("Invalid option -%c\n",options.vars()->optopt) :
error("Invalid option --%s\n",options.vars()->optarg);
free(code);
return USAGE_ERROR_CODE;
break;
}
index=-1;
}
if (options.vars()->optind==argc || options.vars()->optind==argc-1) {
error("Invalid arguments: rerun with --help\n");
free(code);
return USAGE_ERROR_CODE;
}
if (only_verify_arguments) {
// freeing all allocated memory
free(code);
return SUCCESS_RETURN_CODE;
}
Alphabet* alphabet=NULL;
if (alph[0]!='\0') {
alphabet=load_alphabet(&vec,alph);
if (alphabet==NULL) {
//.........这里部分代码省略.........
开发者ID:Rajat-dhyani,项目名称:UnitexGramLab,代码行数:101,代码来源:KeyWords.cpp
示例10: main_PersistResource
int main_PersistResource(int argc,char* const argv[]) {
if (argc==1) {
usage();
return SUCCESS_RETURN_CODE;
}
const char *resource_file = NULL;
int res_graph=0;
int res_alphabet=0;
int res_dico=0;
int unpersist=0;
int verbose=0;
VersatileEncodingConfig vec = VEC_DEFAULT;
int val,index=-1;
bool only_verify_arguments = false;
const char*output_file = NULL;
const char*resource_type = NULL;
UnitexGetOpt options;
while (EOF!=(val=options.parse_long(argc,argv,optstring_PersistResource,lopts_PersistResource,&index))) {
switch(val) {
case 'a': res_alphabet = 1; resource_type = "alphabet"; break;
case 'g': res_graph = 1; resource_type = "graph"; break;
case 'd': res_dico = 1; resource_type = "dictionary"; break;
case 'u': unpersist = 1; break;
case 'v': verbose = 1; break;
case 'o': if (options.vars()->optarg[0]=='\0') {
error("Empty output argument\n");
return USAGE_ERROR_CODE;
}
output_file = options.vars()->optarg; // FIXME(gvollant)
break;
case 'V': only_verify_arguments = true;
break;
case 'h': usage();
return SUCCESS_RETURN_CODE;
case ':': index==-1 ? error("Missing argument for option -%c\n",options.vars()->optopt):
error("Missing argument for option --%s\n",lopts_PersistResource[index].name);
return USAGE_ERROR_CODE;
case '?': index==-1 ? error("Invalid option -%c\n",options.vars()->optopt) :
error("Invalid option --%s\n",options.vars()->optarg);
return USAGE_ERROR_CODE;
case 'k':
case 'q': /* ignore -k and -q parameter instead to raise an error */
break;
}
index=-1;
}
if ((res_graph+res_alphabet+res_dico) != 1) {
error("Invalid arguments: rerun with --help\n");
return USAGE_ERROR_CODE;
}
if ((output_file!=NULL) && (unpersist!=0)) {
error("Invalid arguments: rerun with --help\n");
return USAGE_ERROR_CODE;
}
if (options.vars()->optind!=argc-1) {
error("Invalid arguments: rerun with --help\n");
return USAGE_ERROR_CODE;
}
if (only_verify_arguments) {
// freeing all allocated memory
return SUCCESS_RETURN_CODE;
}
resource_file = argv[options.vars()->optind];
size_t size_buf_persisted_filename = strlen(resource_file) + 0x200;
char* buf_persisted_filename = (char*)malloc(size_buf_persisted_filename +1);
if (buf_persisted_filename == NULL) {
alloc_error("PersistResource's main");
return ALLOC_ERROR_CODE;
}
*buf_persisted_filename='\0';
if (unpersist == 0) {
int result = 0;
if (res_alphabet)
result = standard_load_persistence_alphabet(resource_file, buf_persisted_filename, size_buf_persisted_filename);
if (res_graph)
result = standard_load_persistence_fst2(resource_file, buf_persisted_filename, size_buf_persisted_filename);
if (res_dico)
result = standard_load_persistence_dictionary(resource_file, buf_persisted_filename, size_buf_persisted_filename);
if (result && verbose)
u_printf("Success on persist %s resource %s to persisted name %s\n", resource_type, resource_file, buf_persisted_filename);
if (!result)
error("The %s resource %s cannnot be persisted\n", resource_type, resource_file);
if (result && (output_file != NULL)) {
U_FILE* text = u_fopen(&vec, output_file, U_WRITE);
if (text == NULL) {
error("Cannot create text file %s\n", output_file);
free(buf_persisted_filename);
return DEFAULT_ERROR_CODE;
}
u_fprintf(text, "%s", buf_persisted_filename);
u_fclose(text);
//.........这里部分代码省略.........
开发者ID:Rajat-dhyani,项目名称:UnitexGramLab,代码行数:101,代码来源:PersistResource.cpp
示例11: main_XMLizer
int main_XMLizer(int argc,char* const argv[]) {
if (argc==1) {
usage();
return SUCCESS_RETURN_CODE;
}
int output_style=TEI;
char output[FILENAME_MAX]="";
char alphabet[FILENAME_MAX]="";
char normalization[FILENAME_MAX]="";
char segmentation[FILENAME_MAX]="";
VersatileEncodingConfig vec=VEC_DEFAULT;
int convLFtoCRLF=1;
int val,index=-1;
bool only_verify_arguments = false;
UnitexGetOpt options;
while (EOF!=(val=options.parse_long(argc,argv,optstring_XMLizer,lopts_XMLizer,&index))) {
switch(val) {
case 'x': output_style=XML; break;
case 't': output_style=TEI; break;
case 'n': if (options.vars()->optarg[0]=='\0') {
error("You must specify a non empty normalization grammar name\n");
return USAGE_ERROR_CODE;
}
strcpy(normalization,options.vars()->optarg);
break;
case 'o': if (options.vars()->optarg[0]=='\0') {
error("You must specify a non empty output file name\n");
return USAGE_ERROR_CODE;
}
strcpy(output,options.vars()->optarg);
break;
case 'a': if (options.vars()->optarg[0]=='\0') {
error("You must specify a non empty alphabet file name\n");
return USAGE_ERROR_CODE;
}
strcpy(alphabet,options.vars()->optarg);
break;
case 's': if (options.vars()->optarg[0]=='\0') {
error("You must specify a non empty segmentation grammar name\n");
return USAGE_ERROR_CODE;
}
strcpy(segmentation,options.vars()->optarg);
break;
case 'V': only_verify_arguments = true;
break;
case 'h': usage();
return SUCCESS_RETURN_CODE;
case ':': index==-1 ? error("Missing argument for option -%c\n",options.vars()->optopt) :
error("Missing argument for option --%s\n",lopts_XMLizer[index].name);
return USAGE_ERROR_CODE;
case 'k': if (options.vars()->optarg[0]=='\0') {
error("Empty input_encoding argument\n");
return USAGE_ERROR_CODE;
}
decode_reading_encoding_parameter(&(vec.mask_encoding_compatibility_input),options.vars()->optarg);
break;
case 'q': if (options.vars()->optarg[0]=='\0') {
error("Empty output_encoding argument\n");
return USAGE_ERROR_CODE;
}
decode_writing_encoding_parameter(&(vec.encoding_output),&(vec.bom_output),options.vars()->optarg);
break;
case '?': index==-1 ? error("Invalid option -%c\n",options.vars()->optopt) :
error("Invalid option --%s\n",options.vars()->optarg);
return USAGE_ERROR_CODE;
}
index=-1;
}
if (options.vars()->optind!=argc-1) {
error("Invalid arguments: rerun with --help\n");
return USAGE_ERROR_CODE;
}
if (segmentation[0]=='\0') {
error("You must specify the segmentation grammar to use\n");
return USAGE_ERROR_CODE;
}
if (only_verify_arguments) {
// freeing all allocated memory
return SUCCESS_RETURN_CODE;
}
char input[FILENAME_MAX];
strcpy(input,argv[options.vars()->optind]);
char snt[FILENAME_MAX];
remove_extension(input,snt);
strcat(snt,"_tmp.snt");
char tmp[FILENAME_MAX];
remove_extension(input,tmp);
strcat(tmp,".tmp");
normalize(input,snt,&vec,KEEP_CARRIAGE_RETURN,convLFtoCRLF,normalization,NULL,1);
struct fst2txt_parameters* p=new_fst2txt_parameters();
p->vec=vec;
p->input_text_file=strdup(snt);
if (p->input_text_file ==NULL) {
alloc_error("main_XMLizer");
//.........这里部分代码省略.........
开发者ID:Rajat-dhyani,项目名称:UnitexGramLab,代码行数:101,代码来源:XMLizer.cpp
示例12: main_TEI2Txt
int main_TEI2Txt(int argc,char* const argv[]) {
if (argc==1) {
usage();
return SUCCESS_RETURN_CODE;
}
char output[FILENAME_MAX]="";
VersatileEncodingConfig vec=VEC_DEFAULT;
int val,index=-1;
bool only_verify_arguments = false;
UnitexGetOpt options;
while (EOF!=(val=options.parse_long(argc,argv,optstring_TEI2Txt,lopts_TEI2Txt,&index))) {
switch(val) {
case 'o': if (options.vars()->optarg[0]=='\0') {
error("You must specify a non empty output file name\n");
return USAGE_ERROR_CODE;
}
strcpy(output,options.vars()->optarg);
break;
case 'k': if (options.vars()->optarg[0]=='\0') {
error("Empty input_encoding argument\n");
return USAGE_ERROR_CODE;
}
decode_reading_encoding_parameter(&(vec.mask_encoding_compatibility_input),options.vars()->optarg);
break;
case 'q': if (options.vars()->optarg[0]=='\0') {
error("Empty output_encoding argument\n");
return USAGE_ERROR_CODE;
}
decode_writing_encoding_parameter(&(vec.encoding_output),&(vec.bom_output),options.vars()->optarg);
break;
case 'V': only_verify_arguments = true;
break;
case 'h': usage();
return SUCCESS_RETURN_CODE;
case ':': index==-1 ? error("Missing argument for option -%c\n",options.vars()->optopt) :
error("Missing argument for option --%s\n",lopts_TEI2Txt[index].name);
return USAGE_ERROR_CODE;
case '?': index==-1 ? error("Invalid option -%c\n",options.vars()->optopt) :
error("Invalid option --%s\n",options.vars()->optarg);
return USAGE_ERROR_CODE;
}
index=-1;
}
if (options.vars()->optind!=argc-1) {
error("Invalid arguments: rerun with --help\n");
return USAGE_ERROR_CODE;
}
if (only_verify_arguments) {
// freeing all allocated memory
return SUCCESS_RETURN_CODE;
}
if(output[0]=='\0') {
remove_extension(argv[options.vars()->optind],output);
strcat(output,".txt");
}
int return_value = tei2txt(argv[options.vars()->optind],output,&vec);
return return_value;
}
开发者ID:UnitexGramLab,项目名称:unitex-core,代码行数:64,代码来源:TEI2Txt.cpp
|
请发表评论