本文整理汇总了C++中TermList::size方法的典型用法代码示例。如果您正苦于以下问题:C++ TermList::size方法的具体用法?C++ TermList::size怎么用?C++ TermList::size使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TermList
的用法示例。
在下文中一共展示了TermList::size方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: analyzeSynonym
void CommonLanguageAnalyzer::analyzeSynonym(TermList& outList, size_t n)
{
static UString SPACE(" ", izenelib::util::UString::UTF_8);
TermList syOutList;
size_t wordCount = outList.size();
for (size_t i = 0; i < wordCount; i++)
{
// cout << "[off]" <<outList[i].wordOffset_<<" [level]"<<outList[i].getLevel() <<" [andor]" <<(unsigned int)(outList[i].getAndOrBit())
// << " "<< outList[i].textString()<<endl;
// find synonym for word(s)
for (size_t len = 1; (len <= n) && (i+len <= wordCount) ; len++)
{
// with space
bool ret = false;
unsigned int subLevel = 0;
UString combine;
if (len > 1)
{
for (size_t j = 0; j < len-1; j++)
{
combine.append(outList[i+j].text_);
combine.append(SPACE);
}
combine.append(outList[i+len-1].text_);
ret = getSynonym(combine, outList[i].wordOffset_, Term::OR, outList[i].getLevel(), syOutList, subLevel);
}
// without space
if (!ret)
{
combine.clear();
for (size_t j = 0; j < len; j++)
combine.append(outList[i+j].text_);
ret = getSynonym(combine, outList[i].wordOffset_, Term::OR, outList[i].getLevel(), syOutList, subLevel);
}
// adjust
if (ret)
{
outList[i].setStats(outList[i].getAndOrBit(), outList[i].getLevel()+subLevel);
for (size_t j = 1; j < len; j++)
{
outList[i+j].wordOffset_ = outList[i].wordOffset_;
outList[i+j].setStats(outList[i+j].getAndOrBit(), outList[i].getLevel());
}
break;
}
}
syOutList.push_back(outList[i]);
}
outList.swap(syOutList);
}
示例2: getBestSolution
Solution LpsolveAdaptator::getBestSolution(LinearProblem * lp) {
lprec *lprec;
int nbCol = lp->getVariables().size();
lprec = make_lp(0, nbCol);
if (lprec == NULL) {
// TODO raise an exception
}
/* set variables name to ease debugging */
for (int i = 0; i < (int)lp->getVariables().size(); ++i) {
Variable * var = (lp->getVariables())[i];
set_col_name(lprec, i+1, var->getNameToChar());
if (var->isBinary()) {
set_binary(lprec, i+1, TRUE);
}
}
/* to build the model faster when adding constraints one at a time */
set_add_rowmode(lprec, TRUE);
for (int i = 0; i < (int)(lp->getConstraints().size()); ++i) {
// FIXME there's a bug here but I can't find it
Constraint c = (Constraint)(lp->getConstraints()[i]);
TermList terms = c.getTerms();
int col[terms.size()];
REAL row[terms.size()];
int j = 0;
for (TermList::const_iterator it = terms.begin(); it != terms.end();
++it, ++j) {
// TODO check if this is fixed
col[j] = ((Term)*it).getVariable().getPosition();
row[j] = ((Term)*it).getCoeff();
}
// WARNING the Consraint uses the same operator values than in lp_lib.h
if (!add_constraintex(lprec, j, row, col, c.getOperator(), c.getBound())) {
// TODO raise an exception
}
}
/* the objective function requires rowmode to be off */
set_add_rowmode(lprec, FALSE);
TermList terms = lp->getObjective().getTerms();
int i = 0;
int col[terms.size()];
REAL row[terms.size()];
for (TermList::const_iterator it = terms.begin(); it != terms.end(); ++it,
++i) {
col[i] = ((Term)*it).getVariable().getPosition();
row[i] = (( Term )*it).getCoeff();
}
if (!set_obj_fnex(lprec, i, row, col)) {
// TODO raise an exception
}
if (lp->getObjective().isMinimize()) {
set_minim(lprec);
} else {
set_maxim(lprec);
}
return getSolution(lprec);
}
示例3: getSynonym
bool CommonLanguageAnalyzer::getSynonym(
const UString& combine,
int offset,
const unsigned char andOrBit,
const unsigned int level,
TermList& syOutList,
unsigned int& subLevel)
{
bool ret = false;
//cout << "combined: "; combine.displayStringValue(izenelib::util::UString::UTF_8); cout << endl;
char* combineStr = lowercase_string_buffer_;
UString::convertString(UString::UTF_8, combine.c_str(), combine.length(), lowercase_string_buffer_, term_string_buffer_limit_);
//cout << "combined string: " << string(combineStr) << endl;
UString::CharT * synonymResultUstr = NULL;
size_t synonymResultUstrLen = 0;
pSynonymContainer_ = uscSPtr_->getSynonymContainer();
pSynonymContainer_->searchNgetSynonym(combineStr, pSynonymResult_);
for (int i =0; i<pSynonymResult_->getSynonymCount(0); i++)
{
char * synonymResult = pSynonymResult_->getWord(0, i);
if (synonymResult)
{
if (strcmp(combineStr, synonymResult) == 0)
{
//cout << "synonym self: "<<string(synonymResult) <<endl;
continue;
}
cout << "synonym : "<<string(synonymResult) <<endl;
ret = true;
size_t synonymResultLen = strlen(synonymResult);
if (synonymResultLen <= term_ustring_buffer_limit_)
{
synonymResultUstr = synonym_ustring_buffer_;
synonymResultUstrLen = UString::toUcs2(synonymEncode_,
synonymResult, synonymResultLen, synonym_ustring_buffer_, term_ustring_buffer_limit_);
}
// word segmentment
UString term(synonymResultUstr, synonymResultUstrLen);
TermList termList;
if (innerAnalyzer_.get())
{
innerAnalyzer_->analyze(term, termList);
if (termList.size() <= 1)
{
syOutList.add(synonymResultUstr, synonymResultUstrLen, offset, NULL, andOrBit, level+subLevel);
subLevel++;
}
else
{
for (TermList::iterator iter = termList.begin(); iter != termList.end(); ++iter)
{
syOutList.add(iter->text_.c_str(), iter->text_.length(), offset, NULL, Term::AND, level+subLevel);
}
subLevel++;
}
}
else
{
syOutList.add(synonymResultUstr, synonymResultUstrLen, offset, NULL, andOrBit, level+subLevel);
subLevel++;
}
}
}
return ret;
}