cld-fixed 0.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (121) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +20 -0
  3. data/.rspec +2 -0
  4. data/Gemfile +6 -0
  5. data/LICENSE +27 -0
  6. data/README.md +34 -0
  7. data/Rakefile +5 -0
  8. data/cld.gemspec +22 -0
  9. data/ext/cld/Makefile.am +28 -0
  10. data/ext/cld/Makefile.in +790 -0
  11. data/ext/cld/aclocal.m4 +8895 -0
  12. data/ext/cld/base/basictypes.h +348 -0
  13. data/ext/cld/base/build_config.h +115 -0
  14. data/ext/cld/base/casts.h +156 -0
  15. data/ext/cld/base/commandlineflags.h +443 -0
  16. data/ext/cld/base/crash.h +41 -0
  17. data/ext/cld/base/dynamic_annotations.h +358 -0
  18. data/ext/cld/base/global_strip_options.h +59 -0
  19. data/ext/cld/base/log_severity.h +46 -0
  20. data/ext/cld/base/logging.h +1403 -0
  21. data/ext/cld/base/macros.h +243 -0
  22. data/ext/cld/base/port.h +54 -0
  23. data/ext/cld/base/scoped_ptr.h +428 -0
  24. data/ext/cld/base/stl_decl.h +0 -0
  25. data/ext/cld/base/stl_decl_msvc.h +107 -0
  26. data/ext/cld/base/string_util.h +29 -0
  27. data/ext/cld/base/strtoint.h +93 -0
  28. data/ext/cld/base/template_util.h +96 -0
  29. data/ext/cld/base/type_traits.h +198 -0
  30. data/ext/cld/base/vlog_is_on.h +143 -0
  31. data/ext/cld/build_aux/config.guess +1500 -0
  32. data/ext/cld/build_aux/config.sub +1616 -0
  33. data/ext/cld/build_aux/depcomp +584 -0
  34. data/ext/cld/build_aux/install-sh +507 -0
  35. data/ext/cld/build_aux/ltmain.sh +8745 -0
  36. data/ext/cld/build_aux/missing +367 -0
  37. data/ext/cld/cld_encodings.h +95 -0
  38. data/ext/cld/configure +17362 -0
  39. data/ext/cld/configure.ac +14 -0
  40. data/ext/cld/encodings/compact_lang_det/#cldutil.cc# +905 -0
  41. data/ext/cld/encodings/compact_lang_det/#cldutil.h# +1205 -0
  42. data/ext/cld/encodings/compact_lang_det/#compact_lang_det_impl.h# +171 -0
  43. data/ext/cld/encodings/compact_lang_det/#ext_lang_enc.cc# +545 -0
  44. data/ext/cld/encodings/compact_lang_det/#ext_lang_enc.h# +119 -0
  45. data/ext/cld/encodings/compact_lang_det/#getonescriptspan.cc# +570 -0
  46. data/ext/cld/encodings/compact_lang_det/#getonescriptspan.h# +131 -0
  47. data/ext/cld/encodings/compact_lang_det/#tote.cc# +299 -0
  48. data/ext/cld/encodings/compact_lang_det/#tote.h# +89 -0
  49. data/ext/cld/encodings/compact_lang_det/cldutil.cc +905 -0
  50. data/ext/cld/encodings/compact_lang_det/cldutil.h +1205 -0
  51. data/ext/cld/encodings/compact_lang_det/cldutil_dbg.h +76 -0
  52. data/ext/cld/encodings/compact_lang_det/cldutil_dbg_empty.cc +76 -0
  53. data/ext/cld/encodings/compact_lang_det/compact_lang_det.cc +62 -0
  54. data/ext/cld/encodings/compact_lang_det/compact_lang_det.h +145 -0
  55. data/ext/cld/encodings/compact_lang_det/compact_lang_det_impl.cc +2574 -0
  56. data/ext/cld/encodings/compact_lang_det/compact_lang_det_impl.h +173 -0
  57. data/ext/cld/encodings/compact_lang_det/compact_lang_det_unittest_small.cc +406 -0
  58. data/ext/cld/encodings/compact_lang_det/compile.cmd +1 -0
  59. data/ext/cld/encodings/compact_lang_det/ext_lang_enc.cc +545 -0
  60. data/ext/cld/encodings/compact_lang_det/ext_lang_enc.h +119 -0
  61. data/ext/cld/encodings/compact_lang_det/generated/cld_generated_score_deltaoctachrome_0406.cc +380 -0
  62. data/ext/cld/encodings/compact_lang_det/generated/cld_generated_score_quadchrome_0406.cc +382 -0
  63. data/ext/cld/encodings/compact_lang_det/generated/compact_lang_det_generated_cjkbis_0.cc +49 -0
  64. data/ext/cld/encodings/compact_lang_det/generated/compact_lang_det_generated_ctjkvz.cc +7119 -0
  65. data/ext/cld/encodings/compact_lang_det/generated/compact_lang_det_generated_ctjkvz_0.cc +61 -0
  66. data/ext/cld/encodings/compact_lang_det/generated/compact_lang_det_generated_deltaoctachrome.cc +1263 -0
  67. data/ext/cld/encodings/compact_lang_det/generated/compact_lang_det_generated_longwords8_0.cc +53 -0
  68. data/ext/cld/encodings/compact_lang_det/generated/compact_lang_det_generated_meanscore.h +10 -0
  69. data/ext/cld/encodings/compact_lang_det/generated/compact_lang_det_generated_quads_0.cc +50 -0
  70. data/ext/cld/encodings/compact_lang_det/generated/compact_lang_det_generated_quadschrome.cc +70935 -0
  71. data/ext/cld/encodings/compact_lang_det/getonescriptspan.cc +570 -0
  72. data/ext/cld/encodings/compact_lang_det/getonescriptspan.h +131 -0
  73. data/ext/cld/encodings/compact_lang_det/letterscript_enum.cc +117 -0
  74. data/ext/cld/encodings/compact_lang_det/letterscript_enum.h +99 -0
  75. data/ext/cld/encodings/compact_lang_det/subsetsequence.cc +259 -0
  76. data/ext/cld/encodings/compact_lang_det/subsetsequence.h +44 -0
  77. data/ext/cld/encodings/compact_lang_det/subsetsequence_unittest.cc +99 -0
  78. data/ext/cld/encodings/compact_lang_det/tote.cc +299 -0
  79. data/ext/cld/encodings/compact_lang_det/tote.h +89 -0
  80. data/ext/cld/encodings/compact_lang_det/unittest_data.h +193 -0
  81. data/ext/cld/encodings/compact_lang_det/utf8propjustletter.h +1162 -0
  82. data/ext/cld/encodings/compact_lang_det/utf8propletterscriptnum.h +1222 -0
  83. data/ext/cld/encodings/compact_lang_det/utf8scannotjustletterspecial.h +1185 -0
  84. data/ext/cld/encodings/compact_lang_det/win/#cld_unilib_windows.cc# +29 -0
  85. data/ext/cld/encodings/compact_lang_det/win/cld_basictypes.h +10 -0
  86. data/ext/cld/encodings/compact_lang_det/win/cld_commandlineflags.h +28 -0
  87. data/ext/cld/encodings/compact_lang_det/win/cld_google.h +18 -0
  88. data/ext/cld/encodings/compact_lang_det/win/cld_htmlutils.h +13 -0
  89. data/ext/cld/encodings/compact_lang_det/win/cld_htmlutils_google3.cc +32 -0
  90. data/ext/cld/encodings/compact_lang_det/win/cld_htmlutils_windows.cc +29 -0
  91. data/ext/cld/encodings/compact_lang_det/win/cld_logging.h +21 -0
  92. data/ext/cld/encodings/compact_lang_det/win/cld_macros.h +19 -0
  93. data/ext/cld/encodings/compact_lang_det/win/cld_strtoint.h +26 -0
  94. data/ext/cld/encodings/compact_lang_det/win/cld_unicodetext.cc +84 -0
  95. data/ext/cld/encodings/compact_lang_det/win/cld_unicodetext.h +40 -0
  96. data/ext/cld/encodings/compact_lang_det/win/cld_unilib.h +15 -0
  97. data/ext/cld/encodings/compact_lang_det/win/cld_unilib_google3.cc +18 -0
  98. data/ext/cld/encodings/compact_lang_det/win/cld_unilib_windows.cc +29 -0
  99. data/ext/cld/encodings/compact_lang_det/win/cld_utf.h +24 -0
  100. data/ext/cld/encodings/compact_lang_det/win/cld_utf8statetable.cc +224 -0
  101. data/ext/cld/encodings/compact_lang_det/win/cld_utf8statetable.h +141 -0
  102. data/ext/cld/encodings/compact_lang_det/win/cld_utf8utils.h +22 -0
  103. data/ext/cld/encodings/compact_lang_det/win/cld_utf8utils_google3.cc +18 -0
  104. data/ext/cld/encodings/compact_lang_det/win/cld_utf8utils_windows.cc +17 -0
  105. data/ext/cld/encodings/compact_lang_det/win/normalizedunicodetext.cc +172 -0
  106. data/ext/cld/encodings/compact_lang_det/win/normalizedunicodetext.h +67 -0
  107. data/ext/cld/encodings/internal/encodings.cc +12 -0
  108. data/ext/cld/encodings/lang_enc.h +254 -0
  109. data/ext/cld/encodings/proto/encodings.pb.h +169 -0
  110. data/ext/cld/encodings/public/encodings.h +301 -0
  111. data/ext/cld/extconf.rb +7 -0
  112. data/ext/cld/languages/internal/#languages.cc# +337 -0
  113. data/ext/cld/languages/internal/languages.cc +336 -0
  114. data/ext/cld/languages/proto/languages.pb.h +179 -0
  115. data/ext/cld/languages/public/languages.h +379 -0
  116. data/ext/cld/thunk.cc +55 -0
  117. data/lib/cld.rb +21 -0
  118. data/lib/cld/version.rb +3 -0
  119. data/spec/cld_spec.rb +67 -0
  120. data/spec/spec_helper.rb +6 -0
  121. metadata +193 -0
