예제 #1
0
파일: Logs.cpp 프로젝트: Tatoeba/yadict
void Logs::insert_delete_meaning(
    int meaningId,
    int wordId,
    int userId,
    bool isMain,
    int actionId
) {
    // TODO factorize
    models::Meanings meaningsModel;

    results::Meaning meaning = meaningsModel.get_meaning_by_id(meaningId);
    if (!meaning.exists()) {
        return;
    }
    // log deletion of all the metas that were set on this meaning
    DefsMap::const_iterator end  = meaning.defsMap.end(); 
    for (
        DefsMap::const_iterator itr = meaning.defsMap.begin();
        itr != end;
        ++itr
    ) {
        insert_delete_meta_meaning(
            meaningId,
            itr->first,
            itr->second,
            userId,
            false,
            actionId
        );

    }
    // log deletion of all 'translation' links that were set on this meaning
    models::Translations transModel;
    TransVector translations = transModel.get_all_trans_meaning(meaningId);
 
    TransVector::const_iterator endTrans = translations.end();
     for (TransVector::const_iterator it = translations.begin(); it != endTrans; ++it) {
        insert_delete_trans_meaning(
            meaningId,
            *it,
            userId,
            false,
            actionId
        );
    }


    insert_meaning_log(
        meaningId,
        wordId,
        DELETE_ACTION,
        userId,
        isMain,
        actionId
    );

}
예제 #2
0
/**
  * Metoda pro spusteni jednoho kroku simulace. Odpaleny prechod se vybira nahodne,
  * protoze petriho site jsou ze sve podstaty nedeterministicke.
  */
void PetriSim::step()
{
    TransVector transits = state.getTransits(); //vytahne si vsechny prechody
    TransVector::iterator it;
    TransVector possible_transits; //prechody, ktere by se mohly odpalit

    bool was_fired = false; //pokud se mohl aspon jeden prechod odpalit
    for (it = transits.begin(); it != transits.end(); it++) {
        if ((*it)->fire()) { //tento prechod se muze odpalit,
            possible_transits.push_back((*it)); //pridam ho do vektoru prechodu k odpaleni
            was_fired = true;
        }
    }

    if (!was_fired) return;

    int which_transit = rand_int(possible_transits.size()); //vyberu nahodny prechod
    int which_values = rand_int(possible_transits[which_transit]->possibleChoicesCount()); //k tomu nahodnou konfiguraci

    possible_transits[which_transit]->doOperations(which_values); //odpalim
}
예제 #3
0
/**
  * Metoda pro spusteni simulace az do konce. Bezi, dokud je proveditelny prechod, nebo dokud
  * nevyprsi zadany pocet kroku.
  *
  * @param steps pocet kroku, kterej se maji udelat, implicitne 100
  */
void PetriSim::run(int steps)
{
    for (int i = 0; i<steps; i++) { //run je omezeno poctem kroku, ochrana proti zacykleni
        TransVector transits = state.getTransits(); //vytahnu vsechny prechody
        TransVector::iterator it;
        TransVector possible_transits; //prechody k odpaleni

        bool was_fired = false;
        for (it = transits.begin(); it != transits.end(); it++) {
            if ((*it)->fire()) { //prechod se muze odpalit
                possible_transits.push_back((*it)); //pridam ho do vektoru prechodu k odpaleni
                was_fired = true;
            }
        }

        if (!was_fired) return;

        int which_transit = rand_int(possible_transits.size()); //vyberu nahodny prechod
        int which_values = rand_int(possible_transits[which_transit]->possibleChoicesCount()); //k tomu nahodnou konfiguraci

        possible_transits[which_transit]->doOperations(which_values); //odpalim
    }
}
예제 #4
0
파일: Logs.cpp 프로젝트: Tatoeba/yadict
void Logs::insert_delete_word(
    int wordId,
    std::string lang,
    std::string text,
    int userId
) {
    
    int actionId = singletons::ActionId::get_instance()->get_action_id();


    // we first log the deletion of all the meta
    models::Metas metasModel;
    MetasMap metasMap = metasModel.get_all_metas_of_word(wordId);

    MetasMap::const_iterator end = metasMap.end();
    for (MetasMap::const_iterator it = metasMap.begin(); it != end; ++it) {
        insert_delete_meta(
            wordId,
            lang,
            it->first,
            it->second,
            userId,
            false,
            actionId
        );

    }


    // then deletion of all the meanings
    models::Meanings meaningsModel;
    MeaningsVector meanings = meaningsModel.get_all_meanings_on_word(wordId);

    MeaningsVector::const_iterator endMeanings = meanings.end();
    for (MeaningsVector::const_iterator it = meanings.begin(); it != endMeanings; ++it) {
        insert_delete_meaning(
            *it,
            wordId,
            userId,
            false,
            actionId
        );
    }



    // then deletion of all the translations link
    models::Translations transModel;
    TransVector transVector = transModel.get_all_trans_id(wordId);

    TransVector::const_iterator endTrans = transVector.end();
    for (TransVector::const_iterator it = transVector.begin(); it != endTrans; ++it) {
        insert_delete_trans(
            wordId,
            *it,
            userId,
            false,
            actionId
        );
    }

    // finally log deletion of word itself
    insert_word_log(
        wordId,
        lang,
        text,
        userId,
        DELETE_ACTION,
        "",
        "",
        actionId
    );
}