LIMA
Libre Multilingual Analyzer — C++ API
Loading...
Searching...
No Matches
MorphoSyntacticData.cpp
Go to the documentation of this file.
1// Copyright 2002-2020 CEA LIST
2// SPDX-FileCopyrightText: 2022 CEA LIST <gael.de-chalendar@cea.fr>
3//
4// SPDX-License-Identifier: MIT
5
8
11
12#include <algorithm>
13
14using namespace Lima::Common::MediaticData;
15
16namespace Lima
17{
18
19namespace LinguisticProcessing
20{
21
22namespace LinguisticAnalysisStructure
23{
24
26{
27 return ((properties==le.properties) &&
29 (lemma==le.lemma) &&
31 (type==le.type));
32}
33
35{
37 if (lemma!=le.lemma) return lemma<le.lemma;
39 if (properties!=le.properties) return properties<le.properties;
40 return type<le.type;
41}
42
43
46
49
51 const Common::PropertyCode::PropertyAccessor& microAccessor,
52 const std::list<LinguisticCode>& microFilter)
53{
54 LinguisticCode micro;
55 for (auto it = cbegin(); it != cend(); it++)
56 {
57 auto tmp = microAccessor.readValue(it->properties);
58 if (micro != L_NONE)
59 {
60 if (micro != tmp)
61 {
62 return false;
63 }
64 }
65 else
66 {
67 micro = tmp;
68 }
69 bool found=false;
70 for (auto filterItr = microFilter.cbegin(); filterItr != microFilter.cend();
71 filterItr++)
72 {
73 if (tmp==*filterItr)
74 {
75 found=true;
76 break;
77 }
78 }
79 if (!found)
80 {
81 return false;
82 }
83 }
84 // if micro is 0, then there was no micros, return false
85 return micro!=L_NONE;
86}
87
89 const Common::PropertyCode::PropertyAccessor& propertyAccessor)
90{
91 std::set<LinguisticCode> values;
92 allValues(propertyAccessor, values);
93 return values.size();
94}
95
97 const Common::PropertyCode::PropertyAccessor& propertyAccessor,
98 std::set<LinguisticCode>& result) const
99{
100 for (auto it = cbegin(); it != cend(); it++)
101 {
102 if (!propertyAccessor.empty(it->properties))
103 {
104 result.insert(propertyAccessor.readValue(it->properties));
105 }
106 }
107}
108
110 std::ostream& xmlStream,
112 const FsaStringsPool& sp) const
113{
114 xmlStream << " <data>" << std::endl;
115
116 if (!empty())
117 {
118 // trie pour avoir les donnees groupees par strings
119 MorphoSyntacticData tmp(*this);
120 sort(tmp.begin(),tmp.end(),ltString());
122 StringsPoolIndex form(0);
123 StringsPoolIndex lemma(0);
124 StringsPoolIndex norm(0);
125 std::string currentType;
126 bool firstEntry = true;
127 for (auto it = tmp.cbegin(); it != tmp.cend(); it++)
128 {
129 if (it->type != type)
130 {
131 // Changement type
132 if (!firstEntry)
133 {
134 xmlStream << " </form>" << std::endl;
135 xmlStream << " </" << currentType << ">" << std::endl;
136 }
137 type=it->type;
138 switch ( type )
139 {
140 case SIMPLE_WORD :
141 currentType = "simple_word";
142 break;
144 currentType = "idiomatic_expression";
145 break;
146 case UNKNOWN_WORD :
147 currentType = "unknown_word";
148 break;
149 case ABBREV_ALTERNATIVE :
150 currentType = "abbrev_alternative";
151 break;
152 case HYPHEN_ALTERNATIVE :
153 currentType = "hyphen_alternative";
154 break;
156 currentType = "concatenated_alternative";
157 break;
159 currentType = "spelling_alternative";
160 break;
161 case CAPITALFIRST_WORD :
162 currentType = "capitalfirst_word";
163 break;
165 currentType = "agglutinated_word";
166 break;
168 currentType = "desagglutinated_word";
169 break;
170 case SPECIFIC_ENTITY :
171 currentType = "specific_entity";
172 break;
174 currentType = "hyperwordstemmer_alternative";
175 break;
177 currentType = "chinese_segmenter";
178 break;
179 default :
180 currentType = "UNKNOWN_MORPHOSYNTACTIC_TYPE";
181 break;
182 }
183 xmlStream << " <" << currentType << ">" << std::endl;
184 }
185 if ((it->inflectedForm != form) || (it->lemma != lemma)
186 || (it->normalizedForm != norm))
187 {
188 if (!firstEntry)
189 {
190 xmlStream << " </form>" << std::endl;
191 }
192 form = it->inflectedForm;
193 lemma = it->lemma;
194 norm = it->normalizedForm;
195 xmlStream << " <form infl=\""
196 << Common::Misc::transcodeToXmlEntities(sp[form]).toStdString()
197 << "\" ";
198 xmlStream << "lemma=\""
199 << Common::Misc::transcodeToXmlEntities(sp[lemma]).toStdString()
200 << "\" ";
201 xmlStream << "norm=\""
202 << Common::Misc::transcodeToXmlEntities(sp[norm]).toStdString()
203 << "\">" << std::endl;
204 }
205 const auto& managers = pcm.getPropertyManagers();
206 xmlStream << " <property>" << std::endl;
207 for (auto propItr = managers.cbegin(); propItr != managers.cend();
208 propItr++)
209 {
210 if (!propItr->second.getPropertyAccessor().empty(it->properties))
211 {
212 xmlStream << " <p prop=\"" << propItr->first
213 << "\" val=\""
214 << propItr->second.getPropertySymbolicValue(it->properties)
215 << "\"/>" << std::endl;
216 }
217 }
218 xmlStream << " </property>" << std::endl;
219 firstEntry=false;
220 }
221 xmlStream << " </form>" << std::endl;
222 xmlStream << " </" << currentType << ">" << std::endl;
223 }
224 xmlStream << " </data>" << std::endl;
225}
226
227std::set<StringsPoolIndex> MorphoSyntacticData::allInflectedForms() const
228 {
229 std::set<StringsPoolIndex> forms;
230 for (auto it = cbegin(); it != cend(); it++)
231 {
232 forms.insert(it->inflectedForm);
233 }
234 return forms;
235 }
236
237std::set<StringsPoolIndex> MorphoSyntacticData::allLemma() const
238 {
239 std::set<StringsPoolIndex> lemma;
240 for (auto it = cbegin(); it != cend(); it++)
241 {
242 lemma.insert(it->lemma);
243 }
244 return lemma;
245 }
246
247std::set<StringsPoolIndex> MorphoSyntacticData::allNormalizedForms() const
248 {
249 std::set<StringsPoolIndex> norms;
250 for (auto it = cbegin(); it != cend(); it++)
251 {
252 norms.insert(it->normalizedForm);
253 }
254 return norms;
255 }
256
258 const Common::PropertyCode::PropertyAccessor& propertyAccessor) const
259{
260 for (auto it = cbegin(); it != cend(); it++)
261 {
262 if (!propertyAccessor.empty(it->properties))
263 {
264 return propertyAccessor.readValue(it->properties);
265 }
266 }
267 return L_NONE;
268}
269
270} // LinguisticAnalysisStructure
271
272} // LinguisticProcessing
273
274} // Lima
#define L_NONE
Definition StdBitset.h:338
Provide function to read write and check a property.
LinguisticCode readValue(const LinguisticCode &code) const
read a property in a coded int.
bool empty(const LinguisticCode &l) const
Test if the given code has property data.
Provide tools to parse a property file, and deal with the property coding system.
const std::map< std::string, PropertyManager > & getPropertyManagers() const
Get the map of all PropertyManagers.
uint64_t countValues(const Common::PropertyCode::PropertyAccessor &propertyAccessor)
void outputXml(std::ostream &xmlStream, const Common::PropertyCode::PropertyCodeManager &pcm, const FsaStringsPool &sp) const
LinguisticCode firstValue(const Common::PropertyCode::PropertyAccessor &propertyAccessor) const
Return the first non empty value for the given accessor.
bool hasUniqueMicro(const Lima::Common::PropertyCode::PropertyAccessor &microAccessor, const std::list< Lima::LinguisticCode > &microFilter)
return true if there is only one micro, and this micro is in microfilter
std::set< LinguisticCode > allValues(const Common::PropertyCode::PropertyAccessor &propertyAccessor) const
LimaString transcodeToXmlEntities(const LimaString &str)
NAUTITIA.
PUGI__FN void sort(I begin, I end, const Pred &pred)
Definition pugixml.cpp:7549