uchardet/src/LangModels/LangItalianModel.cpp
Jehan 9518f4d7a2 Rebuild a bunch of language models.
Adding generic language model (see coming commit), which uses the same
data as specific single-byte encoding statistics model, except that it
applies it to unicode code points.
For this to work, instead of the CharToOrderMap which was mapping
directly from encoded byte (always 256 values) to order, now we add an
array of frequent characters, ordered by generic unicode code points to
the order of frequency (which can be used on the same sequence mapping
array).

This of course means that each prober where we will want to use these
generic models will have to implement their own byte to code point
decoder, as this is per-encoding logics anyway. This will come in a
subsequent commit.
2021-03-16 12:35:18 +01:00

295 lines
14 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: Italian *********/
/**
* Generated by BuildLangModel.py
* On: 2021-03-16 01:31:12.602629
**/
/* 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_1_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, 17, 9, 10, 1, 16, 14, 19, 0, 31, 26, 5, 13, 4, 3, /* 4X */
12, 20, 7, 8, 6, 11, 15, 28, 25, 27, 18,SYM,SYM,SYM,SYM,SYM, /* 5X */
SYM, 2, 17, 9, 10, 1, 16, 14, 19, 0, 31, 26, 5, 13, 4, 3, /* 6X */
12, 20, 7, 8, 6, 11, 15, 28, 25, 27, 18,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,SYM,SYM,SYM,SYM,SYM,SYM,SYM,SYM,SYM,SYM,SYM,SYM,SYM,SYM,SYM, /* AX */
SYM,SYM,SYM,SYM,SYM, 54,SYM,SYM,SYM,SYM,SYM,SYM,SYM,SYM,SYM,SYM, /* BX */
21, 37, 46, 38, 35, 55, 39, 41, 22, 30, 40, 45, 29, 36, 48, 56, /* CX */
57, 42, 23, 33, 49, 58, 32,SYM, 52, 24, 43, 59, 34, 60, 61, 44, /* DX */
21, 37, 46, 38, 35, 62, 39, 41, 22, 30, 40, 45, 29, 36, 48, 63, /* EX */
64, 42, 23, 33, 49, 65, 32,SYM, 52, 24, 43, 66, 34, 67, 68, 69, /* FX */
};
/*X0 X1 X2 X3 X4 X5 X6 X7 X8 X9 XA XB XC XD XE XF */
static const unsigned char Iso_8859_3_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, 17, 9, 10, 1, 16, 14, 19, 0, 31, 26, 5, 13, 4, 3, /* 4X */
12, 20, 7, 8, 6, 11, 15, 28, 25, 27, 18,SYM,SYM,SYM,SYM,SYM, /* 5X */
SYM, 2, 17, 9, 10, 1, 16, 14, 19, 0, 31, 26, 5, 13, 4, 3, /* 6X */
12, 20, 7, 8, 6, 11, 15, 28, 25, 27, 18,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, 70,SYM,SYM,SYM,ILL, 71,SYM,SYM, 72, 73, 53, 74,SYM,ILL, 50, /* AX */
SYM, 75,SYM,SYM,SYM,SYM, 76,SYM,SYM, 77, 78, 53, 79,SYM,ILL, 50, /* BX */
21, 37, 46,ILL, 35, 80, 81, 41, 22, 30, 40, 45, 29, 36, 48, 82, /* CX */
ILL, 42, 23, 33, 49, 83, 32,SYM, 84, 24, 43, 85, 34, 86, 87, 44, /* DX */
21, 37, 46,ILL, 35, 88, 89, 41, 22, 30, 40, 45, 29, 36, 48, 90, /* EX */
ILL, 42, 23, 33, 49, 91, 32,SYM, 92, 24, 43, 93, 34, 94, 95,SYM, /* FX */
};
/*X0 X1 X2 X3 X4 X5 X6 X7 X8 X9 XA XB XC XD XE XF */
static const unsigned char Iso_8859_9_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, 17, 9, 10, 1, 16, 14, 19, 0, 31, 26, 5, 13, 4, 3, /* 4X */
12, 20, 7, 8, 6, 11, 15, 28, 25, 27, 18,SYM,SYM,SYM,SYM,SYM, /* 5X */
SYM, 2, 17, 9, 10, 1, 16, 14, 19, 0, 31, 26, 5, 13, 4, 3, /* 6X */
12, 20, 7, 8, 6, 11, 15, 28, 25, 27, 18,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,SYM,SYM,SYM,SYM,SYM,SYM,SYM,SYM,SYM,SYM,SYM,SYM,SYM,SYM,SYM, /* AX */
SYM,SYM,SYM,SYM,SYM, 96,SYM,SYM,SYM,SYM,SYM,SYM,SYM,SYM,SYM,SYM, /* BX */
21, 37, 46, 38, 35, 97, 39, 41, 22, 30, 40, 45, 29, 36, 48, 98, /* CX */
53, 42, 23, 33, 49, 99, 32,SYM, 52, 24, 43,100, 34,101,102, 44, /* DX */
21, 37, 46, 38, 35,103, 39, 41, 22, 30, 40, 45, 29, 36, 48,104, /* EX */
53, 42, 23, 33, 49,105, 32,SYM, 52, 24, 43,106, 34,107,108,109, /* FX */
};
/*X0 X1 X2 X3 X4 X5 X6 X7 X8 X9 XA XB XC XD XE XF */
static const unsigned char Iso_8859_15_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, 17, 9, 10, 1, 16, 14, 19, 0, 31, 26, 5, 13, 4, 3, /* 4X */
12, 20, 7, 8, 6, 11, 15, 28, 25, 27, 18,SYM,SYM,SYM,SYM,SYM, /* 5X */
SYM, 2, 17, 9, 10, 1, 16, 14, 19, 0, 31, 26, 5, 13, 4, 3, /* 6X */
12, 20, 7, 8, 6, 11, 15, 28, 25, 27, 18,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,SYM,SYM,SYM,SYM,SYM, 51,SYM, 51,SYM,SYM,SYM,SYM,SYM,SYM,SYM, /* AX */
SYM,SYM,SYM,SYM,110,111,SYM,SYM,112,SYM,SYM,SYM, 47, 47,113,SYM, /* BX */
21, 37, 46, 38, 35,114, 39, 41, 22, 30, 40, 45, 29, 36, 48,115, /* CX */
116, 42, 23, 33, 49,117, 32,SYM, 52, 24, 43,118, 34,119,120, 44, /* DX */
21, 37, 46, 38, 35,121, 39, 41, 22, 30, 40, 45, 29, 36, 48,122, /* EX */
123, 42, 23, 33, 49,124, 32,SYM, 52, 24, 43,125, 34,126,127,128, /* FX */
};
/*X0 X1 X2 X3 X4 X5 X6 X7 X8 X9 XA XB XC XD XE XF */
static const unsigned char Windows_1252_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, 17, 9, 10, 1, 16, 14, 19, 0, 31, 26, 5, 13, 4, 3, /* 4X */
12, 20, 7, 8, 6, 11, 15, 28, 25, 27, 18,SYM,SYM,SYM,SYM,SYM, /* 5X */
SYM, 2, 17, 9, 10, 1, 16, 14, 19, 0, 31, 26, 5, 13, 4, 3, /* 6X */
12, 20, 7, 8, 6, 11, 15, 28, 25, 27, 18,SYM,SYM,SYM,SYM,CTR, /* 7X */
SYM,ILL,SYM,129,SYM,SYM,SYM,SYM,SYM,SYM, 51,SYM, 47,ILL,130,ILL, /* 8X */
ILL,SYM,SYM,SYM,SYM,SYM,SYM,SYM,SYM,SYM, 51,SYM, 47,ILL,131,132, /* 9X */
SYM,SYM,SYM,SYM,SYM,SYM,SYM,SYM,SYM,SYM,SYM,SYM,SYM,SYM,SYM,SYM, /* AX */
SYM,SYM,SYM,SYM,SYM,133,SYM,SYM,SYM,SYM,SYM,SYM,SYM,SYM,SYM,SYM, /* BX */
21, 37, 46, 38, 35,134, 39, 41, 22, 30, 40, 45, 29, 36, 48,135, /* CX */
136, 42, 23, 33, 49,137, 32,SYM, 52, 24, 43,138, 34,139,140, 44, /* DX */
21, 37, 46, 38, 35,141, 39, 41, 22, 30, 40, 45, 29, 36, 48,142, /* EX */
143, 42, 23, 33, 49,144, 32,SYM, 52, 24, 43,145, 34,146,147,148, /* FX */
};
/*X0 X1 X2 X3 X4 X5 X6 X7 X8 X9 XA XB XC XD XE XF */
static const int Unicode_Char_size = 68;
static const unsigned int Unicode_CharOrder[] =
{
65, 2, 66, 17, 67, 9, 68, 10, 69, 1, 70, 16, 71, 14, 72, 19,
73, 0, 74, 31, 75, 26, 76, 5, 77, 13, 78, 4, 79, 3, 80, 12,
81, 20, 82, 7, 83, 8, 84, 6, 85, 11, 86, 15, 87, 28, 88, 25,
89, 27, 90, 18, 97, 2, 98, 17, 99, 9, 100, 10, 101, 1,102, 16,
103, 14, 104, 19, 105, 0, 106, 31, 107, 26, 108, 5, 109, 13,110, 4,
111, 3, 112, 12, 113, 20, 114, 7, 115, 8, 116, 6, 117, 11,118, 15,
119, 28, 120, 25, 121, 27, 122, 18, 192, 21, 200, 22, 201, 30,204, 29,
210, 23, 211, 33, 214, 32, 217, 24, 224, 21, 232, 22, 233, 30,236, 29,
242, 23, 243, 33, 246, 32, 249, 24,
};
/* Model Table:
* Total sequences: 921
* First 512 sequences: 0.9992462827093448
* Next 512 sequences (512-1024): 0.0007537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3,0,0,0,0,0,
0,0,2,0,0,0,2,0,2,2,0,0,2,0,2,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
2,0,0,2,2,3,2,3,2,2,3,2,0,2,2,2,2,2,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,
3,3,3,3,0,0,0,2,0,2,0,3,2,2,0,0,2,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,
2,0,0,0,3,3,2,3,3,2,2,0,2,0,2,3,2,0,0,3,0,0,0,0,0,0,2,0,2,0,0,0,0,0,
2,0,2,0,3,0,0,2,2,2,0,0,2,2,0,2,0,2,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,
};
const SequenceModel Iso_8859_1ItalianModel =
{
Iso_8859_1_CharToOrderMap,
ItalianLangModel,
34,
(float)0.9992462827093448,
PR_TRUE,
"ISO-8859-1",
"it"
};
const SequenceModel Iso_8859_3ItalianModel =
{
Iso_8859_3_CharToOrderMap,
ItalianLangModel,
34,
(float)0.9992462827093448,
PR_TRUE,
"ISO-8859-3",
"it"
};
const SequenceModel Iso_8859_9ItalianModel =
{
Iso_8859_9_CharToOrderMap,
ItalianLangModel,
34,
(float)0.9992462827093448,
PR_TRUE,
"ISO-8859-9",
"it"
};
const SequenceModel Iso_8859_15ItalianModel =
{
Iso_8859_15_CharToOrderMap,
ItalianLangModel,
34,
(float)0.9992462827093448,
PR_TRUE,
"ISO-8859-15",
"it"
};
const SequenceModel Windows_1252ItalianModel =
{
Windows_1252_CharToOrderMap,
ItalianLangModel,
34,
(float)0.9992462827093448,
PR_TRUE,
"WINDOWS-1252",
"it"
};
const LanguageModel ItalianModel =
{
"it",
Unicode_CharOrder,
68,
ItalianLangModel,
34,
(float)0.9992462827093448,
};