LIMA
Libre Multilingual Analyzer — C++ API
Loading...
Searching...
No Matches
documentProperty.cpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2022 CEA LIST <gael.de-chalendar@cea.fr>
2//
3// SPDX-License-Identifier: MIT
4
5/************************************************************************
6 * @file abstractDocumentXMLParser.cpp
7 * @author Olivier Mesnard
8 * @date 20 Sept 2005
9 *
10 * common functions of [Structured] and [Simple] DocumentXMLParser
11 *
12 ***********************************************************************/
13
14#include "documentProperty.h"
15
19
20// #include "linguisticProcessing/LinguisticProcessingCommon.h"
21
23
24using namespace std;
26
27namespace Lima {
28namespace DocumentsReader {
29
46
48 : m_storageType ( STORAGE_UTF8_STRING ), m_storageSize ( 0 ),
49 m_cardinalityType ( CARDINALITY_OPTIONAL ),
50 m_tagElementNames(), m_tagAttributeNames()
51{
52}
53
55 : m_storageType ( dpt.m_storageType ), m_storageSize ( dpt.m_storageSize ),
56 m_cardinalityType ( dpt.m_cardinalityType ),
57 m_tagElementNames(dpt.m_tagElementNames), m_tagAttributeNames(dpt.m_tagAttributeNames)
58{
59}
60
70
75
77{
78 if (this != &dpt)
79 *m_d = *dpt.m_d;
80 m_id = dpt.m_id;
81 return *this;
82}
83
89
94
97const long int& DocumentPropertyType::getStorageSize(void) const { return m_d->m_storageSize; }
98const std::deque< QString >& DocumentPropertyType::getElementTagNames() const { return m_d->m_tagElementNames; }
99const std::deque< std::pair<QString,QString> > & DocumentPropertyType::getAttributeTagNames() const { return m_d->m_tagAttributeNames; }
100
104
105
108 Manager* )
109{
110#ifdef DEBUG_LP
111 DRLOGINIT;
112 LDEBUG << "DocumentPropertyType::init()";
113#endif
114
115 // type de l'attribut (string, integer, date)
116 try
117 {
118 QString storageTypeId = QString::fromUtf8(unitConfiguration.getParamsValueAtKey ( "storageType" ).c_str());
119 for ( int i = 0 ; static_cast<StorageType> ( i ) < MAX_STORAGE_TYPE ; i++ )
120 {
121 StorageType storageType = static_cast<StorageType> ( i );
122 if ( !storageTypeId.compare ( storageTypeTag[storageType] ) )
123 {
124 m_d->m_storageType = storageType;
125 break;
126 }
127 }
128 }
129 catch ( NoSuchParam& e )
130 {
131 DRLOGINIT;
132 LERROR << "no param 'storageType' in DocumentPropertyType group for " << getId();
133 throw Lima::InvalidConfiguration("no param 'storageType' in DocumentPropertyType group for "+getId());
134 }
135
136 // taille pour le stockage (nombre de bytes pour une chaine de caracteres)
137 try
138 {
140 m_d->m_storageSize=atoi ( unitConfiguration.getParamsValueAtKey ( "storageSize" ).c_str() );
141 }
142 }
143 catch ( NoSuchParam& e )
144 {
145 DRLOGINIT;
146 LWARN << "no param 'storageSize' in DocumentPropertyType group for " << getId();
147 }
148
149 // cardinalite: valeur obligatoire, optionelle ou multiple
150 try
151 {
152 QString cardinalityTypeId = QString::fromUtf8(unitConfiguration.getParamsValueAtKey ( "cardinality" ).c_str());
153 for ( int i = 0 ; i < MAX_STORAGE_TYPE ; i++ )
154 {
155 CardinalityType cardinalityType = static_cast<CardinalityType> ( i );
156 if ( !cardinalityTypeId.compare ( cardinalityTypeTag[cardinalityType] ) )
157 {
158 m_d->m_cardinalityType = cardinalityType;
159 break;
160 }
161 }
162 }
163 catch ( NoSuchParam& e )
164 {
165 DRLOGINIT;
166 LERROR << "no param 'cardinality' in DocumentPropertyType group for " << getId();
167 throw Lima::InvalidConfiguration("no param 'cardinality' in DocumentPropertyType group for " + getId());
168 }
169
170 // liste des noms d'elements dont le contenu defini la valeur de l'attribut
171 try
172 {
173 const std::deque< std::string >& list = unitConfiguration.getListsValueAtKey ( "elementNames" );
174 for(const std::string& elem : list)
175 {
176#ifdef DEBUG_LP
178 LDEBUG << "DocumentPropertyType::init: m_tagElementNames.push_back("
179 << elem << ")";
180#endif
181 m_d->m_tagElementNames.push_back(QString::fromUtf8(elem.c_str()));
182 }
183 }
184 catch ( NoSuchList& e )
185 {
186 DRLOGINIT;
187 LDEBUG << "no list 'elementNames' in DocumentPropertyType group for " << getId();
188 }
189
190 // liste des noms d'elements + attributs dont la valeur defini la valeur de l'attribut
191 try
192 {
193 const std::deque< std::string >& list = unitConfiguration.getListsValueAtKey ( "attributeNames" );
194 for ( auto it = list.begin() ; it != list.end() ; it++ )
195 {
196 //uint64_t spaceOffset=it->find(' '); portage 32 64
197 std::string::size_type spaceOffset=it->find ( ' ' );
198 if ( spaceOffset == std::string::npos )
199 {
200 DRLOGINIT;
201 LWARN << "DocumentPropertyType::init(): ill formed attributeName for "
202 << getId() << ": " << *it;
203 }
204 else
205 {
206 unsigned int equalOffset=it->find ( '=',spaceOffset+1 );
207 std::string attributeName ( *it,spaceOffset+1,equalOffset-spaceOffset-1 );
208 std::string newFieldName ( *it,0,spaceOffset );
209#ifdef DEBUG_LP
211 LDEBUG << "DocumentPropertyType::init: m_tagAttributeNames.push_back("
212 << newFieldName << ", " << attributeName << ")";
213#endif
214 m_d->m_tagAttributeNames.push_back ( pair<QString,QString> ( QString::fromUtf8(newFieldName.c_str()),QString::fromUtf8(attributeName.c_str()) ) );
215 }
216 }
217 }
218 catch ( NoSuchList& e )
219 {
220 DRLOGINIT;
221 LDEBUG << "no list 'attributeNames' in DocumentPropertyType group for " << getId();
222 }
223
224}
225
227{
228 return getId() < dpt.getId();
229}
230
231
234
238
241 Manager* manager )
242{
244 unitConfiguration, manager );
245}
246
249
253
256 Manager* manager )
257{
259 unitConfiguration, manager );
260 DRLOGINIT;
261 if ( m_d->m_tagAttributeNames.empty() && m_d->m_tagElementNames.empty() )
262 {
263 LERROR << "no list ('attributeNames' or 'elementNames') in DocumentPropertyType group for " << getId();
264 throw Lima::InvalidConfiguration("no list ('attributeNames' or 'elementNames') in DocumentPropertyType group for " + getId());
265 }
266}
267
268} // namespace DocumentsReader
269} // namespace Lima
270
#define LWARN
Definition LimaCommon.h:160
#define LDEBUG
Definition LimaCommon.h:157
#define LERROR
Definition LimaCommon.h:161
Defines a Factory to create Object of type Base.
#define DRLOGINIT
std::deque< std::string > & getListsValueAtKey(const std::string &key)
return a message when a 'param' was not found
std::deque< std::pair< QString, QString > > m_tagAttributeNames
DocumentPropertyTypePrivate & operator=(const DocumentPropertyTypePrivate &dpt)
const std::deque< QString > & getElementTagNames() const
DocumentPropertyType & operator=(const DocumentPropertyType &dpt)
const std::deque< std::pair< QString, QString > > & getAttributeTagNames() const
void init(Lima::Common::XMLConfigurationFiles::GroupConfigurationStructure &unitConfiguration, Manager *manager) override
const CardinalityType & getValueCardinality() const
bool operator<(const DocumentPropertyType &dpt) const
void init(Lima::Common::XMLConfigurationFiles::GroupConfigurationStructure &unitConfiguration, Manager *manager) override
void init(Lima::Common::XMLConfigurationFiles::GroupConfigurationStructure &unitConfiguration, Manager *manager) override
Manage initialization of InitializableObjects using configuration module and parameters.
Use this exception to signal an error in one of the configuration files.
Definition LimaCommon.h:345
#define EXTENSIONDOCUMENTPROPERTYTYPE_CLASSID
#define STANDARDDOCUMENTPROPERTYTYPE_CLASSID
#define MAX_STORAGE_TYPE
originally detectModuleConfigurationStructure.h in detectlibraries
Lima::SimpleFactory< AbstractReaderResource, Lima::DocumentsReader::ExtensionDocumentPropertyType > extensionDocumentPropertyTypeFactory(EXTENSIONDOCUMENTPROPERTYTYPE_CLASSID)
static const QString cardinalityTypeTag[MAX_STORAGE_TYPE]
Lima::SimpleFactory< AbstractReaderResource, Lima::DocumentsReader::StandardDocumentPropertyType > standardPropertyTypeFactory(STANDARDDOCUMENTPROPERTYTYPE_CLASSID)
StorageType
a type meaning the storage type of an attribute
static const QString storageTypeTag[MAX_STORAGE_TYPE]
CardinalityType
a type meaning the cardinality of an attribute
NAUTITIA.
STL namespace.