예제 #1
0
    int Register(const CP_Array &pairs)
    {
        if (pairs.empty())
            return 0;

        lem::UFString ints;
        for (auto pair : pairs)
        {
            ints += lem::format_str(L" %d:%d", pair.GetCoord().GetIndex(), pair.GetState());
        }

        ints += L' ';

        std::map< lem::UFString, int >::const_iterator it = ints2index.find(ints);
        if (it == ints2index.end())
        {
            const int index = CastSizeToInt(ints_list.size());
            ints_list.push_back(new UFString(ints));
            pairs_list.push_back(new CP_Array(pairs));
            ints2index.insert(std::make_pair(ints, index));
            return index;
        }
        else
        {
            return it->second;
        }
    }
예제 #2
0
 ABC_CoordPairsList()
 {
     pairs_list.push_back(new CP_Array);
     ints_list.push_back(new lem::UFString(L" "));
     ints2index.insert(std::make_pair(UFString(L" "), 0));
     return;
 }
예제 #3
0
void BasicModel::PullFeatures2( lem::MCollect<lem::CString> & b, const lem::PtrCollect<ModelTokenFeatures> & token_features, int ifocus, int offset1, int offset2 ) const
{
 int iword1 = ifocus + offset1;
 int iword2 = ifocus + offset2;

 if( iword1 >= 0 && iword1 < token_features.size() && iword2 >= 0 && iword2 < token_features.size() )
 {
  b.push_back( lem::format_str( "sfx[%d,%d]=%d,%d", offset1, offset2, token_features[iword1]->suffix_id, token_features[iword2]->suffix_id ).c_str() );

  // здесь можно вывести и другие свойства слов.
  // ... TODO
 }

 return;
}
예제 #4
0
void BasicModel::PullFeatures1(
                               lem::MCollect<lem::CString> & b,
                               const lem::PtrCollect<ModelTokenFeatures> & token_features,
                               int ifocus,
                               int offset,
                               bool rich_set,
                               bool emit_Aa_feature
                              ) const
{
 int iword = ifocus + offset;

 if( iword >= 0 && iword < token_features.size() )
 {
  const ModelTokenFeatures & f = * token_features[iword];

  if( codebook->GetMaxSuffixLen() > 0 )
   b.push_back( lem::format_str( "sfx[%d]=%d", offset, f.suffix_id ).c_str() );

  if( emit_Aa_feature && f.Aa==true && !f.IsBegin && !f.IsEnd )
   b.push_back( lem::format_str( "Aa[%d]=True", offset ).c_str() );

  // здесь можно вывести и другие свойства слова.
  if( rich_set && EMIT_POS_TAGS )
  {
   b.push_back( lem::format_str("pos[%d,N]=%s", offset, f.POS_N.c_str() ).c_str() );
   b.push_back( lem::format_str("pos[%d,A]=%s", offset, f.POS_A.c_str() ).c_str() );
   b.push_back( lem::format_str("pos[%d,V]=%s", offset, f.POS_V.c_str() ).c_str() );
   b.push_back( lem::format_str("pos[%d,IMV]=%s", offset, f.POS_IMV.c_str() ).c_str() );
   b.push_back( lem::format_str("pos[%d,I]=%s", offset, f.POS_I.c_str() ).c_str() );
   b.push_back( lem::format_str("pos[%d,Y]=%s", offset, f.POS_Y.c_str() ).c_str() );
   b.push_back( lem::format_str("pos[%d,VY]=%s", offset, f.POS_VY.c_str() ).c_str() );
   b.push_back( lem::format_str("pos[%d,PRN]=%s", offset, f.POS_PRN.c_str() ).c_str() );
   b.push_back( lem::format_str("pos[%d,PRN2]=%s", offset, f.POS_PRN2.c_str() ).c_str() );
   b.push_back( lem::format_str("pos[%d,C]=%s", offset, f.POS_C.c_str() ).c_str() );
   b.push_back( lem::format_str("pos[%d,D]=%s", offset, f.POS_D.c_str() ).c_str() );
   b.push_back( lem::format_str("pos[%d,P]=%s", offset, f.POS_P.c_str() ).c_str() );
   b.push_back( lem::format_str("pos[%d,PX]=%s", offset, f.POS_PX.c_str() ).c_str() );
   b.push_back( lem::format_str("pos[%d,PP]=%s", offset, f.POS_PP.c_str() ).c_str() );
   b.push_back( lem::format_str("pos[%d,MU]=%s", offset, f.POS_MU.c_str() ).c_str() );
  }

  if( EMIT_FORMTAGS_FOR_CONTEXT && offset!=0 )
   {
    for( int k = 0; k < f.allform_tags.size(); ++k )
    {
     b.push_back( lem::format_str("formtag[%d]=%d", offset, f.allform_tags[k] ).c_str() );
    }
   }

  if( EMIT_SEMANTIC_TAGS )
  {
   for( int k = 0; k < f.semantic_tags.size(); ++k )
   {
    b.push_back( lem::format_str("sem[%d]=%s", offset, lem::to_utf8( f.semantic_tags[k] ).c_str() ).c_str() );
   }
  }
 }

 return;
}
bool TreeMatchingExperience::GetMatchedFragmentAt( const LexerTextPos * token, lem::PtrCollect<SynPatternResult> & results, bool * matched ) const
{
 LEM_CHECKIT_Z( token!=NULL );
 FRAGMENT2ITEM::const_iterator it = fragment2item.find(token);
 if( it==fragment2item.end() )
  return false;
 else
  {
   for( lem::Container::size_type i=0; i<it->second->results.size(); ++i )
    results.push_back( it->second->results[i]->Copy1(NULL) );
  
   *matched = it->second->success;
 
   return true;
  }
}
예제 #6
0
void BasicModel::PullFeatures1(
                               lem::MCollect<lem::CString> & b,
                               const lem::PtrCollect<ModelTokenFeatures> & token_features,
                               int ifocus,
                               int offset,
                               bool rich_set,
                               bool emit_Aa_feature
                              ) const
{
 int iword = ifocus + offset;

 if( iword >= 0 && iword < token_features.size() )
 {
  const ModelTokenFeatures & f = * token_features[iword];

  b.push_back( lem::format_str( "sfx[%d]=%d", offset, f.suffix_id ).c_str() );

  if( emit_Aa_feature )
   b.push_back( lem::format_str( "Aa[%d]=%d", offset, f.Aa ).c_str() );

  // здесь можно вывести и другие свойства слова.
  if( rich_set )
  {
   b.push_back( lem::format_str("pos[%d,N]=%s", offset, f.POS_N.c_str() ).c_str() );
   b.push_back( lem::format_str("pos[%d,A]=%s", offset, f.POS_A.c_str() ).c_str() );
   b.push_back( lem::format_str("pos[%d,V]=%s", offset, f.POS_V.c_str() ).c_str() );
   b.push_back( lem::format_str("pos[%d,IMV]=%s", offset, f.POS_IMV.c_str() ).c_str() );
   b.push_back( lem::format_str("pos[%d,I]=%s", offset, f.POS_I.c_str() ).c_str() );
   b.push_back( lem::format_str("pos[%d,Y]=%s", offset, f.POS_Y.c_str() ).c_str() );
   b.push_back( lem::format_str("pos[%d,VY]=%s", offset, f.POS_VY.c_str() ).c_str() );
   b.push_back( lem::format_str("pos[%d,PRN]=%s", offset, f.POS_PRN.c_str() ).c_str() );
   b.push_back( lem::format_str("pos[%d,PRN2]=%s", offset, f.POS_PRN2.c_str() ).c_str() );
   b.push_back( lem::format_str("pos[%d,C]=%s", offset, f.POS_C.c_str() ).c_str() );
   b.push_back( lem::format_str("pos[%d,D]=%s", offset, f.POS_D.c_str() ).c_str() );
   b.push_back( lem::format_str("pos[%d,P]=%s", offset, f.POS_P.c_str() ).c_str() );
   b.push_back( lem::format_str("pos[%d,PX]=%s", offset, f.POS_PX.c_str() ).c_str() );
   b.push_back( lem::format_str("pos[%d,PP]=%s", offset, f.POS_PP.c_str() ).c_str() );
  }
 }

 return;
}
예제 #7
0
void SG_DeclensionTable::GenerateForms(
                                       const Lexem &entry_name,
                                       lem::MCollect<Lexem> & res,
                                       lem::PtrCollect<CP_Array> & form_dims, 
                                       const SynGram &sg,
                                       const SG_DeclensionAutomat &dsa 
                                      ) const
{
 res.reserve(form.size());

 for( lem::Container::size_type i=0; i<form.size(); i++ )
  {
   UCString frm( dsa.ProduceForm( entry_name, GetClass(), *form[i], sg ) );

   res.push_back( frm);
   form_dims.push_back( new CP_Array( form[i]->GetDim() ) );
  }

 return;
}
예제 #8
0
    void SaveSQL(OFormatter &out, const SQL_Production &sql_version)
    {
        const wchar_t* NPrefix = sql_version.GetNPrefix();

        int id_pair = 0;
        for (lem::Container::size_type i = 0; i < ints_list.size(); ++i)
        {
            int id_pairs = CastSizeToInt(i);

            out.printf("INSERT INTO abc_pairs( id, str_pairs )"
                " VALUES( %d, %us'%us' );\n",
                id_pairs, NPrefix, ints_list[i]->c_str());

            const CP_Array &p = *pairs_list[i];
            for (lem::Container::size_type j = 0; j < p.size(); ++j)
            {
                out.printf("INSERT INTO abc_pair( id, id_pairs, id_coord, id_state )"
                    " VALUES ( %d, %d, %d, %d );\n",
                    id_pair++, id_pairs, p[j].GetCoord().GetIndex(), p[j].GetState());
            }
        }

        return;
    }