本文整理汇总了C++中lem::FString类的典型用法代码示例。如果您正苦于以下问题:C++ FString类的具体用法?C++ FString怎么用?C++ FString使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FString类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: sqlite_select_int
int lem::sqlite_select_int( struct sqlite3* hdb, const lem::FString & Select )
{
LEM_CHECKIT_Z( hdb!=NULL );
LEM_CHECKIT_Z( !Select.empty() );
int retval=-1;
sqlite3_stmt *stmt=NULL;
const char *dummy;
int res = sqlite3_prepare_v2( hdb, Select.c_str(), Select.length(), &stmt, &dummy );
if( res==SQLITE_OK )
{
res = sqlite3_step( stmt );
if( res == SQLITE_ROW )
{
try
{
retval = sqlite3_column_int(stmt,0);
}
catch(...)
{
}
}
sqlite3_finalize(stmt);
}
else
{
lem::MemFormatter msg;
msg.printf( "SQLite error: can not execute query %s, message=%us", Select.c_str(), lem::sqlite_errmsg(hdb).c_str() );
throw E_BaseException( msg.string() );
}
return retval;
}
示例2: SelectInt
int StorageConnection_SQLITE::SelectInt( const lem::FString &sql, int default_value )
{
int retval=default_value;
sqlite3_stmt *stmt=NULL;
const char *dummy;
int res = sqlite3_prepare_v2( hdb, sql.c_str(), sql.length(), &stmt, &dummy );
if( res==SQLITE_OK )
{
res = sqlite3_step( stmt );
if( res == SQLITE_ROW )
{
try
{
retval = sqlite3_column_int(stmt,0);
}
catch(...)
{
}
}
sqlite3_finalize(stmt);
}
else
{
lem::MemFormatter msg;
msg.printf( "SQLite error: can not execute query %s, message=%us", sql.c_str(), lem::sqlite_errmsg(hdb).c_str() );
throw lem::E_BaseException( msg.string() );
}
return retval;
}
示例3: rs
void NGramsDBMS::Dump3Grams(
const lem::FString &suffix,
const lem::FString &sgm,
lem::OFormatter &to
)
{
FString sql = lem::format_str(
"SELECT w1.word, w2.word, w3.word, w"
" FROM NGRAM3%s%s, NGRAM_WORDS%s%s w1, NGRAM_WORDS%s%s w2, NGRAM_WORDS%s%s w3"
" WHERE w1.id=iword1 AND w2.id=iword2 AND w3.id=iword3"
, suffix.c_str(), sgm.c_str()
, suffix.c_str(), sgm.c_str()
, suffix.c_str(), sgm.c_str()
, suffix.c_str(), sgm.c_str()
);
std::unique_ptr<LS_ResultSet> rs(Select(sql));
while (rs->Fetch())
{
UCString s1(rs->GetUCString(0));
UCString s2(rs->GetUCString(1));
UCString s3(rs->GetUCString(2));
const int w = rs->GetInt(3);
to.printf("%us %us %us [%d]\n", s1.c_str(), s2.c_str(), s3.c_str(), w);
}
return;
}
示例4: cs
void NGramsDBMS::Find1Grams(
const lem::FString &suffix,
const lem::FString &sgm,
int max_w1,
int min_freq,
std::map< UCString, std::pair<int, float> > & reslist
)
{
FString sql = lem::format_str("SELECT wrd.word, w"
" FROM NGRAM1%s%s, NGRAM_WORDS%s%s WRD"
" WHERE iword1=wrd.id ORDER BY w DESC"
, suffix.c_str(), sgm.c_str(), suffix.c_str(), sgm.c_str());
std::unique_ptr<LS_ResultSet> rs(Select(sql));
while (rs->Fetch())
{
const int f = rs->GetInt(1);
if (f >= min_freq)
{
UCString cs(rs->GetUCString(0));
const int ciw = f;
const float cw = float(f) / max_w1;
auto it = reslist.find(cs);
if (it == reslist.end())
reslist.insert(std::make_pair(cs, std::make_pair(ciw, cw)));
}
}
return;
}
示例5: sql
bool NGramsDBMS::GetStat(
int order,
const lem::FString &suffix,
const lem::FString &segment,
float &min_w,
float &max_w,
lem::int64_t &n
)
{
if (TableExists(lem::format_str("NGRAM_STATS%d%s%s", order, suffix.c_str(), segment.c_str())))
{
lem::FString sql(lem::format_str("SELECT max_w%d, count_n%d FROM NGRAM_STATS%d%s%s",
order, order, order, suffix.c_str(), segment.c_str()));
std::unique_ptr<LS_ResultSet> rs(Select(sql));
if (rs->Fetch())
{
const float _max_w = (float)rs->GetInt(0);
const float _min_w = 0.F;
const int _n = rs->GetInt(1);
max_w = max(max_w, _max_w);
min_w = min(min_w, _min_w);
n += _n;
return true;
}
}
return false;
}
示例6: switch
lem::FString NGramsStorage_SQLITE::StartBulkInsert( const lem::FString &suffix, int order )
{
switch( order )
{
case 1: return lem::format_str( "INSERT INTO NGRAM1%s( id, iword1, w ) ", suffix.c_str() );
case 2: return lem::format_str( "INSERT INTO NGRAM2%s( id, iword1, iword2, w ) ", suffix.c_str() );
case 3: return lem::format_str( "INSERT INTO NGRAM3%s( id, iword1, iword2, iword3, w ) ", suffix.c_str() );
case 4: return lem::format_str( "INSERT INTO NGRAM4%s( id, iword1, iword2, iword3, iword4, w ) ", suffix.c_str() );
case 5: return lem::format_str( "INSERT INTO NGRAM5%s( id, iword1, iword2, iword3, iword4, iword5, w ) ", suffix.c_str() );
default: LEM_STOPIT; return lem::FString();
}
}
示例7: FindWord
int NGramsDBMS::FindWord(
const lem::FString &suffix,
const lem::FString &sgm,
const lem::UCString &word
)
{
FString sql = lem::format_str("SELECT id FROM NGRAM_WORDS%s%s WHERE word='%s'"
, suffix.c_str(), sgm.c_str(), to_utf8(word.c_str()).c_str()
);
const int id = SelectInt(sql, -1);
return id;
}
示例8: ExecuteSql
void NGramsDBMS::CreateIndeces2(const lem::FString &suffix, int order)
{
for (int k = 0; k < order; ++k)
{
if (!IndexExists(format_str("ngrams_idx%d%d%s", order, 3 + k, suffix.c_str()), lem::format_str("NGRAM%d%s", order, suffix.c_str())))
{
ExecuteSql(lem::format_str("CREATE INDEX ngrams_idx%d%d%s ON NGRAM%d%s(iword%d)",
order, k + 3, suffix.c_str(), order, suffix.c_str(), k + 1));
}
}
return;
}
示例9: UpdateStatistics
void NGramsDBMS::UpdateStatistics(const lem::FString &suffix, int order)
{
ExecuteSql(lem::format_str("DELETE FROM NGRAM_STATS%d%s", order, suffix.c_str()).c_str());
std::pair<int, int> p1(0, 0);
p1 = SelectIntPair(lem::format_str("SELECT Coalesce(max(w),0), count(*) FROM NGRAM%d%s", order, suffix.c_str()).c_str());
FString sql = format_str(
"INSERT INTO NGRAM_STATS%d%s( max_w%d, count_n%d ) VALUES ( %d, %d )",
order, suffix.c_str(), order, order, p1.first, p1.second
);
ExecuteSql(sql);
return;
}
示例10: sum
lem::int64_t NGramsDBMS::SumFrequency(
int order,
const lem::FString &suffix,
const lem::FString &sgm
)
{
FString sql = lem::format_str("SELECT sum(w)"
" FROM NGRAM%d%s%s"
, order, suffix.c_str(), sgm.c_str()
);
const int f = SelectInt(sql, 0);
return f;
}
示例11: SelectIntPair
std::pair<int, int> NGramsDBMS::FindRawNGramsID(
const lem::FString &suffix,
const lem::FString &segment,
const lem::UCString &left
)
{
FString sql = lem::format_str("SELECT w, N.id"
" FROM NGRAM_WORDS%s%s wrd1, NGRAM1%s%s N"
" WHERE wrd1.word='%s'AND iword1=wrd1.id"
, suffix.c_str(), segment.c_str(), suffix.c_str(), segment.c_str()
, to_utf8(left.c_str()).c_str());
std::pair<int, int> r = SelectIntPair(sql);
return r;
}
示例12: switch
// Итератация по всем 3-граммам
void NGramsDBMS::ForEachRaw3(
Ngrams &ngrams,
const lem::FString &suffix,
const lem::FString &sgm,
NGramHandler *handler,
int sorting_type
)
{
const char *sorting = "";
switch (sorting_type)
{
case 1: sorting = "ORDER BY id"; break;
case 2: sorting = "ORDER BY w"; break;
case 3: sorting = "ORDER BY w DESC"; break;
}
FString sql = lem::format_str("SELECT NG.id, iword1, iword2, iword3, wrd1.word, wrd2.word, wrd3.word, NG.w"
" FROM NGRAM3%s%s NG, NGRAM_WORDS%s%s wrd1, NGRAM_WORDS%s%s wrd2, NGRAM_WORDS%s%s wrd3"
" WHERE wrd1.id=iword1 AND wrd2.id=iword2 AND wrd3.id=iword3"
" %s"
, suffix.c_str(), sgm.c_str()
, suffix.c_str(), sgm.c_str()
, suffix.c_str(), sgm.c_str()
, suffix.c_str(), sgm.c_str()
, sorting
);
std::unique_ptr<LS_ResultSet> rs(Select(sql));
while (rs->Fetch())
{
const int id_ngram = rs->GetInt(0);
const int id_word1 = rs->GetInt(1);
const int id_word2 = rs->GetInt(2);
const int id_word3 = rs->GetInt(3);
UCString word1(rs->GetUCString(4));
UCString word2(rs->GetUCString(5));
UCString word3(rs->GetUCString(6));
const int f = rs->GetInt(7);
const int ciw = f;
if (!handler->Do(ngrams, id_ngram, ciw, id_word1, id_word2, id_word3, word1, word2, word3))
break;
}
return;
}
示例13: sprintf
void NGramsStorage_SQLITE::CreateTable_NGrams5( const lem::FString &suffix )
{
char asql[1000];
#if LEM_DEBUGGING==1
sprintf( asql, "CREATE TABLE NGRAM5%s( "
"id integer NOT NULL,"
"iword1 integer NOT NULL,"
"iword2 integer NOT NULL,"
"iword3 integer NOT NULL,"
"iword4 integer NOT NULL,"
"iword5 integer NOT NULL,"
"w integer NOT NULL"
")", suffix.c_str() );
#else
sprintf( asql, "CREATE TABLE NGRAM5%s( "
"id integer,"
"iword1 integer,"
"iword2 integer,"
"iword3 integer,"
"iword4 integer,"
"iword5 integer,"
"w integer"
")", suffix.c_str() );
#endif
ExecuteSql(asql);
sprintf( asql, "CREATE TABLE NGRAM_STATS5%s( "
"max_w5 integer NOT NULL,"
"count_n5 integer NOT NULL"
")", suffix.c_str() );
ExecuteSql(asql);
#if LEM_DEBUGGING==1
sprintf( asql, "CREATE UNIQUE INDEX NGRAM_UNQ5_%s ON NGRAM5%s( iword1, iword2, iword3, iword4, iword5 )", suffix.c_str(), suffix.c_str() );
ExecuteSql(asql);
sprintf( asql, "CREATE UNIQUE INDEX ngrams_idx51%s ON NGRAM5%s(id)", suffix.c_str(), suffix.c_str() );
ExecuteSql(asql);
#endif
return;
}
示例14: GetWord
lem::UCString NGramsDBMS::GetWord(const lem::FString &suffix, const lem::FString &segment, int id_word)
{
FString sql = lem::format_str("SELECT word FROM NGRAM_WORDS%s%s WHERE id=%d"
, suffix.c_str(), segment.c_str(), id_word
);
std::unique_ptr<LS_ResultSet> rs(Select(sql));
if (rs->Fetch())
{
UCString w(rs->GetUCString(0));
return w;
}
else
{
LEM_STOPIT;
return lem::UCString();
}
}
示例15: LEM_CHECKIT_Z
void NGramsStorage_SQLITE::SelectFStrings( const lem::FString &Select, lem::Collect<lem::FString> &list )
{
LEM_CHECKIT_Z( !Select.empty() );
sqlite3_stmt *stmt=NULL;
int res = sqlite3_prepare_v2( hdb, Select.c_str(), -1, &stmt, NULL );
if( res==SQLITE_OK )
{
while( sqlite3_step( stmt ) == SQLITE_ROW )
{
lem::FString s = lem::sqlite_column_fstring( stmt, 0 );
list.push_back(s);
}
sqlite3_finalize(stmt);
}
return;
}