1 // Copyright 2013 Google Inc. All Rights Reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 //
16 // Author: dsites@google.com (Dick Sites)
17 //
18 // Stuff used only by online detector, not used offline
19 //
20 
21 #ifndef I18N_ENCODINGS_CLD2_INTERNAL_NEW_CLDUTIL_H__
22 #define I18N_ENCODINGS_CLD2_INTERNAL_NEW_CLDUTIL_H__
23 
24 #include "cldutil_shared.h"
25 #include "scoreonescriptspan.h"
26 #include "tote.h"
27 
28 namespace CLD2 {
29 
30 // Score up to 64KB of a single script span in one pass
31 // Make a dummy entry off the end to calc length of last span
32 // Return offset of first unused input byte
33 int GetUniHits(const char* text,
34                      int letter_offset, int letter_limit,
35                      ScoringContext* scoringcontext,
36                      ScoringHitBuffer* hitbuffer);
37 
38 // Score up to 64KB of a single script span, doing both delta-bi and
39 // distinct bis in one pass
40 void GetBiHits(const char* text,
41                      int letter_offset, int letter_limit,
42                      ScoringContext* scoringcontext,
43                      ScoringHitBuffer* hitbuffer);
44 
45 // Score up to 64KB of a single script span in one pass
46 // Make a dummy entry off the end to calc length of last span
47 // Return offset of first unused input byte
48 int GetQuadHits(const char* text,
49                      int letter_offset, int letter_limit,
50                      ScoringContext* scoringcontext,
51                      ScoringHitBuffer* hitbuffer);
52 
53 // Score up to 64KB of a single script span, doing both delta-octa and
54 // distinct words in one pass
55 void GetOctaHits(const char* text,
56                      int letter_offset, int letter_limit,
57                      ScoringContext* scoringcontext,
58                      ScoringHitBuffer* hitbuffer);
59 
60 // Not sure if these belong here or in scoreonescriptspan.cc
61 int ReliabilityDelta(int value1, int value2, int gramcount);
62 int ReliabilityExpected(int actual_score_1kb, int expected_score_1kb);
63 
64 // Create a langprob packed value from its parts.
65 uint32 MakeLangProb(Language lang, int qprob);
66 
67 
68 void ProcessProbV2Tote(uint32 probs, Tote* tote);
69 
70 // Return score for a particular per-script language, or zero
71 int GetLangScore(uint32 probs, uint8 pslang);
72 
minint(int a,int b)73 static inline int minint(int a, int b) {return (a < b) ? a: b;}
maxint(int a,int b)74 static inline int maxint(int a, int b) {return (a > b) ? a: b;}
75 
76 }       // End namespace CLD2
77 
78 #endif  // I18N_ENCODINGS_CLD2_INTERNAL_NEW_CLDUTIL_H__
79 
80 
81