Logo Search packages:      
Sourcecode: apertium version File versions  Download package

LexTorWord * LexTorWord::next_word ( wistream &  is,
FSTProcessor *  fstp = NULL 
) [static]

When calling this method the set of lexical choice for each word will be extracted from the FSTProcessor object if present. Moreover the input stream (is) is supossed to be in the intermediate format used by the apertium MT system.

Definition at line 131 of file lextor_word.cc.

References extract_lexical_choices(), ignored_string, and word.

Referenced by LexTor::trainlch().

                                                      {
  LexTorWord w;
  wchar_t c, prev_c=L' ';
  bool finish=false;
  bool reading_word=false;

  while (!finish) {
    is>>c;

    if (is.fail()) {
      if (reading_word) {
      wcerr<<L"Error in LexTorWord::next_word while reading input word\n";
      wcerr<<L"Malformed input string, at '"<<c<<L"'\n";
      exit(EXIT_FAILURE);
      } else {
      if ((w.word.length()>0)||(w.ignored_string.length()>0)) {
        if(fstp!=NULL)
          w.extract_lexical_choices(fstp);
        return new LexTorWord(w);
      } else 
        return NULL;
      }
    }

    if ((c==L'^') && (prev_c!=L'\\') && (!reading_word)) {
      reading_word=true;
    } else if ((c==L'$') && (prev_c!=L'\\') && (reading_word)) {
      finish=true;
    } else {
      if (reading_word)
      w.word+=c;
      else
      w.ignored_string+=c;
    }
    prev_c=c;
  }

  if ((w.word.length()==0) && (w.ignored_string.length()==0))
    return NULL;

  if(fstp!=NULL)
    w.extract_lexical_choices(fstp);

  /*
    cerr<<"word: "<<w.word<<"\n";
    for (unsigned int i=0; i<w.lexical_choices.size(); i++) {
    cerr<<"Lex choice at "<<i<<": "<<w.lexical_choices[i]<<"\n";
    }
    cerr<<"Default: "<<w.default_choice<<"\n\n";
  */

  return new LexTorWord(w);
}


Generated by  Doxygen 1.6.0   Back to index