Welcome to mirror list, hosted at ThFree Co, Russian Federation.

parse.cpp « src « MGIZA « alignment-enabled « experimental - github.com/moses-smt/mgiza.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: c8eb5701b3928c8d1164fda955469998f1c4694a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/*

EGYPT Toolkit for Statistical Machine Translation
Written by Yaser Al-Onaizan, Jan Curin, Michael Jahr, Kevin Knight, John Lafferty, Dan Melamed, David Purdy, Franz Och, Noah Smith, and David Yarowsky.

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, 
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 
USA.

*/

/* FJO 01/2001: completely reorganized parameter processing */

#include <strstream>
#include <string>
#include <fstream>
#include "defs.h"
#include "utility.h"
#include "Globals.h"
#include "D4Tables.h"
#include "D5Tables.h"
#include "ATables.h"
#include "Parameter.h"

extern bool ONLYALDUMPS;

void parseConfigFile (char * fname )
  // This functions reads in the configuration file to set up some run-time
  // parameters. The parameters are global variables that are defined in 
  // main.cc and used all over the place in the program
  // The format of the configuration file can be explained in the following way
  // FORMAT:
  // the character '\n' separates lines ..
  // lines that start with "//" (skipping over white spaces are considered 
  // as comments and will be ignored.
  // Any other line is considered as an attribute setting instruction and it 
  // is divided into haves (separated by a colon ":"). The first half is the
  // attribute value which consists of the concatenation of all non-white space
  // tokens before the colon. These tokens will have spaces eseparating them.
  // The attribute vlue is the first token after the colon (any thing after 
  // it will be ignored ;
  // For example :
  // if the configuration file has the following entry:
  //
  // NO.   ITERATIONS   MODEL 2 :	10
  //
  // then the attribute is "NO. ITERATIONS MODEL 2" , and the attribute value
  // is "10"  (these do not include the quotation marks).

{

  string line, word, attrib, attribval ;
  ifstream Config_File(fname);
  if(!Config_File){
    cerr << "ERROR:  Cannot open configuration file " << fname << "!\n" ;
    exit(1);
  }

  cout << "The following options are from the config file and will be overwritten by any command line options.\n";
  
  while(getline(Config_File, line)){

    istrstream buffer(line.c_str());
    word = attrib = attribval = "" ;
    buffer >> word  ;
    if (word != "//"){ // if line does not start with "//" (i.e. not a comment)
      attrib = word ;
      while((buffer >> word) && (word != ":")){
	attrib += " " + word ;
      }      
      if(!(buffer >> attribval))
	{
	  istrstream buffer2(line.c_str());
	  buffer2>>attrib;
	  buffer2>>attribval;
	}

      // This# is where (1) the configuration file is defined and
      //               (2) parsing of its attributes occurs.
      
      if(attrib == "t FILE"){
	t_Filename = attribval;
	cout << "\tt file:  " << t_Filename << '\n';
      }
      else if(attrib ==  "a FILE"){
	a_Filename = attribval;
	cout << "\ta file:  " << a_Filename << '\n';
      }
      else if(attrib == "d FILE"){
	d_Filename = attribval;
	cout << "\td file:  " << d_Filename << '\n';
      }
      else if(attrib == "n FILE"){
	n_Filename = attribval;
	cout << "\tn file:  " << n_Filename << '\n';
      }
      else if(attrib == "p0 FILE"){
	p0_Filename = attribval;
	cout << "\tp0 file:  " << p0_Filename << '\n';
      }
      else if ( line == ""){}
      else if(  !makeSetCommand(attrib,attribval,getGlobalParSet(),2) )
	cerr << "ERROR: Unrecognized attribute :" << attrib << '\n';
    }
  }
}


void parseArguments(int argc, char *argv[])
{
  int arg = 1;
    
    if(!strcmp(argv[1], "--h") || !strcmp(argv[1], "--help")){
        printHelp();
        exit(0);
    }
    if( argv[1][0]=='-' )
        arg=0;
    else
        parseConfigFile(argv[1]);
    while(++arg<argc){
        if( strlen(argv[arg])>2 && argv[arg][0]=='-' && argv[arg][1]=='-' ) {
            if( !makeSetCommand(argv[arg]+1,"1",getGlobalParSet(),2))
                cerr << "WARNING: ignoring unrecognized option:  "<< argv[arg] << '\n' ;  
        }
        else if( arg+1<argc && !makeSetCommand(argv[arg],argv[arg+1],getGlobalParSet(),2))
            cerr << "WARNING: ignoring unrecognized option:  "<< argv[arg] << '\n' ;  
        else
        {
            arg++;
        }
    }
    if( OPath.length() )
        OPath+="/";
    Prefix = (OPath + Prefix);
    LogFilename = (OPath + LogFilename);
    printGIZAPars(cout);
}