LIMA
Libre Multilingual Analyzer — C++ API
Loading...
Searching...
No Matches
SyntacticAnalyzer-deps.cpp
Go to the documentation of this file.
1// Copyright 2002-2013 CEA LIST
2// SPDX-FileCopyrightText: 2022 CEA LIST <gael.de-chalendar@cea.fr>
3//
4// SPDX-License-Identifier: MIT
5
17
26
27#include <boost/graph/reverse_graph.hpp>
28
29using namespace std;
30using namespace boost;
31using namespace Lima::Common::MediaticData;
35
36namespace Lima
37{
38namespace LinguisticProcessing
39{
40namespace SyntacticAnalysis
41{
42
44
46 m_language(),
47 m_recognizers(),
48 m_actions(),
49 m_applySameRuleWhileSuccess(false)
50{}
51
54 Manager* manager)
55
56{
59 try
60 {
61 m_actions = unitConfiguration.getListsValueAtKey("actions");
62 }
64 {
65 LERROR << "no parameter 'actions' in SyntacticAnalyzerDeps group for language " << (int) m_language;
67 }
68 std::deque< std::string >::const_iterator actionsit, actionsit_end;
69 actionsit = m_actions.begin(); actionsit_end = m_actions.end();
70 for (; actionsit != actionsit_end; actionsit++)
71 {
72 std::string action = *actionsit;
73 if ( (action != "setl2r") && (action != "setr2l") )
74 {
75 m_recognizers[action] = std::dynamic_pointer_cast<Automaton::Recognizer>(LinguisticResources::single().getResource(m_language, action));
76 }
77 else
78 {
79 LWARN << "SyntacticAnalyzerDeps actions setl2r and setr2l are deprecated";
80 }
81}
82
83 try {
84 std::string val=unitConfiguration.getParamsValueAtKey("applySameRuleWhileSuccess");
85 if (val == "true" || val == "yes") {
87 }
88 else {
90 }
91 }
92 catch (Common::XMLConfigurationFiles::NoSuchParam& ) {} // keep default value
93
94
95}
96
98 AnalysisContent& analysis) const
99{
100 Lima::TimeUtilsController timer("SyntacticAnalysis");
102 LINFO << "start syntactic analysis - dependence relations search";
103
104 auto anagraph = std::dynamic_pointer_cast<AnalysisGraph>(analysis.getData("PosGraph"));
105 if (anagraph==0)
106 {
107 LERROR << "no AnalysisGraph ! abort";
108 return MISSING_DATA;
109 }
110 auto sb = std::dynamic_pointer_cast<SegmentationData>(analysis.getData("SentenceBoundaries"));
111 if (sb==0)
112 {
113 LERROR << "no sentence bounds ! abort";
114 return MISSING_DATA;
115 }
116 if (sb->getGraphId() != "PosGraph") {
117 LERROR << "SentenceBounds have been computed on " << sb->getGraphId() << " !";
118 LERROR << "SyntacticAnalyzer-deps needs SentenceBounds on PosGraph";
120 }
121
122 if (analysis.getData("SyntacticData") == 0)
123 {
124 auto syntacticData = std::make_shared<SyntacticData>(anagraph.get(), nullptr);
125 syntacticData->setupDependencyGraph();
126 analysis.setData("SyntacticData",syntacticData);
127 }
128
129 auto recoData = std::dynamic_pointer_cast<RecognizerData>(analysis.getData("RecognizerData"));
130 if (recoData == 0)
131 {
132 recoData = std::make_shared<RecognizerData>();
133 analysis.setData("RecognizerData", recoData);
134 }
135
136 // ??OME2 for (SegmentationData::const_iterator boundItr=sb->begin();
137 // boundItr!=sb->end();
138 for (std::vector<Segment>::const_iterator boundItr=(sb->getSegments()).begin();
139 boundItr!=(sb->getSegments()).end();
140 boundItr++)
141 {
142 LinguisticGraphVertex beginSentence=boundItr->getFirstVertex();
143 LinguisticGraphVertex endSentence=boundItr->getLastVertex();
144#ifdef DEBUG_LP
145 LDEBUG << "analyze sentence from vertex " << beginSentence << " to vertex " << endSentence;
146#endif
147 std::deque< std::string >::const_iterator actionsit, actionsit_end;
148 actionsit = m_actions.begin(); actionsit_end = m_actions.end();
149 for (; actionsit != actionsit_end; actionsit++)
150 {
151 std::string action = *actionsit;
152 if (action == "setl2r" || action == "setr2l")
153 {
154 LWARN << "SyntacticAnalyzerDeps actions setl2r and setr2l are deprecated";
155 }
156 else
157 {
158#ifdef DEBUG_LP
159 LDEBUG << "Geting automaton for action" << action;
160#endif
161 auto recognizer = (*(m_recognizers.find(action))).second;
162 std::vector<Automaton::RecognizerMatch> result;
163#ifdef DEBUG_LP
164 LDEBUG << "Applying automaton for action " << action << " on sentence from "
165 << beginSentence << " to " << endSentence;
166#endif
167 recognizer->apply(*anagraph,
168 beginSentence,
169 endSentence,
170 analysis,
171 result,
172 true, // test all vertices=true
173 false,// stop at first success=false
174 false, // only one success per type=true
175 false, // return at first success=false
176 m_applySameRuleWhileSuccess // depends on config file
177 );
178 }
179 }
180
181 }
182
183 LINFO << "end syntactic analysis - dependence relations search";
184 return SUCCESS_ID;
185}
186
187
188} // closing namespace SyntacticAnalysis
189} // closing namespace LinguisticProcessing
190} // closing namespace Lima
#define SAPLOGINIT
#define LWARN
Definition LimaCommon.h:160
#define LDEBUG
Definition LimaCommon.h:157
#define LINFO
Definition LimaCommon.h:158
#define LERROR
Definition LimaCommon.h:161
A graph structure for linguistic analysis.
LinguisticGraph::vertex_descriptor LinguisticGraphVertex
Defines a Factory to create Object of type Base.
#define SYNTACTICANALYZERDEPS_CLASSID
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
void setData(const QString &id, std::shared_ptr< AnalysisData > data)
set an analysisData with the given id.
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
std::map< std::string, std::shared_ptr< Automaton::Recognizer > > m_recognizers
void init(Common::XMLConfigurationFiles::GroupConfigurationStructure &unitConfiguration, Manager *manager) override
initialize with parameters from configuration file.
LimaStatusCode process(AnalysisContent &analysis) const override
Process on data in analysisContent.
static const LinguisticResources & single()
const singleton accessor
Definition Singleton.h:51
This file contains a class to control log of informations about time, such as logging cumulated time ...
SimpleFactory< MediaProcessUnit, SyntacticAnalyzerDeps > syntacticAnalyzerDepsFactory(SYNTACTICANALYZERDEPS_CLASSID)
NAUTITIA.
LimaStatusCode
Definition LimaCommon.h:236
@ SUCCESS_ID
Definition LimaCommon.h:237
@ INVALID_CONFIGURATION
Definition LimaCommon.h:242
@ MISSING_DATA
Definition LimaCommon.h:243
STL namespace.