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_NEW_WORD(profiler) profiler.profNewWord()
     35 #define PROF_NEW_WORD_BIGRAM(profiler) profiler.profNewWordBigram()
     36 #define PROF_NODE_RESET(profiler) profiler.reset()
     37 #define PROF_NODE_COPY(src, dest) dest.copy(src)
     38 #else
     39 #define PROF_SPACE_SUBSTITUTION(profiler)
     40 #define PROF_SPACE_OMISSION(profiler)
     41 #define PROF_ADDITONAL_PROXIMITY(profiler)
     42 #define PROF_SUBSTITUTION(profiler)
     43 #define PROF_OMISSION(profiler)
     44 #define PROF_INSERTION(profiler)
     45 #define PROF_MATCH(profiler)
     46 #define PROF_COMPLETION(profiler)
     47 #define PROF_TRANSPOSITION(profiler)
     48 #define PROF_NEARESTKEY(profiler)
     49 #define PROF_TERMINAL(profiler)
     50 #define PROF_NEW_WORD(profiler)
     51 #define PROF_NEW_WORD_BIGRAM(profiler)
     52 #define PROF_NODE_RESET(profiler)
     53 #define PROF_NODE_COPY(src, dest)
     54 #endif
     55 
     56 namespace latinime {
     57 
     58 class DicNodeProfiler {
     59  public:
     60 #if DEBUG_DICT
     61     AK_FORCE_INLINE DicNodeProfiler()
     62             : mProfOmission(0), mProfInsertion(0), mProfTransposition(0),
     63               mProfAdditionalProximity(0), mProfSubstitution(0),
     64               mProfSpaceSubstitution(0), mProfSpaceOmission(0),
     65               mProfMatch(0), mProfCompletion(0), mProfTerminal(0),
     66               mProfNearestKey(0), mProfNewWord(0), mProfNewWordBigram(0) {}
     67 
     68     int mProfOmission;
     69     int mProfInsertion;
     70     int mProfTransposition;
     71     int mProfAdditionalProximity;
     72     int mProfSubstitution;
     73     int mProfSpaceSubstitution;
     74     int mProfSpaceOmission;
     75     int mProfMatch;
     76     int mProfCompletion;
     77     int mProfTerminal;
     78     int mProfNearestKey;
     79     int mProfNewWord;
     80     int mProfNewWordBigram;
     81 
     82     void profSpaceSubstitution() {
     83         ++mProfSpaceSubstitution;
     84     }
     85 
     86     void profSpaceOmission() {
     87         ++mProfSpaceOmission;
     88     }
     89 
     90     void profAdditionalProximity() {
     91         ++mProfAdditionalProximity;
     92     }
     93 
     94     void profSubstitution() {
     95         ++mProfSubstitution;
     96     }
     97 
     98     void profOmission() {
     99         ++mProfOmission;
    100     }
    101 
    102     void profInsertion() {
    103         ++mProfInsertion;
    104     }
    105 
    106     void profMatch() {
    107         ++mProfMatch;
    108     }
    109 
    110     void profCompletion() {
    111         ++mProfCompletion;
    112     }
    113 
    114     void profTransposition() {
    115         ++mProfTransposition;
    116     }
    117 
    118     void profNearestKey() {
    119         ++mProfNearestKey;
    120     }
    121 
    122     void profTerminal() {
    123         ++mProfTerminal;
    124     }
    125 
    126     void profNewWord() {
    127         ++mProfNewWord;
    128     }
    129 
    130     void profNewWordBigram() {
    131         ++mProfNewWordBigram;
    132     }
    133 
    134     void reset() {
    135         mProfSpaceSubstitution = 0;
    136         mProfSpaceOmission = 0;
    137         mProfAdditionalProximity = 0;
    138         mProfSubstitution = 0;
    139         mProfOmission = 0;
    140         mProfInsertion = 0;
    141         mProfMatch = 0;
    142         mProfCompletion = 0;
    143         mProfTransposition = 0;
    144         mProfNearestKey = 0;
    145         mProfTerminal = 0;
    146         mProfNewWord = 0;
    147         mProfNewWordBigram = 0;
    148     }
    149 
    150     void copy(const DicNodeProfiler *const profiler) {
    151         mProfSpaceSubstitution = profiler->mProfSpaceSubstitution;
    152         mProfSpaceOmission = profiler->mProfSpaceOmission;
    153         mProfAdditionalProximity = profiler->mProfAdditionalProximity;
    154         mProfSubstitution = profiler->mProfSubstitution;
    155         mProfOmission = profiler->mProfOmission;
    156         mProfInsertion = profiler->mProfInsertion;
    157         mProfMatch = profiler->mProfMatch;
    158         mProfCompletion = profiler->mProfCompletion;
    159         mProfTransposition = profiler->mProfTransposition;
    160         mProfNearestKey = profiler->mProfNearestKey;
    161         mProfTerminal = profiler->mProfTerminal;
    162         mProfNewWord = profiler->mProfNewWord;
    163         mProfNewWordBigram = profiler->mProfNewWordBigram;
    164     }
    165 
    166     void dump() const {
    167         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",
    168                 mProfOmission, mProfInsertion, mProfTransposition, mProfAdditionalProximity,
    169                 mProfSubstitution, mProfSpaceSubstitution, mProfSpaceOmission, mProfMatch,
    170                 mProfCompletion, mProfTerminal, mProfNewWord, mProfNewWordBigram);
    171     }
    172 #else
    173     DicNodeProfiler() {}
    174 #endif
    175  private:
    176     // Caution!!!
    177     // Use a default copy constructor and an assign operator because shallow copies are ok
    178     // for this class
    179 };
    180 }
    181 #endif // LATINIME_DIC_NODE_PROFILER_H
    182