本文整理汇总了C++中Vocabulary类的典型用法代码示例。如果您正苦于以下问题:C++ Vocabulary类的具体用法?C++ Vocabulary怎么用?C++ Vocabulary使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Vocabulary类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: tr
void QuizFrame::editCurrentTerm() {
if( controller->isQuizInProgress() ) {
Folder* vocabTree = controller->getVocabTree();
Term* term = controller->getCurrentTerm();
if( !term ) {
QMessageBox::warning( this, QObject::tr( "Information" ), tr( "DissociatedWord" ) );
return;
}
Vocabulary* vocab = vocabTree->getVocabulary( term->getVocabId() );
if( vocab == NULL || !vocab->isTermExists( term->getId() ) ) {
QMessageBox::warning( this, QObject::tr( "Information" ), tr( "DissociatedWord" ) );
return;
}
TermDialog dialog( *vocab, controller, this, *term );
int result = dialog.exec();
if( result ) {
QString firstLang( controller->getQuizFirstLanguage() );
QString testLang( controller->getQuizTestLanguage() );
Term newTerm = dialog.getTerm();
Translation firstLangTrans = newTerm.getTranslation( firstLang );
Translation testLangTrans = newTerm.getTranslation( testLang );
term->addTranslation( firstLangTrans );
term->addTranslation( testLangTrans );
BilingualKey commentKey( firstLang, testLang );
term->addComment( commentKey, newTerm.getComment( commentKey ) );
term->setImagePath( newTerm.getImagePath() );
vocab->setModificationDate( QDateTime::currentDateTime() );
vocab->setDirty( true );
setTerm( newTerm );
}
}
}
示例2: editResultTerm
void SearchDialog::editResultTerm() {
ResultListItem* currItem = (ResultListItem*)resultsListView->currentItem();
if( currItem ) {
Term* term = currItem->getTerm();
if( term ) {
Vocabulary* vocab = controller->getVocabTree()->getVocabulary( term->getVocabId() );
TermDialog dialog( *vocab, controller, this, *term );
#if defined(Q_WS_HILDON)
dialog.showFullScreen();
#endif
int result = dialog.exec();
if( result ) {
Term newTerm = dialog.getTerm();
term->addTranslation( newTerm.getTranslation( controller->getPreferences().getFirstLanguage() ) );
term->addTranslation( newTerm.getTranslation( controller->getPreferences().getTestLanguage() ) );
BilingualKey commentKey( controller->getPreferences().getFirstLanguage(), controller->getPreferences().getTestLanguage() );
term->addComment( commentKey, newTerm.getComment( commentKey ) );
term->setImagePath( newTerm.getImagePath() );
currItem->updateUi();
vocab->setModificationDate( QDateTime::currentDateTime() );
vocab->setDirty( true );
}
}
}
}
示例3: kSetSynonyms
reg_t kSetSynonyms(EngineState *s, int argc, reg_t *argv) {
SegManager *segMan = s->_segMan;
reg_t object = argv[0];
List *list;
Node *node;
int script;
int numSynonyms = 0;
Vocabulary *voc = g_sci->getVocabulary();
// Only SCI0-SCI1 EGA games had a parser. In newer versions, this is a stub
if (getSciVersion() > SCI_VERSION_1_EGA_ONLY)
return s->r_acc;
voc->clearSynonyms();
list = s->_segMan->lookupList(readSelector(segMan, object, SELECTOR(elements)));
node = s->_segMan->lookupNode(list->first);
while (node) {
reg_t objpos = node->value;
int seg;
script = readSelectorValue(segMan, objpos, SELECTOR(number));
seg = s->_segMan->getScriptSegment(script);
if (seg > 0)
numSynonyms = s->_segMan->getScript(seg)->getSynonymsNr();
if (numSynonyms) {
const byte *synonyms = s->_segMan->getScript(seg)->getSynonyms();
if (synonyms) {
debugC(kDebugLevelParser, "Setting %d synonyms for script.%d",
numSynonyms, script);
if (numSynonyms > 16384) {
error("Segtable corruption: script.%03d has %d synonyms",
script, numSynonyms);
/* We used to reset the corrupted value here. I really don't think it's appropriate.
* Lars */
} else
for (int i = 0; i < numSynonyms; i++) {
synonym_t tmp;
tmp.replaceant = READ_LE_UINT16(synonyms + i * 4);
tmp.replacement = READ_LE_UINT16(synonyms + i * 4 + 2);
voc->addSynonym(tmp);
}
} else
warning("Synonyms of script.%03d were requested, but script is not available", script);
}
node = s->_segMan->lookupNode(node->succ);
}
debugC(kDebugLevelParser, "A total of %d synonyms are active now.", numSynonyms);
return s->r_acc;
}
示例4: test_simple_vocabulary
void test_simple_vocabulary(void) {
Vocabulary* voc = new Vocabulary("/home/sasha/work/data/test/stopwords.csv");
cout << voc->contains("the") << endl;
cout << voc->contains(".") << endl;
cout << voc->contains(")") << endl;
cout << voc->contains(",") << endl;
delete voc;
}
示例5: search
void SearchDialog::search() {
const Preferences& prefs = controller->getPreferences();
QList<TermKey> results = controller->search( queryField->currentText(), prefs.getFirstLanguage(), prefs.getTestLanguage() );
resultsListView->clear();
for( QList<TermKey>::ConstIterator it = results.begin(); it != results.end(); it++ ) {
const TermKey& termKey = *it;
Term* term = controller->getTerm( termKey );
Vocabulary* vocab = controller->getVocabTree()->getVocabulary( termKey.getVocabId() );
if( vocab ) {
ResultListItem* resultItem = new ResultListItem( resultsListView, term,
prefs.getFirstLanguage(), prefs.getTestLanguage(), vocab->getTitle(), vocab->getParent()->getHumanReadablePath(),
prefs.isAltInTermListShown() );
resultItem->setFont( 0, prefs.getMediumFont( prefs.getFirstLanguage() ) );
resultItem->setFont( 1, prefs.getMediumFont( prefs.getTestLanguage() ) );
}
}
resultsCounterLabel->setText( tr( "%1 term(s) found" ).arg( results.count() ) );
updateUi();
}
示例6: print_topics
void print_topics(const int num_per, const Vocabulary<W>& vocab) {
int topic_idx = 0;
for(const std::vector<double> topic : prior_word_) {
INFO << "Topic " << topic_idx;
std::vector<size_t> sorted_topic = ferrum::sort_indices(topic, false);
for(size_t item_idx = 0; item_idx < num_per; ++item_idx) {
size_t which = sorted_topic[item_idx];
INFO << "\t" << topic[which] << "\t" << vocab.word(which);
}
++topic_idx;
}
}
示例7: parse_sentence
int parse_sentence(const string& sentence, const Vocabulary& vocab, real subsample_thres, unsigned* p_seed, vector<uint64_t>* words) {
istringstream iss(sentence);
uint64_t total_cnt = vocab.total_cnt();
int word_cnt = 0;
string word;
while (iss >> word) {
uint64_t word_id;
if (!vocab.find_word_id(word, &word_id)) {
continue;
}
++word_cnt;
if (subsample_thres > 0) {
double t = subsample_thres * total_cnt / vocab.get_word_cnt(word_id);
double remain_prob = (sqrt(1 / t) + 1) * t; // not the same as the paper, which is sqrt(t)
if (remain_prob < static_cast<real>(rand_r(p_seed)) / RAND_MAX) {
continue;
}
}
words->push_back(word_id);
}
return word_cnt;
}
示例8: cfg_lock
void FissionReactor::updateVocabulary(const Vocabulary& v)
{
// first update anything in the Reactor base class that might be needed
ConfigWriteLock cfg_lock(*this);
Reactor::updateVocabulary(v);
v.refreshTerm(m_input_event_type);
v.refreshTerm(m_input_event_term);
boost::mutex::scoped_lock codec_lock(m_codec_mutex);
if (m_codec_ptr)
m_codec_ptr->updateVocabulary(v);
}
示例9: save_word_vec
void save_word_vec(ostream& os, const Net& net, const Vocabulary& vocab) {
size_t sz = net.hidden_layer_size();
const vector<Word>& words = vocab.vocab();
os << words.size() << " " << sz << endl;
for (size_t i = 0; i != words.size(); ++i) {
os << words[i].word;
const real* v = net.get_input_vec(i);
for (size_t j = 0; j != sz; ++j) {
os << " " << v[j];
}
os << endl;
}
}
示例10: MapBackToStr
inline void MapBackToStr(const vector<WORD_ID>& wid, vector<WORD>& tok, Vocabulary& vocab, vector<size_t>& NT_index){
tok.resize(wid.size());
NT_index.clear();
for(int i = 0; i< wid.size(); i++){
if(!ShouldIgnore(wid[i],vocab)){
tok[i] = vocab.getWord(wid[i]);
}
if(IsNT(wid[i],vocab)){
NT_index.push_back(i);
}
}
}
示例11: print_set
void print_set(FILE *f_inv, Vocabulary &voc, Translations &trans,
Translations &occured_words)
{
int trans_no = 0;
FOR_EACH (Translations, j, trans) {
string_t translation = *j;
if (occured_words.count(translation) > 0) {
continue;
}
occured_words.insert(translation);
if (trans_no > 0) {
fprintf(f_inv, ", ");
}
fprintf(f_inv, "%s", translation.c_str());
occured_words.insert(translation);
TranslationMap::iterator ref = voc.translation_map().find(
'\1' + translation);
if (ref != voc.translation_map().end()) {
fprintf(f_inv, ", ");
print_set(f_inv, voc, ref->second, occured_words);
}
++trans_no;
}
示例12: load
void LexicalTable::load( char *fileName )
{
cerr << "Loading lexical translation table from " << fileName;
ifstream inFile;
inFile.open(fileName);
if (inFile.fail()) {
cerr << " - ERROR: could not open file\n";
exit(1);
}
istream *inFileP = &inFile;
char line[LINE_MAX_LENGTH];
int i=0;
while(true) {
i++;
if (i%100000 == 0) cerr << "." << flush;
SAFE_GETLINE((*inFileP), line, LINE_MAX_LENGTH, '\n', __FILE__);
if (inFileP->eof()) break;
vector<string> token = tokenize( line );
if (token.size() != 3) {
cerr << "line " << i << " in " << fileName
<< " has wrong number of tokens, skipping:\n"
<< token.size() << " " << token[0] << " " << line << endl;
continue;
}
double prob = atof( token[2].c_str() );
WORD_ID wordT = vcbT.storeIfNew( token[0] );
WORD_ID wordS = vcbS.storeIfNew( token[1] );
ltable[ wordS ][ wordT ] = prob;
}
cerr << endl;
}
示例13: create
bool PhraseAlignment::create(const char line[], int lineID )
{
vector< string > token = tokenize( line );
int item = 1;
PHRASE phraseF, phraseE;
for (size_t j=0; j<token.size(); j++) {
if (token[j] == "|||") item++;
else {
if (item == 1)
phraseF.push_back( vcbF.storeIfNew( token[j] ) );
else if (item == 2)
phraseE.push_back( vcbE.storeIfNew( token[j] ) );
else if (item == 3) {
int e,f;
sscanf(token[j].c_str(), "%d-%d", &f, &e);
if ((size_t)e >= phraseE.size() || (size_t)f >= phraseF.size()) {
cerr << "WARNING: sentence " << lineID << " has alignment point (" << f << ", " << e << ") out of bounds (" << phraseF.size() << ", " << phraseE.size() << ")\n";
} else {
if (alignedToE.size() == 0) {
vector< size_t > dummy;
for(size_t i=0; i<phraseE.size(); i++)
alignedToE.push_back( dummy );
for(size_t i=0; i<phraseF.size(); i++)
alignedToF.push_back( dummy );
foreign = phraseTableF.storeIfNew( phraseF );
english = phraseTableE.storeIfNew( phraseE );
}
alignedToE[e].push_back( f );
alignedToF[f].push_back( e );
}
}
}
}
return (item>2); // real phrase pair, not just foreign phrase
}
示例14: load
void LexicalTable::load( const string &filePath )
{
cerr << "Loading lexical translation table from " << filePath;
ifstream inFile;
inFile.open(filePath.c_str());
if (inFile.fail()) {
cerr << " - ERROR: could not open file\n";
exit(1);
}
istream *inFileP = &inFile;
string line;
int i=0;
while(getline(*inFileP, line)) {
i++;
if (i%100000 == 0) cerr << "." << flush;
vector<string> token = tokenize( line.c_str() );
if (token.size() != 3) {
cerr << "line " << i << " in " << filePath << " has wrong number of tokens, skipping:\n" <<
token.size() << " " << token[0] << " " << line << endl;
continue;
}
double prob = atof( token[2].c_str() );
WORD_ID wordE = vcbE.storeIfNew( token[0] );
WORD_ID wordF = vcbF.storeIfNew( token[1] );
ltable[ wordF ][ wordE ] = prob;
}
cerr << endl;
}
示例15: MatchesAlignment
// Check for equal non-terminal alignment in case of SCFG rules.
// Precondition: otherTargetToSourceAlignment has the same size as m_targetToSourceAlignments.begin()->first
bool ExtractionPhrasePair::MatchesAlignment( ALIGNMENT *otherTargetToSourceAlignment ) const
{
if (!hierarchicalFlag) return true;
// all or none of the phrasePair's word alignment matrices match, so just pick one
const ALIGNMENT *thisTargetToSourceAlignment = m_targetToSourceAlignments.begin()->first;
assert(m_phraseTarget->size() == thisTargetToSourceAlignment->size() + 1);
assert(thisTargetToSourceAlignment->size() == otherTargetToSourceAlignment->size());
// loop over all symbols but the left hand side of the rule
for (size_t i=0; i<thisTargetToSourceAlignment->size()-1; ++i) {
if (isNonTerminal( vcbT.getWord( m_phraseTarget->at(i) ) )) {
size_t thisAlign = *(thisTargetToSourceAlignment->at(i).begin());
size_t otherAlign = *(otherTargetToSourceAlignment->at(i).begin());
if (thisTargetToSourceAlignment->at(i).size() != 1 ||
otherTargetToSourceAlignment->at(i).size() != 1 ||
thisAlign != otherAlign) {
return false;
}
}
}
return true;
}