LIMA
Libre Multilingual Analyzer — C++ API
Loading...
Searching...
No Matches
DeepTokenizerBase.cpp
Go to the documentation of this file.
1// Copyright 2002-2021 CEA LIST
2// SPDX-FileCopyrightText: 2022 CEA LIST <gael.de-chalendar@cea.fr>
3//
4// SPDX-License-Identifier: MIT
5
6#include "DeepTokenizerBase.h"
7
8#include <QtCore/QRegularExpression>
9
11
12using namespace std;
14using namespace Lima::Common::Misc;
15
16namespace Lima
17{
18namespace LinguisticProcessing
19{
20
21// set default key in status according to other elements in status
23{
24 string defaultKey;
25 switch (curSettings.getStatus()) {
26 case T_ALPHA : {
27 switch (curSettings.getAlphaCapital()) {
28 case T_CAPITAL : defaultKey = "t_capital" ; break;
29 case T_SMALL : defaultKey = "t_small" ; break;
30 case T_CAPITAL_1ST : defaultKey = "t_capital_1st" ; break;
31 case T_ACRONYM : defaultKey = "t_acronym" ; break;
32 case T_CAPITAL_SMALL : defaultKey = "t_capital_small"; break;
33 case T_ABBREV : defaultKey = "t_abbrev" ; break;
34 default : break;
35 }
36 switch (curSettings.getAlphaRoman()) { // Roman supersedes Cardinal
37 case T_CARDINAL_ROMAN : defaultKey = "t_cardinal_roman"; break;
38 case T_ORDINAL_ROMAN : defaultKey = "t_ordinal_roman" ; break;
39 case T_NOT_ROMAN : defaultKey = "t_not_roman" ; break;
40 default : break;
41 }
42 if (curSettings.isAlphaHyphen()) {
43 //no change
44 //defaultKey = "t_alpha_hyphen";
45 }
46 if (curSettings.isAlphaPossessive()) {
47 defaultKey = "t_alpha_possessive";
48 }
49 break;
50 } // end T_ALPHA
51 case T_NUMERIC : {
52 switch (curSettings.getNumeric()) {
53 case T_INTEGER : defaultKey = "t_integer" ; break;
54 case T_COMMA_NUMBER : defaultKey = "t_comma_number" ; break;
55 case T_DOT_NUMBER : defaultKey = "t_dot_number" ; break;
56 case T_FRACTION : defaultKey = "t_fraction" ; break;
57 case T_ORDINAL_INTEGER : defaultKey = "t_ordinal_integer"; break;
58 default: break;
59 }
60 break;
61 }
62 case T_ALPHANUMERIC : defaultKey = "t_alphanumeric" ; break;
63 case T_PATTERN : defaultKey = "t_pattern" ; break;
64 case T_WORD_BRK : defaultKey = "t_word_brk" ; break;
65 case T_SENTENCE_BRK : defaultKey = "t_sentence_brk" ; break;
66 case T_PARAGRAPH_BRK: defaultKey = "t_paragraph_brk" ; break;
67 default: defaultKey = "t_fallback";
68 }
69// #ifdef DEBUG_LP
70// TOKENIZERLOGINIT;
71// LDEBUG << "CppUppsalaTokenizerPrivate::computeDefaultStatus" << defaultKey;
72// #endif
73 curSettings.setDefaultKey(utf8stdstring2limastring(defaultKey));
74}
75
76// set default key in status according to other elements in status
78{
79// #ifdef DEBUG_LP
80// TOKENIZERLOGINIT;
81// LDEBUG << "CppUppsalaTokenizerPrivate::computeDefaultStatus"
82// << token.stringForm();
83// #endif
84 static QRegularExpression reCapital("^[[:upper:]]+$", QRegularExpression::UseUnicodePropertiesOption);
85 static QRegularExpression reSmall("^[[:lower:]]+$", QRegularExpression::UseUnicodePropertiesOption);
86 static QRegularExpression reCapital1st("^[[:upper:]]\\w+$", QRegularExpression::UseUnicodePropertiesOption);
87 static QRegularExpression reAcronym("^([[:upper:]]\\.)+$", QRegularExpression::UseUnicodePropertiesOption);
88 static QRegularExpression reCapitalSmall("^([[:upper:][:lower:]])+$", QRegularExpression::UseUnicodePropertiesOption);
89 static QRegularExpression reAbbrev("^\\w+\\.$", QRegularExpression::UseUnicodePropertiesOption);
90 static QRegularExpression reTwitter("^[@#]\\w+$", QRegularExpression::UseUnicodePropertiesOption);
91 static QRegularExpression reAlphaHyphen("^\\w+[\\-]\\w+$", QRegularExpression::UseUnicodePropertiesOption);
92
93 // t_cardinal_roman
94 static QRegularExpression reCardinalRoman("^(?=[MDCLXVI])M*(C[MD]|D?C{0,3})(X[CL]|L?X{0,3})(I[XV]|V?I{0,3})$");
95 // t_ordinal_roman
96 static QRegularExpression reOrdinalRoman("^(?=[MDCLXVI])M*(C[MD]|D?C{0,3})(X[CL]|L?X{0,3})(I[XV]|V?I{0,3})(st|nd|d|th|er|ème)$");
97 // t_integer
98 static QRegularExpression reInteger("^\\d+$");
99 // t_comma_number
100 static QRegularExpression reCommaNumber("^\\d+,\\d$");
101 // t_dot_number
102 static QRegularExpression reDotNumber("^\\d\\.\\d$");
103 // t_fraction
104 static QRegularExpression reFraction("^\\d([.,]\\d+)?/\\d([.,]\\d+)?$");
105 // t_ordinal_integer
106 static QRegularExpression reOrdinalInteger("^\\d+(st|nd|d|th|er|ème)$");
107 // t_alphanumeric
108 static QRegularExpression reAlphanumeric("^[\\d[:lower:][:upper:]]+$", QRegularExpression::UseUnicodePropertiesOption);
109 static QRegularExpression reSentenceBreak("^[;.!?]$");
110
111 TStatus curSettings;
112 if (reCapital.match(token.stringForm()).hasMatch())
113 {
114// #ifdef DEBUG_LP
115// LDEBUG << "CppUppsalaTokenizerPrivate::computeDefaultStatus t_capital";
116// #endif
117 curSettings.setDefaultKey(QString::fromUtf8("t_capital"));
118 }
119 else if (reSmall.match(token.stringForm()).hasMatch())
120 {
121// #ifdef DEBUG_LP
122// LDEBUG << "CppUppsalaTokenizerPrivate::computeDefaultStatus t_small";
123// #endif
124 curSettings.setDefaultKey(QString::fromUtf8("t_small"));
125 }
126 else if (reCapital1st.match(token.stringForm()).hasMatch())
127 {
128// #ifdef DEBUG_LP
129// LDEBUG << "CppUppsalaTokenizerPrivate::computeDefaultStatus t_capital_1st";
130// #endif
131 curSettings.setDefaultKey(QString::fromUtf8("t_capital_1st"));
132 }
133 else if (reAcronym.match(token.stringForm()).hasMatch())
134 {
135// #ifdef DEBUG_LP
136// LDEBUG << "CppUppsalaTokenizerPrivate::computeDefaultStatus t_acronym";
137// #endif
138 curSettings.setDefaultKey(QString::fromUtf8("t_acronym"));
139 }
140 else if (reCapitalSmall.match(token.stringForm()).hasMatch())
141 {
142// #ifdef DEBUG_LP
143// LDEBUG << "CppUppsalaTokenizerPrivate::computeDefaultStatus t_capital_small";
144// #endif
145 curSettings.setDefaultKey(QString::fromUtf8("t_capital_small"));
146 }
147 else if (reAbbrev.match(token.stringForm()).hasMatch())
148 {
149// #ifdef DEBUG_LP
150// LDEBUG << "CppUppsalaTokenizerPrivate::computeDefaultStatus t_abbrev";
151// #endif
152 curSettings.setDefaultKey(QString::fromUtf8("t_abbrev"));
153 }
154 else if (reTwitter.match(token.stringForm()).hasMatch())
155 {
156// #ifdef DEBUG_LP
157// LDEBUG << "CppUppsalaTokenizerPrivate::computeDefaultStatus t_twitter";
158// #endif
159 curSettings.setDefaultKey(QString::fromUtf8("t_twitter"));
160 }
161 else if (reCardinalRoman.match(token.stringForm()).hasMatch())
162 {
163// #ifdef DEBUG_LP
164// LDEBUG << "CppUppsalaTokenizerPrivate::computeDefaultStatus t_cardinal_roman";
165// #endif
166 curSettings.setDefaultKey(QString::fromUtf8("t_cardinal_roman"));
167 }
168 else if (reOrdinalRoman.match(token.stringForm()).hasMatch())
169 {
170// #ifdef DEBUG_LP
171// LDEBUG << "CppUppsalaTokenizerPrivate::computeDefaultStatus t_ordinal_roman";
172// #endif
173 curSettings.setDefaultKey(QString::fromUtf8("t_ordinal_roman"));
174 }
175 else if (reInteger.match(token.stringForm()).hasMatch())
176 {
177// #ifdef DEBUG_LP
178// LDEBUG << "CppUppsalaTokenizerPrivate::computeDefaultStatus t_integer";
179// #endif
180 curSettings.setDefaultKey(QString::fromUtf8("t_integer"));
181 }
182 else if (reCommaNumber.match(token.stringForm()).hasMatch())
183 {
184// #ifdef DEBUG_LP
185// LDEBUG << "CppUppsalaTokenizerPrivate::computeDefaultStatus t_comma_number";
186// #endif
187 curSettings.setDefaultKey(QString::fromUtf8("t_comma_number"));
188 }
189 else if (reDotNumber.match(token.stringForm()).hasMatch())
190 {
191// #ifdef DEBUG_LP
192// LDEBUG << "CppUppsalaTokenizerPrivate::computeDefaultStatus t_dot_number";
193// #endif
194 curSettings.setDefaultKey(QString::fromUtf8("t_dot_number"));
195 }
196 else if (reFraction.match(token.stringForm()).hasMatch())
197 {
198// #ifdef DEBUG_LP
199// LDEBUG << "CppUppsalaTokenizerPrivate::computeDefaultStatus t_fraction";
200// #endif
201 curSettings.setDefaultKey(QString::fromUtf8("t_fraction"));
202 }
203 else if (reOrdinalInteger.match(token.stringForm()).hasMatch())
204 {
205// #ifdef DEBUG_LP
206// LDEBUG << "CppUppsalaTokenizerPrivate::computeDefaultStatus t_ordinal_integer";
207// #endif
208 curSettings.setDefaultKey(QString::fromUtf8("t_ordinal_integer"));
209 }
210 else if (reAlphanumeric.match(token.stringForm()).hasMatch())
211 {
212// #ifdef DEBUG_LP
213// LDEBUG << "CppUppsalaTokenizerPrivate::computeDefaultStatus t_alphanumeric";
214// #endif
215 curSettings.setDefaultKey(QString::fromUtf8("t_alphanumeric"));
216 }
217 else if (reAlphaHyphen.match(token.stringForm()).hasMatch())
218 {
219 curSettings.setDefaultKey(QString::fromUtf8("t_alpha_hyphen"));
220 curSettings.setAlphaHyphen(true);
221 }
222 else if (reSentenceBreak.match(token.stringForm()).hasMatch())
223 {
224// #ifdef DEBUG_LP
225// LDEBUG << "CppUppsalaTokenizerPrivate::computeDefaultStatus t_sentence_brk";
226// #endif
227 curSettings.setDefaultKey(QString::fromUtf8("t_sentence_brk"));
228 }
229 else // if (reSmall.match(token.stringForm()).hasMatch())
230 {
231// #ifdef DEBUG_LP
232// LDEBUG << "CppUppsalaTokenizerPrivate::computeDefaultStatus t_word_brk (default)";
233// #endif
234 curSettings.setDefaultKey(QString::fromUtf8("t_word_brk"));
235 }
236
237 /*
238 // t_not_roman
239 static QRegularExpression reNotRoman("^$");
240 // t_alpha_concat_abbrev
241 static QRegularExpression reAlphConcatAbbrev("^$");
242 // t_pattern
243 static QRegularExpression rePattern("^$");
244 // t_word_brk
245 static QRegularExpression reWordBreak("^$");
246 // t_sentence_brk
247 static QRegularExpression reSentenceBreak("^$");
248 // t_paragraph_brk
249 static QRegularExpression reParagraphBreak("^$");
250 */
251
252 token.setStatus(curSettings);
253}
254
255} // namespace LinguisticProcessing
256} // namespace Lima
virtual void computeDefaultStatus(LinguisticAnalysisStructure::TStatus &curSettings)
void setDefaultKey(const Lima::LimaString &defaultKey)
Definition TStatus.cpp:325
void setStatus(const TStatus &status)
Set the TStatus of a token.
Definition Token.h:100
LimaString utf8stdstring2limastring(const std::string &src)
NAUTITIA.
STL namespace.