LIMA
Libre Multilingual Analyzer — C++ API
Loading...
Searching...
No Matches
SpecificEntitiesMicros.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
6/************************************************************************
7 *
8 * @file SpecificEntitiesMicros.cpp
9 * @author Romaric Besancon (romaric.besancon@cea.fr)
10 * @date Thu Apr 5 2007
11 * copyright Copyright (C) 2007 by CEA LIST
12 *
13 ***********************************************************************/
14
21
23using namespace Lima::Common::PropertyCode;
24using namespace Lima::Common::MediaticData;
25using namespace std;
26
27namespace Lima {
28namespace LinguisticProcessing {
29namespace SpecificEntities {
30
33
38
42
43//***********************************************************************
45 GroupConfigurationStructure& unitConfiguration,
46 Manager* manager)
47{
48#ifdef DEBUG_LP
50 LDEBUG << "SpecificEntitiesMicros initialization";
51#endif
52 auto language = manager->getInitializationParameters().language;
53 const auto& microManager = static_cast<const LanguageData&>(MediaticData::single().mediaData(language)).getPropertyCodeManager().getPropertyManager("MICRO");
54
55 const auto& entities = unitConfiguration.getLists();
56 #ifdef DEBUG_LP
57 LDEBUG << "entities.size() " << entities.size();
58 #endif
59
60 for (auto entity: entities)
61 {
62 auto entityName = QString::fromStdString(entity.first);
63#ifdef DEBUG_LP
64 LDEBUG << "Adding categories to entity " << entityName;
65#endif
66 try
67 {
68 EntityType type;
69 try {
70 type = static_cast<const MediaticData&>(MediaticData::single()).getEntityType(entityName);
71 } catch (const LimaException& e) {
73 LIMA_EXCEPTION("Unknown entity " << entityName << " observed in " << e.what());
74 }
75 for (auto micro: entity.second)
76 {
77 auto code = microManager.getPropertyValue(micro);
78 if (code == L_NONE)
79 {
81 LERROR << "SpecificEntitiesMicros::init on entity" << entityName
82 << "," << micro
83 << "linguistic code is not defined for language"
84 << MediaticData::single().getMediaId(language);
85 }
86 else
87 {
88#ifdef DEBUG_LP
89 LDEBUG << "Adding " << micro << code << " to EntityType " << type;
90#endif
91 m_micros[type].insert(code);
92 }
93 }
94 }
95 catch (LimaException& e)
96 {
97 // just a warning (on LERROR)
99 LERROR << entityName << " is not a defined specific entity";
100 }
101 }
102}
103
104const set<LinguisticCode>* SpecificEntitiesMicros::
105getMicros(const EntityType& type)
106{
107 map<EntityType,set<LinguisticCode> >::const_iterator it=m_micros.find(type);
108 if (it==m_micros.end())
109 {
110 SELOGINIT;
111 LERROR << "no microcategories defined for type " << type << " ("
113 << ")";
114 throw LimaException( (QString(QLatin1String("no microcategories defined for type %1"))).arg(MediaticData::single().getEntityName(type)).toUtf8().constData() );
115 }
116 return &((*it).second);
117}
118
119
120
121} // end namespace
122} // end namespace
123} // end namespace
#define LIMA_EXCEPTION(X)
This macro writes the message X to a previously configured error stream before throwing a LimaExcepti...
Definition LimaCommon.h:293
#define LDEBUG
Definition LimaCommon.h:157
#define LERROR
Definition LimaCommon.h:161
#define SELOGINIT
Defines a Factory to create Object of type Base.
#define SPECIFICENTITIESMICROS_CLASSID
#define L_NONE
Definition StdBitset.h:338
Holds linguistic data for one language.
holds data about codes and names for grammatical categories, etc.
const std::map< std::string, std::deque< std::string > > & getLists()
Manage initialization of InitializableObjects using configuration module and parameters.
const InitializationParameters & getInitializationParameters() const
get Initialization Parameters
The main LIMA exception class.
Definition LimaCommon.h:262
virtual const char * what() const override
Definition LimaCommon.h:280
void init(Common::XMLConfigurationFiles::GroupConfigurationStructure &unitConfiguration, Manager *manager) override
const std::set< LinguisticCode > * getMicros(const Common::MediaticData::EntityType &type)
static const MediaticData & single()
const singleton accessor
Definition Singleton.h:51
std::string limastring2utf8stdstring(const Lima::LimaString &phrase, uint32_t size0)
Convert a wide string to a string , in dest up to size bytes.
SimpleFactory< AbstractResource, SpecificEntitiesMicros > SpecificEntitiesMicrosFactory(SPECIFICENTITIESMICROS_CLASSID)
NAUTITIA.
STL namespace.
static const struct TextHtmlEntity entities[]