예제 #1
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;
}
예제 #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;
}
예제 #3
0
void ViolationHandler::LoadTxt( lem::Iridium::Macro_Parser & txtfile )
{
 if( txtfile.probe( B_OSPAREN ) )
  {
   txtfile.read_it( B_SUB );
   violation_score = -txtfile.read_int();
   txtfile.probe( B_CSPAREN );
  }
 else
  {
   violation_score=0;
  }

 return;
}
예제 #4
0
void LEMM_Compiler::LoadTxt( lem::Iridium::Macro_Parser & txtfile, Dictionary & dict )
{
 txtfile.read_it( B_OFIGPAREN );

 while( !txtfile.eof() )
 {
  lem::Iridium::BethToken t = txtfile.read();
  if( t.eqi( L"suffix" ) )
   {
    int id = txtfile.read_int();
    lem::UCString suffix = txtfile.read();
    if( suffix[0]==L'"' && suffix.back()==L'"' )
     suffix.strip_quotes();

    suffices.push_back( std::make_pair(id,suffix) );
   }
  else if( t.eqi( L"word" ) )
   {
    int id = txtfile.read_int();
    lem::UCString word = txtfile.read();
    if( word[0]==L'"' && word.back()==L'"' )
     word.strip_quotes();

    words.push_back( std::make_pair(id,word) );
   }
  else if( t.eqi(L"ngram2") )
   {
    lem::MCollect<int> terms;
    LoadNGram(txtfile,dict,terms,2);
    LEMM_Ngram2 n2;
    n2.tags.first = terms[0];
    n2.tags.second = terms[1];
    n2.freq = terms[2];
    ngram2.push_back(n2);
   }
  else if( t.eqi(L"ngram2_1") )
   {
    lem::MCollect<int> terms;
    LoadNGram(txtfile,dict,terms,2);
    LEMM_Ngram2 n2;
    n2.tags.first = terms[0];
    n2.tags.second = terms[1];
    n2.freq = terms[2];
    ngram2_1.push_back(n2);
   }
  else if( t.eqi(L"ngram3") )
   {
    lem::MCollect<int> terms;
    LoadNGram(txtfile,dict,terms,3);
    LEMM_Ngram3 n3;
    n3.tags.first = terms[0];
    n3.tags.second = terms[1];
    n3.tags.third = terms[2];
    n3.freq = terms[3];
    ngram3.push_back(n3);
   }
  else if( t.eqi(L"ngram3_1") )
   {
    lem::MCollect<int> terms;
    LoadNGram(txtfile,dict,terms,3);
    LEMM_Ngram3 n3;
    n3.tags.first = terms[0];
    n3.tags.second = terms[1];
    n3.tags.third = terms[2];
    n3.freq = terms[3];
    ngram3_1.push_back(n3);
   }
  else if( t.eqi(L"ngram3_2") )
   {
    lem::MCollect<int> terms;
    LoadNGram(txtfile,dict,terms,3);
    LEMM_Ngram3 n3;
    n3.tags.first = terms[0];
    n3.tags.second = terms[1];
    n3.tags.third = terms[2];
    n3.freq = terms[3];
    ngram3_2.push_back(n3);
   }
  else if( t.eqi(L"ngram4") )
   {
    lem::MCollect<int> terms;
    LoadNGram(txtfile,dict,terms,4);
    LEMM_Ngram4 n4;
    n4.tags.first = terms[0];
    n4.tags.second = terms[1];
    n4.tags.third = terms[2];
    n4.tags.fourth = terms[3];
    n4.freq = terms[4];
    ngram4.push_back(n4);
   }
  else if( t.eqi( L"suffix_len" ) )
   {
    suffix_len = txtfile.read_int();
   }

  else if( t.GetToken()==B_CFIGPAREN )
   break;
  else
   {
    dict.GetIO().merr().printf( "%vfDInvalid statement [%us]%vn\n", t.string().c_str() );
    lem::Iridium::Print_Error( t, txtfile );
    throw lem::E_ParserError();
   }
 }

 return;
}
예제 #5
0
void KB_Facts::LoadTxt(Solarix::Dictionary &dict, lem::Iridium::Macro_Parser &txtfile)
{
    name = txtfile.read().string();

    txtfile.read_it(B_LANGUAGE);
    txtfile.read_it(B_EQUAL);

    lem::Iridium::BethToken lang = txtfile.read();
    id_language = dict.GetSynGram().Find_Language(lang.string());
    if (id_language == UNKNOWN)
    {
        lem::Iridium::Print_Error(lang, txtfile);
        dict.GetIO().merr().printf("Unknown language name %us\n", lang.c_str());
        throw lem::E_BaseException();
    }

    txtfile.read_it(B_OFIGPAREN);

    n_ret = 0;

    while (!txtfile.eof())
    {
        if (txtfile.probe(B_CFIGPAREN))
            break;

        lem::Iridium::BethToken t = txtfile.read();
        if (t.string().eqi(L"arity"))
        {
            txtfile.read_it(B_EQUAL);
            n_arg = txtfile.read_int();
        }
        else if (t.string().eqi(L"return"))
        {
            txtfile.read_it(B_EQUAL);

            lem::Iridium::BethToken t_ret = txtfile.read();
            if (t_ret.eqi(L"boolean"))
            {
                n_ret = 1;
                ret_type = 0;
            }
            else if (t_ret.eqi(L"integer"))
            {
                n_ret = 1;
                ret_type = 1;
            }
            else
            {
                lem::Iridium::Print_Error(t_ret, txtfile);
                dict.GetIO().merr().printf("Unknown return type %us\n", t_ret.c_str());
                throw lem::E_BaseException();
            }
        }
        else if (t.string().eqi(L"violation_score"))
        {
            txtfile.read_it(B_EQUAL);

            if (txtfile.probe(B_SUB))
                violation_score = -txtfile.read_int();
            else
                violation_score = txtfile.read_int();
        }
        else if (t.string().eqi(L"violation_handler"))
        {
            txtfile.read_it(B_EQUAL);

            violation_handler = new PredicateTemplate();
            PredicateTemplateParams_KB params(n_arg);
            violation_handler->LoadTxt(dict, txtfile, params);
        }
        else if (t.string().eqi(L"generic"))
        {
            allow_generic = true;
        }
        else
        {
            lem::Iridium::Print_Error(t, txtfile);
            dict.GetIO().merr().printf("Unknown property %us\n", t.c_str());
            throw lem::E_BaseException();
        }
    }

    return;
}