LIMA
Libre Multilingual Analyzer — C++ API
Loading...
Searching...
No Matches
SimpleDefaultProperties.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// DefaultProperties is the implementation of the last module of
8// Morphological Analysis. Each token from the main tokens
9// path which remains without linguuistic properties receives
10// properties by default found into dictionnary using Tokenizer
11// status names as keys.
12//<if token has any linguistic properties, directly or by its
13// orthographic alternatives, default properties are not applied>
14
16
18
28
29using namespace boost;
30using namespace std;
31using namespace Lima::Common::MediaticData;
33
34namespace Lima
35{
36namespace LinguisticProcessing
37{
38namespace MorphologicAnalysis
39{
40
42
45
48
51 Manager* manager)
52{
54 m_language = manager->getInitializationParameters().media;
55 const Common::PropertyCode::PropertyManager& microManager = static_cast<const Common::MediaticData::LanguageData&>(Common::MediaticData::MediaticData::single().mediaData(m_language)).getPropertyCodeManager().getPropertyManager("MICRO");
56
57 try
58 {
59 deque<string> cats=unitConfiguration.getListsValueAtKey("defaultCategories");
60 for (deque<string>::iterator it=cats.begin();
61 it!=cats.end();
62 it++)
63 {
64 LinguisticCode microId=microManager.getPropertyValue(*it);
65 LDEBUG << "default category : " << microId;
66 if (!microManager.getPropertyAccessor().empty(microId) )
67 {
68 m_defaultProperties.push_back(microId);
69 }
70 else
71 {
72 LWARN << "micro categorie seems to be undefined !";
74 }
75 }
76 }
78 {
80 LWARN << "SimpleDefaultCateogries: no default properties defined !";
81 m_defaultProperties.push_back(L_NONE);
82 }
83 try
84 {
85 string dico = unitConfiguration.getParamsValueAtKey("charChart");
86 auto res = LinguisticResources::single().getResource(m_language, dico);
87 m_charChart = std::dynamic_pointer_cast< FlatTokenizer::CharChart >(res);
88 }
90 {
91 LERROR << "no param 'charChart' in SimpleDefaultCateogries group for language " << (int)m_language;
93 }
94
95}
96
103 AnalysisContent& analysis) const
104{
107 LINFO << "MorphologicalAnalysis: starting process DefaultProperties";
108
109 auto tokenList=std::dynamic_pointer_cast<AnalysisGraph>(analysis.getData("AnalysisGraph"));
110
111 // Affectation des propriétés par défaut
112 affectPropertiesOnePath(*tokenList);
113
114 // Graphe après l'affectation des propriétés par défaut
115 // std::cout << std::endl;
116 // std::cout << "Graph after Default Properties:" << std::endl;
117
118 // Fin de l'analyse morphologique
119 // std::cout << "End of Morphological Analysis" << std::endl;
120 // std::cout << std::endl;
121
122 LINFO << "MorphologicalAnalysis: ending process SimpleDefaultProperties";
123 TimeUtils::logElapsedTime("SimpleDefaultProperties");
124 return SUCCESS_ID;
125}
126
127
128// directly use the list of vertices (do not need to go through the graph)
129void SimpleDefaultProperties::affectPropertiesOnePath(
130 AnalysisGraph& anagraph) const
131{
132 graph_traits<LinguisticGraph>::vertex_iterator vBegin, vEnd, v;
133 boost::tie(vBegin, vEnd) = vertices(*(anagraph.getGraph()));
135
136 for (v = vBegin; v != vEnd; v++)
137 {
138 MorphoSyntacticData* currentData=get(vertex_data, *(anagraph.getGraph()), *v);
139 if (currentData == 0)
140 {
141 continue;
142 } // NULL for first and last vertex
143
144 //<if token has any linguistic properties, directly or by its
145 // orthographic alternatives, default properties are not applied>
146 if (currentData->empty())
147 {
148 Token* token=get(vertex_token, *(anagraph.getGraph()), *v);
149 LimaString str = m_charChart->unmark(token->stringForm());
151 elem.inflectedForm=token->form();
152 elem.lemma=sp[str];
153 elem.normalizedForm=elem.lemma;
154 elem.type=UNKNOWN_WORD;
155 for (vector<LinguisticCode>::const_iterator it=m_defaultProperties.begin();
156 it!=m_defaultProperties.end();
157 it++)
158 {
159 elem.properties=*it;
160 currentData->push_back(elem);
161 }
162 }
163 }
164}
165
166} // MorphologicAnalysis
167} // LinguisticProcessing
168} // Lima
#define LWARN
Definition LimaCommon.h:160
#define LDEBUG
Definition LimaCommon.h:157
#define LINFO
Definition LimaCommon.h:158
#define LERROR
Definition LimaCommon.h:161
@ vertex_token
@ vertex_data
#define MORPHOLOGINIT
#define SIMPLEDEFAULTPROPERTIES_CLASSID
Defines a Factory to create Object of type Base.
#define L_NONE
Definition StdBitset.h:338
Holds all data that pass through the ProcessUnits Analysis data are shared pointers,...
std::shared_ptr< AnalysisData > getData(const QString &id)
return AnalysisData by id
Holds linguistic data for one language.
const FsaStringsPool & stringsPool(MediaId med) const
const MediaData & mediaData(MediaId media) const
bool empty(const LinguisticCode &l) const
Test if the given code has property data.
Provide tools to manage a specific property.
const PropertyAccessor & getPropertyAccessor() const
give the corresponding PropertyAccessor
LinguisticCode getPropertyValue(const std::string &symbolicValue) const
Get the coded property value from the symbolic value.
std::deque< std::string > & getListsValueAtKey(const std::string &key)
return a message when a 'param' was not found
Manage initialization of InitializableObjects using configuration module and parameters.
const InitializationParameters & getInitializationParameters() const
get Initialization Parameters
Use this exception to signal an error in one of the configuration files.
Definition LimaCommon.h:345
An AnalysisData containing a LinguisticGraph with a language and an id.
const LinguisticGraph * getGraph(void) const
Returns the underlying graph structure.
LimaStatusCode process(AnalysisContent &analysis) const override
Each token of the specified path without dictionnary entry is searched into the specified dictionary.
void init(Common::XMLConfigurationFiles::GroupConfigurationStructure &unitConfiguration, Manager *manager) override
initialize with parameters from configuration file.
static const MediaticData & single()
const singleton accessor
Definition Singleton.h:51
static MediaticData & changeable()
singleton accessor
Definition Singleton.h:71
static void logElapsedTime(const std::string &mess, const std::string &taskCategory=std::string(""))
log the number of microseconds since last UpdateCurrentTime
static void updateCurrentTime(const std::string &taskCategory=std::string(""))
store current time for new elapsed time computation
SimpleFactory< MediaProcessUnit, SimpleDefaultProperties > simpleDefaultPropertiesFactory(SIMPLEDEFAULTPROPERTIES_CLASSID)
NAUTITIA.
LimaStatusCode
Definition LimaCommon.h:236
@ SUCCESS_ID
Definition LimaCommon.h:237
QString LimaString
Definition LimaString.h:33
STL namespace.
launch exception related to the configuration file parsing