uchardet/src/LangModels/LangSloveneModel.cpp
Jehan f8752f2b56 src, script: add concept of alphabet_mapping in language models.
This allows to handle cases where some characters are actually
alternative/variants of another. For instance, a same word can be
written with both variants, while both are considered correct and
equivalent. Browsing a bit Slovenian Wikipedia, it looks like they only
use them for titles there.

I use this the first time on characters with diacritics in Slovene.
Indeed these are so rarely used that they would hardly show in the stats
and worse, any sequence using these in tested text would likely show as
negative sequences hence drop the confidence in Slovenian. As a
consequence, various Slovene text would show up as Slovak as it's close
enough and contains the same character with diacritics in a common way.
2021-03-21 15:54:24 +01:00

289 lines
13 KiB
C++

/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Communicator client code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "../nsSBCharSetProber.h"
#include "../nsLanguageDetector.h"
/********* Language model for: Slovene *********/
/**
* Generated by BuildLangModel.py
* On: 2021-03-21 14:41:34.895906
**/
/* Character Mapping Table:
* ILL: illegal character.
* CTR: control character specific to the charset.
* RET: carriage/return.
* SYM: symbol (punctuation) that does not belong to word.
* NUM: 0 - 9.
*
* Other characters are ordered by probabilities
* (0 is the most common character in the language).
*
* Orders are generic to a language. So the codepoint with order X in
* CHARSET1 maps to the same character as the codepoint with the same
* order X in CHARSET2 for the same language.
* As such, it is possible to get missing order. For instance the
* ligature of 'o' and 'e' exists in ISO-8859-15 but not in ISO-8859-1
* even though they are both used for French. Same for the euro sign.
*/
static const unsigned char Iso_8859_2_CharToOrderMap[] =
{
CTR,CTR,CTR,CTR,CTR,CTR,CTR,CTR,CTR,CTR,RET,CTR,CTR,RET,CTR,CTR, /* 0X */
CTR,CTR,CTR,CTR,CTR,CTR,CTR,CTR,CTR,CTR,CTR,CTR,CTR,CTR,CTR,CTR, /* 1X */
SYM,SYM,SYM,SYM,SYM,SYM,SYM,SYM,SYM,SYM,SYM,SYM,SYM,SYM,SYM,SYM, /* 2X */
NUM,NUM,NUM,NUM,NUM,NUM,NUM,NUM,NUM,NUM,SYM,SYM,SYM,SYM,SYM,SYM, /* 3X */
SYM, 2, 16, 22, 13, 1, 24, 18, 21, 3, 6, 11, 5, 12, 4, 0, /* 4X */
14, 30, 7, 8, 9, 15, 10, 26, 25, 27, 17,SYM,SYM,SYM,SYM,SYM, /* 5X */
SYM, 2, 16, 22, 13, 1, 24, 18, 21, 3, 6, 11, 5, 12, 4, 0, /* 6X */
14, 30, 7, 8, 9, 15, 10, 26, 25, 27, 17,SYM,SYM,SYM,SYM,CTR, /* 7X */
CTR,CTR,CTR,CTR,CTR,CTR,CTR,CTR,CTR,CTR,CTR,CTR,CTR,CTR,CTR,CTR, /* 8X */
CTR,CTR,CTR,CTR,CTR,CTR,CTR,CTR,CTR,CTR,CTR,CTR,CTR,CTR,CTR,CTR, /* 9X */
SYM, 33,SYM, 34,SYM, 35, 36,SYM,SYM, 20, 37, 38, 39,SYM, 23, 40, /* AX */
SYM, 41,SYM, 42,SYM, 43, 44,SYM,SYM, 20, 45, 46, 47,SYM, 23, 48, /* BX */
7, 2, 49, 50, 51, 52, 53, 54, 19, 1, 55, 56, 57, 3, 58, 59, /* CX */
60, 61, 62, 0, 0, 63, 29,SYM, 31, 64, 15, 65, 28, 32, 66, 67, /* DX */
7, 2, 68, 69, 70, 71, 72, 73, 19, 1, 74, 75, 76, 3, 77, 78, /* EX */
79, 80, 81, 0, 0, 82, 29,SYM, 31, 83, 15, 84, 28, 32, 85,SYM, /* FX */
};
/*X0 X1 X2 X3 X4 X5 X6 X7 X8 X9 XA XB XC XD XE XF */
static const unsigned char Iso_8859_16_CharToOrderMap[] =
{
CTR,CTR,CTR,CTR,CTR,CTR,CTR,CTR,CTR,CTR,RET,CTR,CTR,RET,CTR,CTR, /* 0X */
CTR,CTR,CTR,CTR,CTR,CTR,CTR,CTR,CTR,CTR,CTR,CTR,CTR,CTR,CTR,CTR, /* 1X */
SYM,SYM,SYM,SYM,SYM,SYM,SYM,SYM,SYM,SYM,SYM,SYM,SYM,SYM,SYM,SYM, /* 2X */
NUM,NUM,NUM,NUM,NUM,NUM,NUM,NUM,NUM,NUM,SYM,SYM,SYM,SYM,SYM,SYM, /* 3X */
SYM, 2, 16, 22, 13, 1, 24, 18, 21, 3, 6, 11, 5, 12, 4, 0, /* 4X */
14, 30, 7, 8, 9, 15, 10, 26, 25, 27, 17,SYM,SYM,SYM,SYM,SYM, /* 5X */
SYM, 2, 16, 22, 13, 1, 24, 18, 21, 3, 6, 11, 5, 12, 4, 0, /* 6X */
14, 30, 7, 8, 9, 15, 10, 26, 25, 27, 17,SYM,SYM,SYM,SYM,CTR, /* 7X */
CTR,CTR,CTR,CTR,CTR,CTR,CTR,CTR,CTR,CTR,CTR,CTR,CTR,CTR,CTR,CTR, /* 8X */
CTR,CTR,CTR,CTR,CTR,CTR,CTR,CTR,CTR,CTR,CTR,CTR,CTR,CTR,CTR,CTR, /* 9X */
SYM, 86, 87, 88,SYM,SYM, 20,SYM, 20,SYM, 89,SYM, 90,SYM, 91, 92, /* AX */
SYM,SYM, 19, 93, 23,SYM,SYM,SYM, 23, 19, 94,SYM, 95, 96, 97, 98, /* BX */
99, 2,100,101,102,103,104,105, 1, 1, 1,106, 3, 3,107,108, /* CX */
109,110, 0, 0, 0,111, 29,112,113, 15, 15,114, 28,115,116,117, /* DX */
118, 2,119,120,121,122,123,124, 1, 1, 1,125, 3, 3,126,127, /* EX */
128,129, 0, 0, 0,130, 29,131,132, 15, 15,133, 28,134,135,136, /* FX */
};
/*X0 X1 X2 X3 X4 X5 X6 X7 X8 X9 XA XB XC XD XE XF */
static const unsigned char Windows_1250_CharToOrderMap[] =
{
CTR,CTR,CTR,CTR,CTR,CTR,CTR,CTR,CTR,CTR,RET,CTR,CTR,RET,CTR,CTR, /* 0X */
CTR,CTR,CTR,CTR,CTR,CTR,CTR,CTR,CTR,CTR,CTR,CTR,CTR,CTR,CTR,CTR, /* 1X */
SYM,SYM,SYM,SYM,SYM,SYM,SYM,SYM,SYM,SYM,SYM,SYM,SYM,SYM,SYM,SYM, /* 2X */
NUM,NUM,NUM,NUM,NUM,NUM,NUM,NUM,NUM,NUM,SYM,SYM,SYM,SYM,SYM,SYM, /* 3X */
SYM, 2, 16, 22, 13, 1, 24, 18, 21, 3, 6, 11, 5, 12, 4, 0, /* 4X */
14, 30, 7, 8, 9, 15, 10, 26, 25, 27, 17,SYM,SYM,SYM,SYM,SYM, /* 5X */
SYM, 2, 16, 22, 13, 1, 24, 18, 21, 3, 6, 11, 5, 12, 4, 0, /* 6X */
14, 30, 7, 8, 9, 15, 10, 26, 25, 27, 17,SYM,SYM,SYM,SYM,CTR, /* 7X */
SYM,ILL,SYM,ILL,SYM,SYM,SYM,SYM,ILL,SYM, 20,SYM,137,138, 23,139, /* 8X */
ILL,SYM,SYM,SYM,SYM,SYM,SYM,SYM,ILL,SYM, 20,SYM,140,141, 23,142, /* 9X */
SYM,SYM,SYM,143,SYM,144,SYM,SYM,SYM,SYM,145,SYM,SYM,SYM,SYM,146, /* AX */
SYM,SYM,SYM,147,SYM,SYM,SYM,SYM,SYM,148,149,SYM,150,SYM,151,152, /* BX */
7, 2,153,154,155,156,157,158, 19, 1,159,160,161, 3,162,163, /* CX */
164,165,166, 0, 0,167, 29,SYM, 31,168, 15,169, 28, 32,170,171, /* DX */
7, 2,172,173,174,175,176,177, 19, 1,178,179,180, 3,181,182, /* EX */
183,184,185, 0, 0,186, 29,SYM, 31,187, 15,188, 28, 32,189,SYM, /* FX */
};
/*X0 X1 X2 X3 X4 X5 X6 X7 X8 X9 XA XB XC XD XE XF */
static const unsigned char Ibm852_CharToOrderMap[] =
{
CTR,CTR,CTR,CTR,CTR,CTR,CTR,CTR,CTR,CTR,RET,CTR,CTR,RET,CTR,CTR, /* 0X */
CTR,CTR,CTR,CTR,CTR,CTR,CTR,CTR,CTR,CTR,CTR,CTR,CTR,CTR,CTR,CTR, /* 1X */
SYM,SYM,SYM,SYM,SYM,SYM,SYM,SYM,SYM,SYM,SYM,SYM,SYM,SYM,SYM,SYM, /* 2X */
NUM,NUM,NUM,NUM,NUM,NUM,NUM,NUM,NUM,NUM,SYM,SYM,SYM,SYM,SYM,SYM, /* 3X */
SYM, 2, 16, 22, 13, 1, 24, 18, 21, 3, 6, 11, 5, 12, 4, 0, /* 4X */
14, 30, 7, 8, 9, 15, 10, 26, 25, 27, 17,SYM,SYM,SYM,SYM,SYM, /* 5X */
SYM, 2, 16, 22, 13, 1, 24, 18, 21, 3, 6, 11, 5, 12, 4, 0, /* 6X */
14, 30, 7, 8, 9, 15, 10, 26, 25, 27, 17,SYM,SYM,SYM,SYM,CTR, /* 7X */
190, 28, 1,191,192,193,194,195,196,197,198,199,200,201,202,203, /* 8X */
1,204,205, 0, 29,206,207,208,209, 29, 28,210,211,212,SYM, 19, /* 9X */
2, 3, 0, 15,213,214, 23, 23,215,216,SYM,217, 19,218,SYM,SYM, /* AX */
SYM,SYM,SYM,SYM,SYM, 2,219,220,221,SYM,SYM,SYM,SYM,222,223,SYM, /* BX */
SYM,SYM,SYM,SYM,SYM,SYM,224,225,SYM,SYM,SYM,SYM,SYM,SYM,SYM,SYM, /* CX */
226,227,228,229,230,231, 3,232,233,SYM,SYM,SYM,SYM,234,235,SYM, /* DX */
0,236, 0,237,238,239, 20, 20, 7, 15, 7,240, 32, 32,241,SYM, /* EX */
SYM,SYM,SYM,SYM,SYM,SYM,SYM,SYM,SYM,SYM,SYM,242, 31, 31,SYM,SYM, /* FX */
};
/*X0 X1 X2 X3 X4 X5 X6 X7 X8 X9 XA XB XC XD XE XF */
static const unsigned char Mac_Centraleurope_CharToOrderMap[] =
{
CTR,CTR,CTR,CTR,CTR,CTR,CTR,CTR,CTR,CTR,RET,CTR,CTR,RET,CTR,CTR, /* 0X */
CTR,CTR,CTR,CTR,CTR,CTR,CTR,CTR,CTR,CTR,CTR,CTR,CTR,CTR,CTR,CTR, /* 1X */
SYM,SYM,SYM,SYM,SYM,SYM,SYM,SYM,SYM,SYM,SYM,SYM,SYM,SYM,SYM,SYM, /* 2X */
NUM,NUM,NUM,NUM,NUM,NUM,NUM,NUM,NUM,NUM,SYM,SYM,SYM,SYM,SYM,SYM, /* 3X */
SYM, 2, 16, 22, 13, 1, 24, 18, 21, 3, 6, 11, 5, 12, 4, 0, /* 4X */
14, 30, 7, 8, 9, 15, 10, 26, 25, 27, 17,SYM,SYM,SYM,SYM,SYM, /* 5X */
SYM, 2, 16, 22, 13, 1, 24, 18, 21, 3, 6, 11, 5, 12, 4, 0, /* 6X */
14, 30, 7, 8, 9, 15, 10, 26, 25, 27, 17,SYM,SYM,SYM,SYM,CTR, /* 7X */
243,244,245, 1,246, 29, 28, 2,247, 19,248, 19,249,249, 1,249, /* 8X */
249,249, 3,249,249,249,249, 0,249, 0, 29,249, 15,249,249, 28, /* 9X */
SYM,SYM,249,SYM,SYM,SYM,SYM,249,SYM,SYM,SYM,249,SYM,SYM,249,249, /* AX */
249,249,SYM,SYM,249,249,SYM,SYM,249,249,249,249,249,249,249,249, /* BX */
249,249,SYM,SYM,249,249,SYM,SYM,SYM,SYM,SYM,249,249,249,249,249, /* CX */
SYM,SYM,SYM,SYM,SYM,SYM,SYM,SYM,249, 7, 7, 31,SYM,SYM, 31,249, /* DX */
249, 20,SYM,SYM, 20,249,249, 2,249,249, 3, 23, 23,249, 0, 0, /* EX */
249,249, 15,249,249,249,249,249, 32, 32,249,249,249,249,249,SYM, /* FX */
};
/*X0 X1 X2 X3 X4 X5 X6 X7 X8 X9 XA XB XC XD XE XF */
static const int Unicode_Char_size = 81;
static const unsigned int Unicode_CharOrder[] =
{
32, 0, 65, 2, 66, 16, 67, 22, 68, 13, 69, 1, 70, 24, 71, 18,
72, 21, 73, 3, 74, 6, 75, 11, 76, 5, 77, 12, 78, 4, 79, 0,
80, 14, 82, 7, 83, 8, 84, 9, 85, 15, 86, 10, 90, 17, 97, 2,
98, 16, 99, 22, 100, 13, 101, 1, 102, 24, 103, 18, 104, 21, 105, 3,
106, 6, 107, 11, 108, 5, 109, 12, 110, 4, 111, 0, 112, 14, 114, 7,
115, 8, 116, 9, 117, 15, 118, 10, 122, 17, 225, 2, 232, 1, 233, 1,
234, 1, 236, 3, 237, 3, 242, 0, 243, 0, 244, 0, 249, 15, 250, 15,
268, 19, 269, 19, 341, 7, 352, 20, 353, 20, 381, 23, 382, 23, 513, 2,
515, 2, 517, 1, 519, 1, 521, 3, 523, 3, 525, 0, 527, 0, 531, 7,
533, 15, 535, 15, 601, 1, 768, 1, 769, 0, 783, 1, 785, 0,7865, 1,
7885, 0,
};
/* Model Table:
* Total considered sequences: 480 / 625
* - Positive sequences: first 360 (0.9950453499390822)
* - Probable sequences: next 83 (443-360) (0.00397996480303231)
* - Neutral sequences: last 182 (0.0009746852578854659)
* - Negative sequences: 145 (off-ratio)
* Negative sequences: TODO
*/
static const PRUint8 SloveneLangModel[] =
{
3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,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0,3,0,0,2,0,0,
3,3,3,3,3,2,0,3,0,2,0,2,2,2,0,3,0,0,0,0,0,0,0,0,0,
3,3,3,3,0,2,0,0,0,0,0,1,0,0,0,2,0,0,0,0,0,3,0,0,2,
3,3,3,3,3,0,3,0,0,0,0,0,0,0,0,3,3,0,0,0,0,0,0,0,0,
3,3,3,3,0,0,0,3,3,1,0,0,0,0,0,2,2,0,0,0,0,0,0,0,0,
};
const SequenceModel Iso_8859_2SloveneModel =
{
Iso_8859_2_CharToOrderMap,
SloveneLangModel,
25,
(float)0.9990253147421145,
PR_FALSE,
"ISO-8859-2",
"sl"
};
const SequenceModel Iso_8859_16SloveneModel =
{
Iso_8859_16_CharToOrderMap,
SloveneLangModel,
25,
(float)0.9990253147421145,
PR_FALSE,
"ISO-8859-16",
"sl"
};
const SequenceModel Windows_1250SloveneModel =
{
Windows_1250_CharToOrderMap,
SloveneLangModel,
25,
(float)0.9990253147421145,
PR_FALSE,
"WINDOWS-1250",
"sl"
};
const SequenceModel Ibm852SloveneModel =
{
Ibm852_CharToOrderMap,
SloveneLangModel,
25,
(float)0.9990253147421145,
PR_FALSE,
"IBM852",
"sl"
};
const SequenceModel Mac_CentraleuropeSloveneModel =
{
Mac_Centraleurope_CharToOrderMap,
SloveneLangModel,
25,
(float)0.9990253147421145,
PR_FALSE,
"MAC-CENTRALEUROPE",
"sl"
};
const LanguageModel SloveneModel =
{
"sl",
Unicode_CharOrder,
81,
SloveneLangModel,
25,
(float)0.9993179075502389,
};