Exemplo n.º 1
0
void LA_Recognizer::LoadTxt_Misspelling( lem::Iridium::Macro_Parser &txtfile, Dictionary &dict )
{
 txtfile.read_it(B_LANGUAGE);
 // дальше идет наименование языка, в рамках которого действует правило.
 txtfile.read_it( B_EQUAL );
 lem::Iridium::BethToken t1 = txtfile.read();
 int id_language = dict.GetSynGram().Find_Language(t1.string());
 if( id_language==UNKNOWN )
  {
   lem::Iridium::Print_Error(t1,txtfile);
   dict.GetIO().merr().printf( "Unknown language name %us\n", t1.c_str() );
   throw lem::E_BaseException();
  }

 txtfile.read_it( B_OFIGPAREN );

 txtfile.read_it( B_IF );

 Solarix::Lexem old_word = txtfile.read().string();
 old_word.strip(L'"');
 dict.GetLexAuto().TranslateLexem( old_word, true, id_language );
 
 txtfile.read_it( B_THEN );

 Solarix::Lexem new_word = txtfile.read().string();
 new_word.strip(L'"');
 dict.GetLexAuto().TranslateLexem( new_word, true, id_language );
  
 txtfile.read_it( B_CFIGPAREN );

 storage->AddMisspelling( id_language, old_word, new_word );
 return;
}
Exemplo n.º 2
0
void TreeScorerResult::LoadTxt(
                               Dictionary & dict,
                               lem::Iridium::Macro_Parser & txtfile,
                               const TreeScorerMarkers & markers
                              )
{
 // ќценка может быть отрицательной.
 if( txtfile.probe( B_SUB ) )
  {
   type=NumberScoreType;
   score = -txtfile.read_int();
  }
 else
  {
   if( lem::is_int( txtfile.pick().string() ) )
    {
     type=NumberScoreType;
     score = txtfile.read_int();
    }
   else
    {
     const lem::Iridium::BethToken & t = txtfile.read();
     id_fact = dict.GetLexAuto().GetKnowledgeBase().FindFacts( t.string() );
     if( id_fact==UNKNOWN )
      {
       type = FuncScoreType;

       Solarix::TrKnownVars vars;

       Solarix::TrTreeType tree_type;
       for( lem::Container::size_type k=0; k<markers.CountMarkers(); ++k )
       {
        vars.RegisterVar( tree_type, markers.GetMarker(k) );
        args.push_back( markers.GetMarker(k) );
       }

       txtfile.seekp(t);
       score_fun = dict.GetLexAuto().GetFunctions().Get().CompileCall( dict.GetLexAuto(), txtfile, vars );
      }
     else
      {
       LoadBoundVars( dict, txtfile, markers );
       type=NGramScoreType;
      }
    }
  }

 return;
}
Exemplo n.º 3
0
void SynPatterns::LoadTxt( Dictionary &dict, lem::Iridium::Macro_Parser & txtfile )
{
 lem::Iridium::BSourceState beg = txtfile.tellp();

 SynPatternOptions *x = new SynPatternOptions();
 x->LoadTxt( dict, txtfile );

 if( IsPatternName(x->GetName()) )
  {
   dict.GetIO().merr().printf( "Patterns group [%us] is already declared\n", x->GetName().c_str() );
   lem::Iridium::Print_Error(beg,txtfile);
   throw lem::E_BaseException();
  }

 if( dict.GetLexAuto().GetWordEntrySet().IsSetName(x->GetName()) )
  {
   dict.GetIO().merr().printf( "%vfC%us%vn is a name of word entry set, word set or collocation set\n", x->GetName().c_str() );
   lem::Iridium::Print_Error(beg,txtfile);
   throw lem::E_BaseException();
  }

 const int id = GetNextTreeID();

 options.push_back(x);
 lem::UCString uname( lem::to_upper(x->GetName() ) );
 patterns.insert( std::make_pair( uname, x ) );
 name2id.insert( std::make_pair( uname, id ) );

 return;
}
Exemplo n.º 4
0
int TreeScorerResult::Calculate( Dictionary & dict, const TreeScorerBoundVariables & bound_variables ) const
{
 if( type==0 )
  return score;
 else
  {
   lem::MCollect<const Solarix::Word_Form*> vars;
   for( lem::Container::size_type i=0; i<args.size(); ++i )
   {
    const Solarix::Word_Form * wf = bound_variables.GetVariable( args[i] );
    if( wf==NULL )
     {
      lem::MemFormatter mem;
      mem.printf( "tree_scorer: can not find bound variable %us", args[i].c_str() );
      throw lem::E_BaseException( mem.string() );
     }

    vars.push_back(wf);
   }

   KB_CheckingResult res = dict.GetLexAuto().GetKnowledgeBase().Prove( id_fact, vars );
   if( res.IsMatched() )
    return res.GetInt();
   else
    return 0;
  }
}
Exemplo n.º 5
0
void TreeScorerResult::LoadTxt( Dictionary & dict, lem::Iridium::Macro_Parser & txtfile, const TreeScorerMarkers & markers )
{
 // ќценка может быть отрицательной.
 if( txtfile.probe( B_SUB ) )
  {
   type=0;
   score = -txtfile.read_int();
  }
 else
  {
   if( lem::is_int( txtfile.pick().string() ) )
    {
     type=0;
     score = txtfile.read_int();
    }
   else
    {
     const lem::Iridium::BethToken & t = txtfile.read();
     id_fact = dict.GetLexAuto().GetKnowledgeBase().FindFacts( t.string() );
     if( id_fact==UNKNOWN )
      {
       // todo - тут могут быть другие варианты вызываемых вычислений.
       lem::Iridium::Print_Error(t,txtfile);
       dict.GetIO().merr().printf( "Unknown scoring expression starts with %us\n", t.string().c_str() );
       throw lem::E_BaseException();
      }

     txtfile.read_it( B_OROUNDPAREN );
     while( !txtfile.eof() )
     {
      if( txtfile.probe( B_CROUNDPAREN ) )
       break;

      if( !args.empty() )
       txtfile.read_it( B_COMMA );

      const lem::Iridium::BethToken & var = txtfile.read();
      lem::UCString upper_var = lem::to_upper(var.string());
      if( !markers.IsAlreadyBound(upper_var) )
       {
        lem::Iridium::Print_Error(var,txtfile);
        dict.GetIO().merr().printf( "variable %us not bound\n", var.string().c_str() );
        throw lem::E_BaseException();
       }

      args.push_back( upper_var );
     }

     type=1;
    }
  }

 return;
}
Exemplo n.º 6
0
int TreeScorerResult::Calculate(
                                Dictionary & dict,
                                const TreeScorerBoundVariables & bound_variables,
                                const ElapsedTimeConstraint & constraints,
                                TrTrace *trace_log
                               ) const
{
 if( type==NumberScoreType )
  return score;
 else if( type==NGramScoreType )
  {
   lem::MCollect<const Solarix::Word_Form*> vars;
   for( lem::Container::size_type i=0; i<args.size(); ++i )
   {
    const Solarix::Word_Form * wf = bound_variables.GetVariable( args[i] );
    if( wf==NULL )
     {
      lem::MemFormatter mem;
      mem.printf( "tree_scorer: can not find bound variable %us", args[i].c_str() );
      throw lem::E_BaseException( mem.string() );
     }

    vars.push_back(wf);
   }

   KB_CheckingResult res = dict.GetLexAuto().GetKnowledgeBase().Prove( id_fact, vars );
   if( res.IsMatched() )
    return res.GetInt();
   else
    return 0;
  }
 else if( type==FuncScoreType )
  {
   TrFunContext ctx0( (TrFunContext*)NULL );

   TrContextInvokation ctx2( &ctx0 );

   for( lem::Container::size_type i=0; i<args.size(); ++i )
   {
    const Solarix::Word_Form * wf = bound_variables.GetVariable( args[i] );
    if( wf==NULL )
     {
      lem::MemFormatter mem;
      mem.printf( "tree_scorer: can not find bound variable %us", args[i].c_str() );
      throw lem::E_BaseException( mem.string() );
     }

    lem::Ptr<TrValue> this_wordform( new TrValue( new Tree_Node(*wf), true ) );
    ctx2.AddVar( args[i], this_wordform );
   }

   lem::Ptr<TrValue> fun_res = score_fun->Run( constraints, dict.GetLexAuto(), ctx2, trace_log );

   if( fun_res->GetType().IsInt() )
    {
     int res_int = fun_res->GetInt();
     return res_int;
    }
   else
    {
     #if LEM_DEBUGGING==1
     if( trace_log!=NULL )
      trace_log->PrintStack(*lem::mout);
     #endif

     lem::UFString msg( lem::format_str( L"Score function must return int, not %s", fun_res->GetType().GetName().c_str() ) );
     throw E_BaseException(msg.c_str());
    }
  }
 else
  {
   LEM_STOPIT;
  }

 return 0;
}