コード例 #1
0
ファイル: lt.cpp プロジェクト: iharh/prj
int
main(int argc, char *argv[])
{
/*
    const char *fstFileName = "ben/ben.automorf.bin";
    const char *inFileName  = "data/in.txt";
*/
    const char *fstFileName = argv[1];
    const char *inFileName  = argv[2];

    FSTProcessor fstp;
    fstp.setDictionaryCaseMode(true); // -w option

    LtLocale::tryToSetLocale();

    {
        std::ifstream ifs(fstFileName, std::ifstream::binary);
        fstp.load(ifs); // hFst.get()
    }

    //clb_stream_stdio ins(inFileName, "rb");
    clb_stream_wif ins(inFileName);

    try
    {
        /*
        do
        {
            wchar_t ch = ins.getWC();
            if (!ins.eof())
            {
                std::wcout << L": " << ch << std::endl;
            }
        }
        while (!ins.eof());
        */

        fstp.initAnalysis();
        if (!fstp.valid())
        {
            exit(EXIT_FAILURE);
        }

        fstp.analysis(ins.getStrStream());

        // std::wcout << "Done." << std::endl;
    }
    catch (std::exception &e)
    {
        std::wcerr << e.what();
        exit(1);
    }

    return EXIT_SUCCESS;
}
int main(int argc, char* argv[]) {
  int op;
  int option_index=0;

  double mincount=0;

  string bil_file="";
  bool use_zlib=false;
  bool debug=false;

  cerr<<"Command line: ";
  for(int i=0; i<argc; i++)
    cerr<<argv[i]<<" ";
  cerr<<"\n\n";

  cerr<<"LOCALE: "<<setlocale(LC_ALL,"")<<"\n";


  while (true) {
    static struct option long_options[] =
      {
	{"biling",       required_argument,  0, 'b'},
	{"help",            no_argument,  0, 'h'},
	{"version",         no_argument,  0, 'v'},
	{0, 0, 0, 0}
      };

    op=getopt_long(argc, argv, "b:hv",long_options, &option_index);
    if (op==-1)
      break;
      
    switch (op) {
    case 'b': 
      bil_file=optarg;
      break;
    case 'h': 
      help(argv[0]);
      exit(EXIT_SUCCESS);
      break;
    case 'v':
      cerr<<"LICENSE:\n\n"
	  <<"   Copyright (C) 2006-2007 Felipe Sánchez-Martínez\n\n"
	  <<"   This program is free software; you can redistribute it and/or\n"
	  <<"   modify it under the terms of the GNU General Public License as\n"
	  <<"   published by the Free Software Foundation; either version 2 of the\n"
	  <<"   License, or (at your option) any later version.\n"
	  <<"   This program is distributed in the hope that it will be useful, but\n"
	  <<"   WITHOUT ANY WARRANTY; without even the implied warranty of\n"
	  <<"   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n"
	  <<"   General Public License for more details.\n"
	  <<"\n"
	  <<"   You should have received a copy of the GNU General Public License\n"
	  <<"   along with this program; if not, write to the Free Software\n"
	  <<"   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA\n"
	  <<"   02111-1307, USA.\n";
      exit(EXIT_SUCCESS);
      break;    
    default:
      help(argv[0]);
      exit(EXIT_FAILURE);
      break;
    }
   }
  

  if (bil_file=="") {
    cerr<<"Error: No bilingual dictionary file was given. You need to provide it with the --biling option\n";
    help(argv[0]);
    exit(EXIT_FAILURE);
  }
  
  FILE *fbil_dic=NULL;
  fbil_dic=fopen(bil_file.c_str(), "r");
  if (!fbil_dic) {
    cerr<<"Error: Cannot open bilingual dictionary file '"<<bil_file<<"\n";
    exit(EXIT_FAILURE);
  }
  FSTProcessor fstp;
  fstp.load(fbil_dic);
  fstp.initBiltrans();
  fclose(fbil_dic);
  
 
  
  wstring translation,lex;


  wchar_t c;
  c= getwchar_unlocked();
	
  while(c!=EOF)
  {
	  if(c ==L'^')
	  {
		  processWord(lex);
		  if(lex.size() > 0 && lex[0]!=L'*')
		  {
			  translation=fstp.biltransWithoutQueue(lex, false);
			  int posStartTagsSL=lex.find(L'<');
			  int posStartTagsTL=translation.find(L'<');
			  
			  wstring slTags=lex.substr(posStartTagsSL);
			  wstring slLemma=lex.substr(0,posStartTagsSL);
			  wstring tlLemma=translation.substr(0,posStartTagsTL);
			  wstring tlTags=translation.substr(posStartTagsTL);
			  
			  std::wcout<<L'^'<<slLemma;
			  replaceAll(tlTags,L"<",L"<RES");
			  std::wcout<<tlTags;
			  std::wcout<<slTags<<L'$';
		  }
		  else
		  {
			  std::wcout<<L'^'<<lex<<L'$';
		  }
	  }
	  else
	  {
		  std::wcout<<c;
		  if(c==L'\0')
		  {
		  	  std::wcout<<L'\n';
			  std::wcout.flush();
		  }
	  }
	c= getwchar_unlocked();
  }
  
//  delete fin;

}