本文整理汇总了C++中Vocabulary类的典型用法代码示例。如果您正苦于以下问题:C++ Vocabulary类的具体用法?C++ Vocabulary怎么用?C++ Vocabulary使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Vocabulary类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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 );
}
}
}
开发者ID:FBergeron,项目名称:tomotko-fremantle,代码行数:34,代码来源:QuizFrame.cpp
示例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 );
}
}
}
}
开发者ID:FBergeron,项目名称:tomotko-qt4,代码行数:25,代码来源:SearchDialog.cpp
示例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;
}
开发者ID:Cruel,项目名称:scummvm,代码行数:59,代码来源:kparse.cpp
示例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;
}
开发者ID:alexanderpanchenko,项目名称:stc,代码行数:9,代码来源:Vocabulary.cpp
示例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();
}
开发者ID:FBergeron,项目名称:tomotko-fremantle,代码行数:19,代码来源:SearchDialog.cpp
示例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;
}
}
开发者ID:fmof,项目名称:unified-probabilistic-frames,代码行数:12,代码来源:wtm.hpp
示例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;
}
开发者ID:yong-wang,项目名称:word2vecPlus,代码行数:22,代码来源:word2vec.cpp
示例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);
}
开发者ID:acmorrow,项目名称:pion-core,代码行数:13,代码来源:FissionReactor.cpp
示例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;
}
}
开发者ID:yong-wang,项目名称:word2vecPlus,代码行数:13,代码来源:word2vec.cpp
示例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);
}
}
}
开发者ID:edwardgao,项目名称:mosesdecoder,代码行数:13,代码来源:PhraseAlignment.cpp
示例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;
}
开发者ID:aababilov,项目名称:dictutils,代码行数:23,代码来源:dicinvert.cpp
示例12: EmptyEventException
void Codec::setConfig(const Vocabulary& v, const xmlNodePtr config_ptr)
{
PlatformPlugin::setConfig(v, config_ptr);
// determine the type of event used by the codec
std::string codec_event_str;
if (! ConfigManager::getConfigOption(EVENT_ELEMENT_NAME, codec_event_str,
config_ptr))
throw EmptyEventException(getId());
// find the Term reference number for the event type
Vocabulary::TermRef event_type = v.findTerm(codec_event_str);
if (event_type == Vocabulary::UNDEFINED_TERM_REF)
throw UnknownTermException(codec_event_str);
m_event_term = v[event_type];
// make sure that it is an object type Term
if (m_event_term.term_type != Vocabulary::TYPE_OBJECT)
throw NotAnObjectException(codec_event_str);
}
开发者ID:acmorrow,项目名称:pion-core,代码行数:20,代码来源:Codec.cpp
示例13: cfg_lock
void TransformReactor::setConfig(const Vocabulary& v, const xmlNodePtr config_ptr)
{
// first set config options for the Reactor base class
ConfigWriteLock cfg_lock(*this);
Reactor::setConfig(v, config_ptr);
// clear the current configuration
m_transforms.clear();
// Outgoing Event type -- i.e. what will the outgoing event be transformed into
// Default (UNDEFINED_TERM_REF) -- make it the same as incoming event type
// <OutgoingEvent>obj-term</OutgoingEvent>
m_event_type = Vocabulary::UNDEFINED_TERM_REF;
std::string event_type_str;
if (ConfigManager::getConfigOption(OUTGOING_EVENT_ELEMENT_NAME, event_type_str, config_ptr))
{
if (!event_type_str.empty())
m_event_type = v.findTerm(event_type_str);
}
// This really doesn't make much sense anymore -- you can wire the delivery of the original right through
// it would make sense, if it was possible to deliver "if-not-changed" but TR2 always changes...
// <DeliverOriginal>always|if-not-changed|never</DeliveryOriginal> -> DEFAULT: never
m_deliver_original = DO_NEVER;
std::string deliver_original_str;
if (ConfigManager::getConfigOption(DELIVER_ORIGINAL_NAME, deliver_original_str, config_ptr))
{
if (deliver_original_str == "true" || deliver_original_str == "always")
m_deliver_original = DO_ALWAYS;
else if (deliver_original_str == "if-not-changed")
m_deliver_original = DO_SOMETIMES;
// Could add code to throw if d_o_s is not "never"
}
// What fields/terms of the original event should be COPIED into the new event
// <CopyOriginal>all-terms|if-not-defined|none</CopyOriginal> -> DEFAULT: if-not-defined
m_copy_original = COPY_UNCHANGED;
std::string copy_original_str;
if (ConfigManager::getConfigOption(COPY_ORIGINAL_ELEMENT_NAME, copy_original_str, config_ptr))
{
if (copy_original_str == "all-terms")
m_copy_original = COPY_ALL;
else if (copy_original_str == "none")
m_copy_original = COPY_NONE;
// Could add code to throw if c_o_s is not "if-not-defined"
}
// now, parse transformation rules
// [rpt] <Transformation>
xmlNodePtr transformation_node = config_ptr;
while ( (transformation_node = ConfigManager::findConfigNodeByName(TRANSFORMATION_ELEMENT_NAME, transformation_node)) != NULL)
{
// parse new Transformation rule
// get the Term used for the Transformation rule
// <Term>src-term</Term>
std::string term_id;
if (! ConfigManager::getConfigOption(TERM_ELEMENT_NAME, term_id,
transformation_node->children))
throw EmptyTermException(getId());
// make sure that the Term is valid
const Vocabulary::TermRef term_ref = v.findTerm(term_id);
if (term_ref == Vocabulary::UNDEFINED_TERM_REF)
throw UnknownTermException(getId());
// get the Type of transformation
// <Type>AssignValue|AssignTerm|Lookup|Rules</Type>
std::string type_str;
if (! ConfigManager::getConfigOption(TYPE_ELEMENT_NAME, type_str,
transformation_node->children))
throw EmptyTypeException(getId()); // TODO: Improve the error message
// Add the transformation
const bool debug_mode = getReactionEngine().getDebugMode();
Transform *new_transform;
if (type_str == "AssignValue")
new_transform = new TransformAssignValue(v, v[term_ref], transformation_node->children, debug_mode);
else if (type_str == "AssignTerm")
new_transform = new TransformAssignTerm(v, v[term_ref], transformation_node->children, debug_mode);
else if (type_str == "Lookup")
new_transform = new TransformLookup(v, v[term_ref], transformation_node->children, debug_mode);
else if (type_str == "Rules")
new_transform = new TransformRules(v, v[term_ref], transformation_node->children, debug_mode);
else if (type_str == "Regex")
new_transform = new TransformRegex(v, v[term_ref], transformation_node->children, debug_mode);
else if (type_str == "SplitTerm")
new_transform = new TransformSplitTerm(v, v[term_ref], transformation_node->children, debug_mode);
else if (type_str == "JoinTerm")
new_transform = new TransformJoinTerm(v, v[term_ref], transformation_node->children, debug_mode);
else if (type_str == "URLEncode")
new_transform = new TransformURLEncode(v, v[term_ref], transformation_node->children, debug_mode);
else if (type_str == "URLDecode")
new_transform = new TransformURLDecode(v, v[term_ref], transformation_node->children, debug_mode);
else
throw InvalidTransformation(type_str);
m_transforms.push_back(new_transform);
// step to the next Comparison rule
//.........这里部分代码省略.........
开发者ID:acmorrow,项目名称:pion-core,代码行数:101,代码来源:TransformReactor.cpp
示例14: main
int main()
{
int imgNum=300;
vector<Mat> imgVec;
imgVec.resize(imgNum);
vector<string> nameVec;
nameVec.resize(imgNum);
vector<vector<KeyPoint> > keyPointsVec;
keyPointsVec.resize(imgNum);
vector<Mat> descriptorsVec;
descriptorsVec.resize(imgNum);
for(int i=0; i<imgNum; i++)
{
char fileName[1024] ={NULL};
sprintf(fileName, "/home/lili/workspace/SLAM/vocabTree/Lip6IndoorDataSet/Images/lip6kennedy_bigdoubleloop_%06d.ppm", i);
nameVec[i]=string(fileName);
imgVec[i]=imread(nameVec[i], CV_LOAD_IMAGE_GRAYSCALE);
}
//-- Step 1: Detect the keypoints using SURF Detector
int minHessian = 400;
SurfFeatureDetector detector(minHessian);
SurfDescriptorExtractor extractor;
vector<unsigned int> labels;
for(int i=0; i<imgNum; i++)
{
detector.detect(imgVec[i], keyPointsVec[i]);
extractor.compute(imgVec[i], keyPointsVec[i], descriptorsVec[i]);
for(int j = 0; j<descriptorsVec[i].rows; j++)
{
labels.push_back(i);
}
}
Mat all_descriptors;
for(int i = 0; i<descriptorsVec.size(); i++)
{
all_descriptors.push_back(descriptorsVec[i]);
}
assert(labels.size() == all_descriptors.rows);
cout<<"all_descriptors.rows "<<all_descriptors.rows<<endl;
cout<<"hahha1 "<<endl;
Vocabulary vocab;
vocab.indexedDescriptors_ = all_descriptors;
vector<KeyPoint> newKeypoints;
Mat newDescriptors;
///add new image to the randomized kd tree
{
string newImageName="/home/lili/workspace/SLAM/vocabTree/Lip6IndoorDataSet/Images/lip6kennedy_bigdoubleloop_000350.ppm";
Mat newImg=imread(newImageName, CV_LOAD_IMAGE_GRAYSCALE);
detector.detect(newImg, newKeypoints);
extractor.compute(newImg, newKeypoints, newDescriptors);
cout<<"newDescriptors.rows: "<<newDescriptors.rows<<endl;
}
vocab.notIndexedDescriptors_ = newDescriptors;
///clustering
int clustersNum;
Mat clusters(15000,64,CV_32F);
//Mat float_all_descriptors;
clustersNum=vocab.clustering(all_descriptors, clusters);
cout<<"clustersNum "<<clustersNum<<endl;
///flann build tree
clock_t begin1 = clock();
vocab.update();
clock_t end1 = clock();
double buildTree_time = double(end1 - begin1) / CLOCKS_PER_SEC;
cout.precision(5);
cout<<"buildTree time "<<buildTree_time<<endl;
cout<<"hahha2 "<<endl;
vector<KeyPoint> queryKeypoints;
Mat queryDescriptors;
///QueryImage
{
string queryImageName="/home/lili/workspace/SLAM/vocabTree/Lip6IndoorDataSet/Images/lip6kennedy_bigdoubleloop_000381.ppm";
//.........这里部分代码省略.........
开发者ID:LiliMeng,项目名称:FLANNBOWSearch,代码行数:101,代码来源:main.cpp
示例15: msgBox
void SearchDialog::doRemoveTerms( bool allowSelectTrans /* = true */, bool confirmBeforeRemove /* = true */ ) {
int selectedItemCount = 0;
// Find all the translation languages of the selected terms.
QStringList translationLanguages;
for( int i = 0; i < resultsListView->topLevelItemCount(); i++ ) {
ResultListItem* termItem = (ResultListItem*)resultsListView->topLevelItem( i );
if( termItem->isSelected() ) {
selectedItemCount++;
Term* term = termItem->getTerm();
for( Term::TranslationMap::ConstIterator it = term->translationsBegin(); it != term->translationsEnd(); it++ ) {
const Translation& trans = *it;
if( !translationLanguages.contains( trans.getLanguage() ) )
translationLanguages.append( trans.getLanguage() );
}
}
}
if( selectedItemCount == 0 )
return;
if( translationLanguages.count() <= 2 ) {
int response;
if( confirmBeforeRemove ) {
QMessageBox msgBox( QObject::tr( "Warning" ), tr( "ConfirmRemoveSelectedTerms" ),
QMessageBox::Warning,
QMessageBox::Yes,
QMessageBox::No | QMessageBox::Default | QMessageBox::Escape,
QMessageBox::NoButton,
this );
msgBox.setButtonText( QMessageBox::Yes, tr( "Yes" ) );
msgBox.setButtonText( QMessageBox::No, tr( "No" ) );
response = msgBox.exec();
}
else
response = QMessageBox::Yes;
if( response == QMessageBox::Yes ) {
for( int i = 0; i < resultsListView->topLevelItemCount(); i++ ) {
ResultListItem* termItem = (ResultListItem*)resultsListView->topLevelItem( i );
if( termItem->isSelected() ) {
Term* term = termItem->getTerm();
Vocabulary* vocab = controller->getVocabTree()->getVocabulary( term->getVocabId() );
if( !term->getImagePath().isNull() ) {
QDir imagePath( term->getImagePath() );
if( imagePath.isRelative() ) {
const QString& imagePath = controller->getApplicationDirName() + "/" + vocab->getParent()->getPath() +
"/v-" + QString::number( vocab->getId() ) + "/" + term->getImagePath();
QFile imageFile( imagePath );
if( imageFile.exists() ) {
if( !imageFile.remove() )
cerr << "Could not remove image " << qPrintable( imagePath ) << endl;
}
}
}
vocab->removeTerm( term->getId() );
delete( termItem );
vocab->setModificationDate( QDateTime::currentDateTime() );
vocab->setDirty( true );
}
}
resultsListView->clearSelection();
updateUi();
emit termsRemoved();
}
}
else {
int response;
QStringList selectedLanguages;
if( allowSelectTrans ) {
TranslationSelectionDialog msgBox( tr( "MultipleTranslationsDetectedForRemoveTermsCaption" ), tr( "MultipleTranslationsDetectedForRemoveTerms" ),
translationLanguages, TranslationSelectionDialog::selectionModeTargetLanguage, controller, this );
msgBox.setMaximumHeight( size().height() - 40 );
msgBox.setMaximumWidth( size().width() - 40 );
response = msgBox.exec();
if( response )
selectedLanguages = msgBox.getSelectedLanguages();
}
else {
selectedLanguages = QStringList();
selectedLanguages.append( controller->getPreferences().getFirstLanguage() );
selectedLanguages.append( controller->getPreferences().getTestLanguage() );
}
if( selectedLanguages.count() == 0 )
return;
for( int i = 0; i < resultsListView->topLevelItemCount(); i++ ) {
ResultListItem* termItem = (ResultListItem*)resultsListView->topLevelItem( i );
if( termItem->isSelected() ) {
Term* term = termItem->getTerm();
Vocabulary* vocab = controller->getVocabTree()->getVocabulary( term->getVocabId() );
for( QStringList::ConstIterator it = selectedLanguages.begin(); it != selectedLanguages.end(); it++ ) {
QString lang = *it;
term->removeTranslation( lang );
}
//.........这里部分代码省略.........
开发者ID:FBergeron,项目名称:tomotko-fremantle,代码行数:101,代码来源:SearchDialog.cpp
示例16: kParse
reg_t kParse(EngineState *s, int argc, reg_t *argv) {
SegManager *segMan = s->_segMan;
reg_t stringpos = argv[0];
Common::String string = s->_segMan->getString(stringpos);
char *error;
reg_t event = argv[1];
g_sci->checkVocabularySwitch();
Vocabulary *voc = g_sci->getVocabulary();
voc->parser_event = event;
reg_t params[2] = { s->_segMan->getParserPtr(), stringpos };
ResultWordListList words;
bool res = voc->tokenizeString(words, string.c_str(), &error);
voc->parserIsValid = false; /* not valid */
if (res && !words.empty()) {
voc->synonymizeTokens(words);
s->r_acc = make_reg(0, 1);
#ifdef DEBUG_PARSER
debugC(kDebugLevelParser, "Parsed to the following blocks:");
for (ResultWordListList::const_iterator i = words.begin(); i != words.end(); ++i) {
debugCN(2, kDebugLevelParser, " ");
for (ResultWordList::const_iterator j = i->begin(); j != i->end(); ++j) {
debugCN(2, kDebugLevelParser, "%sType[%04x] Group[%04x]", j == i->begin() ? "" : " / ", j->_class, j->_group);
}
debugCN(2, kDebugLevelParser, "\n");
}
#endif
voc->replacePronouns(words);
int syntax_fail = voc->parseGNF(words);
if (syntax_fail) {
s->r_acc = make_reg(0, 1);
writeSelectorValue(segMan, event, SELECTOR(claimed), 1);
invokeSelector(s, g_sci->getGameObject(), SELECTOR(syntaxFail), argc, argv, 2, params);
/* Issue warning */
debugC(kDebugLevelParser, "Tree building failed");
} else {
voc->parserIsValid = true;
voc->storePronounReference();
writeSelectorValue(segMan, event, SELECTOR(claimed), 0);
#ifdef DEBUG_PARSER
voc->dumpParseTree();
#endif
}
} else {
s->r_acc = make_reg(0, 0);
writeSelectorValue(segMan, event, SELECTOR(claimed), 1);
if (error) {
s->_segMan->strcpy(s->_segMan->getParserPtr(), error);
debugC(kDebugLevelParser, "Word unknown: %s", error);
/* Issue warning: */
invokeSelector(s, g_sci->getGameObject(), SELECTOR(wordFail), argc, argv, 2, params);
free(error);
return make_reg(0, 1); /* Tell them that it didn't work */
}
}
return s->r_acc;
}
开发者ID:Cruel,项目名称:scummvm,代码行数:73,代码来源:kparse.cpp
示例17: 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;
}
开发者ID:xwd,项目名称:mosesGit-hiero,代码行数:35,代码来源:score.cpp
示例18: 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
}
开发者ID:Deseaus,项目名称:mosesdecoder,代码行数:35,代码来源:statistics-main.cpp
示例19: 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;
}
开发者ID:Deseaus,项目名称:mosesdecoder,代码行数:32,代码来源:statistics-main.cpp
示例20: 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;
}
开发者ID:A30041839,项目名称:mosesdecoder,代码行数:28,代码来源:ExtractionPhrasePair.cpp
注:本文中的Vocabulary类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论