@@ -0,0 +1,379 @@
1
+ // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2
+ // Use of this source code is governed by a BSD-style license that can be
3
+ // found in the LICENSE file.
4
+
5
+ #ifndef LANGUAGES_PUBLIC_LANGUAGES_H_
6
+ #define LANGUAGES_PUBLIC_LANGUAGES_H_
7
+
8
+ // This interface defines the Language enum and functions that depend
9
+ // only on Language values.
10
+
11
+ // A hash-function for Language, hash<Language>, is defined in
12
+ // i18n/languages/public/languages-hash.h
13
+
14
+ #ifndef SWIG
15
+ // Language enum defined in languages.proto
16
+ // Also description on how to add languages.
17
+ #include "languages/proto/languages.pb.h"
18
+
19
+ // We need this for compatibility:
20
+ // - The Language enum in the default namespace.
21
+ // COMMENTED OUT TO REDUCE DEPENDENCIES ON GOOGLE3 CODE
22
+ //using namespace i18n::languages;
23
+
24
+ #else
25
+ // And we must have a swig-compatible enum.
26
+ // This one is a simple cleaned up version of language.proto, making the enum
27
+ // compatible with C++.
28
+ #include "i18n/languages/internal/languages_proto_wrapper.h"
29
+
30
+ #endif
31
+
32
+ // COMMENTED OUT TO REDUCE DEPENDENCIES ON GOOGLE3 CODE
33
+ //#include "util/utf8/proptables/script_enum.h"
34
+
35
+ const int kNumLanguages = NUM_LANGUAGES;
36
+
37
+ // Return the default language (ENGLISH).
38
+ Language default_language();
39
+
40
+
41
+ // *******************************************
42
+ // Language predicates
43
+ // IsValidLanguage()
44
+ // IS_LANGUAGE_UNKNOWN()
45
+ // IsCJKLanguage()
46
+ // IsChineseLanguage()
47
+ // IsNorwegianLanguage()
48
+ // IsPortugueseLanguage()
49
+ // IsRightToLeftLanguage()
50
+ // IsMaybeRightToLeftLanguage()
51
+ // IsSameLanguage()
52
+ // IsScriptRequiringLongerSnippets()
53
+ // *******************************************
54
+
55
+ // IsValidLanguage
56
+ // ===============
57
+ //
58
+ // Function to check if the input is within range of the Language enum. If
59
+ // IsValidLanguage(lang) returns true, it is safe to call
60
+ // static_cast<Language>(lang).
61
+ //
62
+ inline bool IsValidLanguage(int lang) {
63
+ return ((lang >= 0) && (lang < kNumLanguages));
64
+ }
65
+
66
+ // Return true if the language is "unknown". (This function was
67
+ // previously a macro, hence the spelling in all caps.)
68
+ //
69
+ inline bool IS_LANGUAGE_UNKNOWN(Language lang) {
70
+ return lang == TG_UNKNOWN_LANGUAGE || lang == UNKNOWN_LANGUAGE;
71
+ }
72
+
73
+ // IsCJKLanguage
74
+ // -------------
75
+ //
76
+ // This function returns true if the language is either Chinese
77
+ // (simplified or traditional), Japanese, or Korean.
78
+ bool IsCJKLanguage(Language lang);
79
+
80
+ // IsChineseLanguage
81
+ // -----------------
82
+ //
83
+ // This function returns true if the language is either Chinese
84
+ // (simplified or traditional)
85
+ bool IsChineseLanguage(Language lang);
86
+
87
+ // IsNorwegianLanguage
88
+ // --------------------
89
+ //
90
+ // This function returns true if the language is any of the Norwegian
91
+ // (regular or Nynorsk).
92
+ bool IsNorwegianLanguage(Language lang);
93
+
94
+ // IsPortugueseLanguage
95
+ // --------------------
96
+ //
97
+ // This function returns true if the language is any of the Portuguese
98
+ // languages (regular, Portugal or Brazil)
99
+ bool IsPortugueseLanguage(Language lang);
100
+
101
+ // IsSameLanguage
102
+ // --------------
103
+ //
104
+ // WARNING: This function provides only a simple test on the values of
105
+ // the two Language arguments. It returns false if either language is
106
+ // invalid. It returns true if the language arguments are equal, or
107
+ // if they are both Chinese languages, both Norwegian languages, or
108
+ // both Portuguese languages, as defined by IsChineseLanguage,
109
+ // IsNorwegianLanguage, and IsPortugueseLanguage. Otherwise it returns
110
+ // false.
111
+ bool IsSameLanguage(Language lang1, Language lang2);
112
+
113
+
114
+ // IsRightToLeftLanguage
115
+ // ---------------------
116
+ //
117
+ // This function returns true if the language is only written right-to-left
118
+ // (E.g., Hebrew, Arabic, Persian etc.)
119
+ //
120
+ // IMPORTANT NOTE: Technically we're talking about scripts, not languages.
121
+ // There are languages that can be written in more than one script.
122
+ // Examples:
123
+ // - Kurdish and Azeri ('AZERBAIJANI') can be written left-to-right in
124
+ // Latin or Cyrillic script, and right-to-left in Arabic script.
125
+ // - Sindhi and Punjabi are written in different scripts, depending on
126
+ // region and dialect.
127
+ // - Turkmen used an Arabic script historically, but not any more.
128
+ // - Pashto and Uyghur can use Arabic script, but use a Roman script
129
+ // on the Internet.
130
+ // - Kashmiri and Urdu are written either with Arabic or Devanagari script.
131
+ //
132
+ // This function only returns true for languages that are always, unequivocally
133
+ // written in right-to-left script.
134
+ //
135
+ // TODO(benjy): If we want to do anything special with multi-script languages
136
+ // we should create new 'languages' for each language+script, as we do for
137
+ // traditional vs. simplified Chinese. However most such languages are rare in
138
+ // use and even rarer on the web, so this is unlikely to be something we'll
139
+ // be concerned with for a while.
140
+ bool IsRightToLeftLanguage(Language lang);
141
+
142
+ // IsMaybeRightToLeftLanguage
143
+ // --------------------------
144
+ //
145
+ // This function returns true if the language may appear on the web in a
146
+ // right-to-left script (E.g., Hebrew, Arabic, Persian, Urdu, Kurdish, etc.)
147
+ //
148
+ // NOTE: See important notes under IsRightToLeftLanguage(...).
149
+ //
150
+ // This function returns true for languages that *may* appear on the web in a
151
+ // right-to-left script, even if they may also appear in a left-to-right
152
+ // script.
153
+ //
154
+ // This function should typically be used in cases where doing some work on
155
+ // left-to-right text would be OK (usually a no-op), and this function is used
156
+ // just to cut down on unnecessary work on regular, LTR text.
157
+ bool IsMaybeRightToLeftLanguage(Language lang);
158
+
159
+ // IsScriptRequiringLongerSnippets
160
+ // --------------------
161
+ //
162
+ // This function returns true if the script chracteristics require longer
163
+ // snippet length (Devanagari, Bengali, Gurmukhi,
164
+ // Gujarati, Oriya, Tamil, Telugu, Kannada, Malayalam).
165
+ // COMMENTED OUT TO REDUCE DEPENDENCIES ON GOOGLE3 CODE
166
+ // bool IsScriptRequiringLongerSnippets(UnicodeScript script);
167
+
168
+
169
+ // *******************************************
170
+ // LANGUAGE NAMES
171
+ //
172
+ // This interface defines a standard name for each valid Language,
173
+ // and a standard name for invalid languages. Some language names use all
174
+ // uppercase letters, but others use mixed case.
175
+ // LanguageName() [Language to name]
176
+ // LanguageEnumName() [language to enum name]
177
+ // LanguageFromName() [name to Language]
178
+ // default_language_name()
179
+ // invalid_language_name()
180
+ // *******************************************
181
+
182
+ // Given a Language, returns its standard name.
183
+ // Return invalid_language_name() if the language is invalid.
184
+ const char* LanguageName(Language lang);
185
+
186
+ // Given a Language, return the name of the enum constant for that
187
+ // language. In all but a few cases, this is the same as its standard
188
+ // name. For example, LanguageName(CHINESE) returns "Chinese", but
189
+ // LanguageEnumName(CHINESE) returns "CHINESE". This is intended for
190
+ // code that is generating C++ code, where the enum constant is more
191
+ // useful than its integer value. Return "NUM_LANGUAGES" if
192
+ // the language is invalid.
193
+ const char* LanguageEnumName(Language lang);
194
+
195
+ // The maximum length of a standard language name.
196
+ const int kMaxLanguageNameSize = 50;
197
+
198
+ // The standard name for the default language.
199
+ const char* default_language_name();
200
+
201
+ // The standard name for all invalid languages.
202
+ const char* invalid_language_name();
203
+
204
+ // If lang_name matches the standard name of a Language, using a
205
+ // case-insensitive comparison, set *language to that Language and
206
+ // return true.
207
+ // Otherwise, set *language to UNKNOWN_LANGUAGE and return false.
208
+ //
209
+ // For backwards compatibility, "HATIAN_CREOLE" is allowed as a name
210
+ // for HAITIAN_CREOLE, and "QUECHAU" is allowed as a name for QUECHUA.
211
+ // For compatibility with LanguageEnumName, "UNKNOWN_LANGUAGE" is allowed
212
+ // as a name for UNKNOWN_LANGUAGE (the return value is true in this case,
213
+ // as it is for "Unknown"), and "CHINESE_T" is allowed as a name for
214
+ // CHINESE_T (i.e., a synonym for "ChineseT").
215
+ //
216
+ // REQUIRES: language must not be NULL.
217
+ //
218
+ bool LanguageFromName(const char* lang_name, Language *language);
219
+
220
+
221
+
222
+ // *******************************************
223
+ // LANGUAGE CODES
224
+ //
225
+ // This interface defines a standard code for each valid language, and
226
+ // a standard code for invalid languages. These are derived from ISO codes,
227
+ // with some Google additions.
228
+ // LanguageCode()
229
+ // default_language_code()
230
+ // invalid_language_code()
231
+ // LanguageCodeWithDialects()
232
+ // LanguageCodeISO639_1()
233
+ // LanguageCodeISO639_2()
234
+ // *******************************************
235
+
236
+ // Given a Language, return its standard code. There are Google-specific codes:
237
+ // For CHINESE_T, return "zh-TW".
238
+ // For TG_UNKNOWN_LANGUAGE, return "ut".
239
+ // For UNKNOWN_LANGUAGE, return "un".
240
+ // For PORTUGUESE_P, return "pt-PT".
241
+ // For PORTUGUESE_B, return "pt-BR".
242
+ // For LIMBU, return "sit-NP".
243
+ // For CHEROKEE, return "chr".
244
+ // For SYRIAC, return "syr".
245
+ // Otherwise return the ISO 639-1 two-letter language code for lang.
246
+ // If lang is invalid, return invalid_language_code().
247
+ //
248
+ // NOTE: See the note below about the codes for Chinese languages.
249
+ //
250
+ const char* LanguageCode(Language lang);
251
+
252
+ // The maximum length of a language code.
253
+ const int kMaxLanguageCodeSize = 50;
254
+
255
+ // The standard code for the default language.
256
+ const char* default_language_code();
257
+
258
+ // The standard code for all invalid languages.
259
+ const char* invalid_language_code();
260
+
261
+
262
+ // --------------------------------------------
263
+ // NOTE: CHINESE LANGUAGE CODES
264
+ //
265
+ // There are three functions that return codes for Chinese languages.
266
+ // LanguageCode(lang) and LanguageCodeWithDialects(lang) are defined here.
267
+ // LanguageCode(lang, encoding) is defined in i18n/encodings.lang_enc.h.
268
+ // The following list shows the different results.
269
+ //
270
+ // LanguageCode(CHINESE) returns "zh"
271
+ // LanguageCode(CHINESE_T) returns "zh-TW".
272
+ //
273
+ // LanguageCodeWithDialects(CHINESE) returns "zh-CN".
274
+ // LanguageCodeWithDialects(CHINESE_T) returns "zh-TW".
275
+ //
276
+ // LanguageCode(CHINESE_T, <any encoding>) returns "zh-TW".
277
+ // LanguageCode(CHINESE, CHINESE_BIG5) returns "zh-TW".
278
+ // LanguageCode(CHINESE, <any other encoding>) returns "zh-CN".
279
+ //
280
+ // --------------------------------------------
281
+
282
+ // LanguageCodeWithDialects
283
+ // ------------------------
284
+ //
285
+ // If lang is CHINESE, return "zh-CN". Otherwise return LanguageCode(lang).
286
+ const char* LanguageCodeWithDialects(Language lang);
287
+
288
+ // LanguageCodeISO639_1
289
+ // --------------------
290
+ //
291
+ // Return the ISO 639-1 two-letter language code for lang.
292
+ // Return invalid_language_code() if lang is invalid or does not have
293
+ // an ISO 639-1 two-letter language code.
294
+ const char* LanguageCodeISO639_1(Language lang);
295
+
296
+ // LanguageCodeISO639_2
297
+ // --------------------
298
+ //
299
+ // Return the ISO 639-2 three-letter language for lang.
300
+ // Return invalid_language_code() if lang is invalid or does not have
301
+ // an ISO 639-2 three-letter language code.
302
+ const char* LanguageCodeISO639_2(Language lang);
303
+
304
+ // LanguageFromCode
305
+ // ----------------
306
+ //
307
+ // If lang_code matches the code for a Language, using a case-insensitive
308
+ // comparison, set *lang to that Language and return true.
309
+ // Otherwise, set *lang to UNKNOWN_LANGUAGE and return false.
310
+ //
311
+ // lang_code can be an ISO 639-1 (two-letter) code, an ISO 639-2
312
+ // (three-letter) code, or a Google-specific code (see LanguageCode).
313
+ //
314
+ // Certain language-code aliases are also allowed:
315
+ // For "zh-cn" and "zh_cn", set *lang to CHINESE.
316
+ // For "zh-tw" and "zh_tw", set *lang to CHINESE_T.
317
+ // For "he", set *lang to HEBREW.
318
+ // For "in", set *lang to INDONESIAN.
319
+ // For "ji", set *lang to YIDDISH.
320
+ // For "fil", set *lang to TAGALOG.
321
+ //
322
+ // REQUIRES: 'lang' must not be NULL.
323
+ bool LanguageFromCode(const char* lang_code, Language *language);
324
+
325
+
326
+ // LanguageFromCodeOrName
327
+ // ----------------------
328
+ //
329
+ // If lang_code_or_name is a language code or a language name.
330
+ // set *language to the corresponding Language and return true.
331
+ // Otherwise set *language to UNKNOWN_LANGUAGE and return false.
332
+ //
333
+ bool LanguageFromCodeOrName(const char* lang_code_or_name,
334
+ Language* language);
335
+
336
+ // LanguageNameFromCode
337
+ // --------------------
338
+ //
339
+ // If language_code is the code for a Language (see LanguageFromCode),
340
+ // return the standard name of that language (see LanguageName).
341
+ // Otherwise return invalid_language_name().
342
+ //
343
+ const char* LanguageNameFromCode(const char* language_code);
344
+
345
+
346
+ // Miscellany
347
+
348
+ // LanguageCodeToUnderscoreForm
349
+ // ----------------------------
350
+ //
351
+ // Given a language code, convert the dash "-" to underscore "_".
352
+ //
353
+ // Specifically, if result_length <= strlen(lang_code), set result[0]
354
+ // to '\0' and return false. Otherwise, copy lang_code to result,
355
+ // converting every dash to an underscore, converting every character
356
+ // before the first dash or underscore to lower case, and converting
357
+ // every character after the first dash or underscore to upper
358
+ // case. If there is no dash or underscore, convert the entire string
359
+ // to lower case.
360
+ //
361
+ // REQUIRES: 'lang_code' must not be NULL. 'result' must not be NULL.
362
+
363
+ bool LanguageCodeToUnderscoreForm(const char* lang_code,
364
+ char* result,
365
+ int result_length);
366
+
367
+ //
368
+ // AlwaysPutInExpectedRestrict
369
+ // ---------------------------
370
+ //
371
+ // For Web pages in certain top-level domains, Web Search always
372
+ // applies a "country restrict". If 'tld' matches one of those, using
373
+ // a case-SENSITIVE comparison, set *expected_language to the Language
374
+ // most commonly found in that top-level domain and return true.
375
+ // Otherwise, set *expected_language to UNKNOWN_LANGUAGE and return false.
376
+ bool AlwaysPutInExpectedRestrict(const char *tld, Language *expected_language);
377
+
378
+
379
+ #endif // LANGUAGES_PUBLIC_LANGUAGES_H_
@@ -0,0 +1,55 @@
1
+ #include <stdio.h>
2
+ #include <string.h>
3
+ #include "encodings/compact_lang_det/compact_lang_det.h"
4
+ #include "encodings/compact_lang_det/ext_lang_enc.h"
5
+ #include "encodings/compact_lang_det/unittest_data.h"
6
+ #include "encodings/proto/encodings.pb.h"
7
+
8
+ typedef struct {
9
+ const char *name;
10
+ const char *code;
11
+ bool reliable;
12
+ } RESULT;
13
+
14
+ extern "C" {
15
+ RESULT detectLanguageThunkInt(const char * src, bool is_plain_text) {
16
+ bool do_allow_extended_languages = true;
17
+ bool do_pick_summary_language = false;
18
+ bool do_remove_weak_matches = false;
19
+ bool is_reliable;
20
+ Language plus_one = UNKNOWN_LANGUAGE;
21
+ const char* tld_hint = NULL;
22
+ int encoding_hint = UNKNOWN_ENCODING;
23
+ Language language_hint = UNKNOWN_LANGUAGE;
24
+
25
+ double normalized_score3[3];
26
+ Language language3[3];
27
+ int percent3[3];
28
+ int text_bytes;
29
+
30
+ Language lang;
31
+ lang = CompactLangDet::DetectLanguage(0,
32
+ src, strlen(src),
33
+ is_plain_text,
34
+ do_allow_extended_languages,
35
+ do_pick_summary_language,
36
+ do_remove_weak_matches,
37
+ tld_hint,
38
+ encoding_hint,
39
+ language_hint,
40
+ language3,
41
+ percent3,
42
+ normalized_score3,
43
+ &text_bytes,
44
+ &is_reliable);
45
+
46
+ RESULT res;
47
+ res.name = LanguageName(lang);
48
+ res.code = ExtLanguageCode(lang);
49
+ res.reliable = is_reliable;
50
+ return res;
51
+ }
52
+ }
53
+
54
+ int main(int argc, char **argv) {
55
+ }
@@ -0,0 +1,21 @@
1
+ require "cld/version"
2
+ require "ffi"
3
+
4
+ module CLD
5
+ extend FFI::Library
6
+
7
+ def self.detect_language(text, is_plain_text=true)
8
+ result = detect_language_ext(text.to_s, is_plain_text)
9
+ Hash[ result.members.map {|member| [member.to_sym, result[member]]} ]
10
+ end
11
+
12
+ private
13
+
14
+ class ReturnValue < FFI::Struct
15
+ layout :name, :string, :code, :string, :reliable, :bool
16
+ end
17
+
18
+ GEM_ROOT = File.expand_path("../../", __FILE__)
19
+ ffi_lib "#{GEM_ROOT}/ext/cld/lib/cld.so"
20
+ attach_function "detect_language_ext","detectLanguageThunkInt", [:buffer_in, :bool], ReturnValue.by_value
21
+ end