Home | History | Annotate | Download | only in dicnode
      1 /*
      2  * Copyright (C) 2012 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 #ifndef LATINIME_DIC_NODE_PROFILER_H
     18 #define LATINIME_DIC_NODE_PROFILER_H
     19 
     20 #include "defines.h"
     21 
     22 #if DEBUG_DICT
     23 #define PROF_SPACE_SUBSTITUTION(profiler) profiler.profSpaceSubstitution()
     24 #define PROF_SPACE_OMISSION(profiler) profiler.profSpaceOmission()
     25 #define PROF_ADDITIONAL_PROXIMITY(profiler) profiler.profAdditionalProximity()
     26 #define PROF_SUBSTITUTION(profiler) profiler.profSubstitution()
     27 #define PROF_OMISSION(profiler) profiler.profOmission()
     28 #define PROF_INSERTION(profiler) profiler.profInsertion()
     29 #define PROF_MATCH(profiler) profiler.profMatch()
     30 #define PROF_COMPLETION(profiler) profiler.profCompletion()
     31 #define PROF_TRANSPOSITION(profiler) profiler.profTransposition()
     32 #define PROF_NEARESTKEY(profiler) profiler.profNearestKey()
     33 #define PROF_TERMINAL(profiler) profiler.profTerminal()
     34 #define PROF_TERMINAL_INSERTION(profiler) profiler.profTerminalInsertion()
     35 #define PROF_NEW_WORD(profiler) profiler.profNewWord()
     36 #define PROF_NEW_WORD_BIGRAM(profiler) profiler.profNewWordBigram()
     37 #define PROF_NODE_RESET(profiler) profiler.reset()
     38 #define PROF_NODE_COPY(src, dest) dest.copy(src)
     39 #else
     40 #define PROF_SPACE_SUBSTITUTION(profiler)
     41 #define PROF_SPACE_OMISSION(profiler)
     42 #define PROF_ADDITONAL_PROXIMITY(profiler)
     43 #define PROF_SUBSTITUTION(profiler)
     44 #define PROF_OMISSION(profiler)
     45 #define PROF_INSERTION(profiler)
     46 #define PROF_MATCH(profiler)
     47 #define PROF_COMPLETION(profiler)
     48 #define PROF_TRANSPOSITION(profiler)
     49 #define PROF_NEARESTKEY(profiler)
     50 #define PROF_TERMINAL(profiler)
     51 #define PROF_TERMINAL_INSERTION(profiler)
     52 #define PROF_NEW_WORD(profiler)
     53 #define PROF_NEW_WORD_BIGRAM(profiler)
     54 #define PROF_NODE_RESET(profiler)
     55 #define PROF_NODE_COPY(src, dest)
     56 #endif
     57 
     58 namespace latinime {
     59 
     60 class DicNodeProfiler {
     61  public:
     62 #if DEBUG_DICT
     63     AK_FORCE_INLINE DicNodeProfiler()
     64             : mProfOmission(0), mProfInsertion(0), mProfTransposition(0),
     65               mProfAdditionalProximity(0), mProfSubstitution(0),
     66               mProfSpaceSubstitution(0), mProfSpaceOmission(0),
     67               mProfMatch(0), mProfCompletion(0), mProfTerminal(0), mProfTerminalInsertion(0),
     68               mProfNearestKey(0), mProfNewWord(0), mProfNewWordBigram(0) {}
     69 
     70     int mProfOmission;
     71     int mProfInsertion;
     72     int mProfTransposition;
     73     int mProfAdditionalProximity;
     74     int mProfSubstitution;
     75     int mProfSpaceSubstitution;
     76     int mProfSpaceOmission;
     77     int mProfMatch;
     78     int mProfCompletion;
     79     int mProfTerminal;
     80     int mProfTerminalInsertion;
     81     int mProfNearestKey;
     82     int mProfNewWord;
     83     int mProfNewWordBigram;
     84 
     85     void profSpaceSubstitution() {
     86         ++mProfSpaceSubstitution;
     87     }
     88 
     89     void profSpaceOmission() {
     90         ++mProfSpaceOmission;
     91     }
     92 
     93     void profAdditionalProximity() {
     94         ++mProfAdditionalProximity;
     95     }
     96 
     97     void profSubstitution() {
     98         ++mProfSubstitution;
     99     }
    100 
    101     void profOmission() {
    102         ++mProfOmission;
    103     }
    104 
    105     void profInsertion() {
    106         ++mProfInsertion;
    107     }
    108 
    109     void profMatch() {
    110         ++mProfMatch;
    111     }
    112 
    113     void profCompletion() {
    114         ++mProfCompletion;
    115     }
    116 
    117     void profTransposition() {
    118         ++mProfTransposition;
    119     }
    120 
    121     void profNearestKey() {
    122         ++mProfNearestKey;
    123     }
    124 
    125     void profTerminal() {
    126         ++mProfTerminal;
    127     }
    128 
    129     void profTerminalInsertion() {
    130         ++mProfTerminalInsertion;
    131     }
    132 
    133     void profNewWord() {
    134         ++mProfNewWord;
    135     }
    136 
    137     void profNewWordBigram() {
    138         ++mProfNewWordBigram;
    139     }
    140 
    141     void reset() {
    142         mProfSpaceSubstitution = 0;
    143         mProfSpaceOmission = 0;
    144         mProfAdditionalProximity = 0;
    145         mProfSubstitution = 0;
    146         mProfOmission = 0;
    147         mProfInsertion = 0;
    148         mProfMatch = 0;
    149         mProfCompletion = 0;
    150         mProfTransposition = 0;
    151         mProfNearestKey = 0;
    152         mProfTerminal = 0;
    153         mProfNewWord = 0;
    154         mProfNewWordBigram = 0;
    155     }
    156 
    157     void copy(const DicNodeProfiler *const profiler) {
    158         mProfSpaceSubstitution = profiler->mProfSpaceSubstitution;
    159         mProfSpaceOmission = profiler->mProfSpaceOmission;
    160         mProfAdditionalProximity = profiler->mProfAdditionalProximity;
    161         mProfSubstitution = profiler->mProfSubstitution;
    162         mProfOmission = profiler->mProfOmission;
    163         mProfInsertion = profiler->mProfInsertion;
    164         mProfMatch = profiler->mProfMatch;
    165         mProfCompletion = profiler->mProfCompletion;
    166         mProfTransposition = profiler->mProfTransposition;
    167         mProfNearestKey = profiler->mProfNearestKey;
    168         mProfTerminal = profiler->mProfTerminal;
    169         mProfNewWord = profiler->mProfNewWord;
    170         mProfNewWordBigram = profiler->mProfNewWordBigram;
    171     }
    172 
    173     void dump() const {
    174         AKLOGI("O %d, I %d, T %d, AP %d, S %d, SS %d, SO %d, M %d, C %d, TE %d, NW = %d, NWB = %d",
    175                 mProfOmission, mProfInsertion, mProfTransposition, mProfAdditionalProximity,
    176                 mProfSubstitution, mProfSpaceSubstitution, mProfSpaceOmission, mProfMatch,
    177                 mProfCompletion, mProfTerminal, mProfNewWord, mProfNewWordBigram);
    178     }
    179 #else
    180     DicNodeProfiler() {}
    181 #endif
    182  private:
    183     // Caution!!!
    184     // Use a default copy constructor and an assign operator because shallow copies are ok
    185     // for this class
    186 };
    187 }
    188 #endif // LATINIME_DIC_NODE_PROFILER_H
    189