Example #1
0
void SynPatternExport::LoadTxt(
                               Dictionary &dict,
                               lem::Iridium::Macro_Parser & txtfile
                              )
{
 txtfile.read_it( B_OFIGPAREN );

 while( !txtfile.eof() )
  {
   bool null_export = txtfile.probe( B_OROUNDPAREN );
   lem::Iridium::BethToken coord_name = txtfile.read();
 
   if( coord_name.GetToken()==B_CFIGPAREN )
    break;

   if( coord_name.string().eqi( L"node" ) )
    {
     txtfile.read_it( B_COLON );
     lem::Iridium::BethToken t_node_name = txtfile.read();
     lem::UCString node_name = t_node_name.string();
     node_name.to_upper();

     if( export_nodes.find(node_name)!=UNKNOWN )
      {
       dict.GetIO().merr().printf( "Wordform %us is already mentioned in export section\n", t_node_name.string().c_str() );
       lem::Iridium::Print_Error(t_node_name,txtfile);
       throw lem::E_BaseException();
      }

     export_nodes.push_back( node_name );
     null_export_nodes.push_back( null_export ? 1 : 0 );

     if( null_export )
      txtfile.read_it( B_CROUNDPAREN );

     continue;
    }

   const GramCoordAdr iglob_coord = dict.GetSynGram().FindCoord(coord_name.string());
 
   if( !iglob_coord.IsDefined() )
    {
     dict.GetIO().merr().printf( "Unknown coordinate %us\n", coord_name.c_str() );
     lem::Iridium::Print_Error(coord_name,txtfile);
     throw lem::E_BaseException();
    }
 
   if( export_coords.find( iglob_coord.GetIndex() )!=UNKNOWN )
    {
     dict.GetIO().merr().printf( "Coordinate %us is already mentioned in export section\n", coord_name.c_str() );
     lem::Iridium::Print_Error(coord_name,txtfile);
     throw lem::E_BaseException();
    }
 
   export_coords.push_back(iglob_coord.GetIndex());
   null_export_coords.push_back( null_export ? 1 : 0 );

   if( null_export )
    txtfile.read_it( B_CROUNDPAREN );
  }

 return;
}
Example #2
0
SG_calibrator::SG_calibrator(const lem::UCString & keyword, const SynGram &sg, const Sol_IO &io, Macro_Parser &txtfile)
{
    if (keyword.eqi(L"wordentry_freq"))
        freq_type = WordEntryFreq;
    else if (keyword.eqi(L"wordform_score"))
        freq_type = WordFormScore;
    else if (keyword.eqi(L"wordforms_score"))
        freq_type = WordFormsScore;

    id_class = UNKNOWN;
    freq = 0;

    word = txtfile.read().string();
    word.strip(L'"');

    // если далее идет открывающая фигурная скобка, то значит конкретизируется словоформа (или несколько
    // словоформ).

    if (txtfile.probe(B_OFIGPAREN))
    {
        while (!txtfile.eof())
        {
            if (txtfile.pick().GetToken() == B_CFIGPAREN)
            {
                txtfile.read();
                break;
            }

            // для обычных: координата:состояние
            // для бистабильных: координата
            lem::Iridium::BethToken coord_name = txtfile.read();

            if (id_class == UNKNOWN)
            {
                const int id_class0 = sg.FindClass(coord_name);
                if (id_class0 != UNKNOWN)
                {
                    id_class = id_class0;
                    continue;
                }
            }

            bool AFFIRM = true;

            if (coord_name.GetToken() == B_NEGATIVE)
            {
                // Оператор отрицания перед определением координаты!
                AFFIRM = false;
                coord_name = txtfile.read();
            }

            const GramCoordAdr iglob_coord = sg.FindCoord(coord_name.string());

            if (!iglob_coord.IsDefined())
            {
                sg.GetIO().merr().printf("Unknown coordinate %us\n", coord_name.c_str());
                lem::Iridium::Print_Error(coord_name, txtfile);
                throw lem::E_BaseException();
            }

            if (sg.coords()[iglob_coord.GetIndex()].IsBistable())
            {
                // Имя состояния не может быть указано.
                coords.push_back(GramCoordPair(iglob_coord, AFFIRM));
            }
            else
            {
                // После двоеточия должно идти имя состояния для координаты.
                txtfile.read_it(B_COLON);

                // Имя состояния.
                BethToken state_name = txtfile.read();

                // Получим индекс состояния для определенной координаты.
                const int istate = sg.coords()[iglob_coord.GetIndex()]
                    .FindState(state_name.string());
                if (istate == UNKNOWN)
                {
                    // Нет такого состояния для этого измерения.
                    lem::Iridium::Print_Error(state_name, txtfile);
                    sg.GetIO().merr().printf(
                        "State [%vfE%us%vn] is not declared for coordinate [%vfE%us%vn]\n"
                        , state_name.c_str(), coord_name.c_str()
                    );
                    throw E_ParserError();
                }

                coords.push_back(GramCoordEx(iglob_coord, istate, AFFIRM));
            }
        }
    }

    txtfile.read_it(B_EQUAL);

    if (txtfile.probe(B_SUB))
        freq = -txtfile.read_int();
    else
        freq = txtfile.read_int();
    return;
}