34namespace LinguisticProcessing {
42m_useSentenceBounds(false),
43m_sentenceBoundsData(
"SentenceBoundaries"),
45m_resolveOverlappingEntities(false),
47m_testAllVertices(false),
48m_stopAtFirstSuccess(true),
49m_onlyOneSuccessPerType(false),
70 m_recognizers.push_back(std::dynamic_pointer_cast<Recognizer>(res));
75 const deque<string>& automatonList=unitConfiguration.
getListsValueAtKey(
"automatonList");
76 for (
auto automaton: automatonList)
79 m_recognizers.push_back(std::dynamic_pointer_cast<Recognizer>(res));
83 LERROR <<
"No 'automaton' or 'automatonList' in ApplyRecognizer group for language "
84 << (int)language <<
" !";
91 getBooleanParameter(unitConfiguration,
"useSentenceBounds");
100 if (! sentenceBoundsData.empty()) {
101 m_sentenceBoundsData=sentenceBoundsData;
111 getBooleanParameter(unitConfiguration,
"updateGraph");
118 m_resolveOverlappingEntities=
119 getBooleanParameter(unitConfiguration,
"resolveOverlappingEntities");
126 string overlappingEntitiesStrategy=
128 if (overlappingEntitiesStrategy==
"IgnoreSmallest") {
131 else if (overlappingEntitiesStrategy==
"IgnoreFirst") {
134 else if (overlappingEntitiesStrategy==
"IgnoreSecond") {
144 getBooleanParameter(unitConfiguration,
"testAllVertices");
151 m_stopAtFirstSuccess=
152 getBooleanParameter(unitConfiguration,
"stopAtFirstSuccess");
160 m_onlyOneSuccessPerType=
161 getBooleanParameter(unitConfiguration,
"onlyOneSuccessPerType");
185bool ApplyRecognizer::
187 const std::string& param)
const {
189 if (value ==
"yes" ||
200 if (m_recognizers.empty()) {
202 LDEBUG <<
"ApplyRecognizer: No recognizer to apply";
207 LINFO <<
"start process";
208 LDEBUG <<
" parameters are:";
209 LDEBUG <<
" - useSentenceBounds :" << m_useSentenceBounds;
210 LDEBUG <<
" - updateGraph :" << m_updateGraph;
211 LDEBUG <<
" - resolveOverlappingEntities :" << m_resolveOverlappingEntities;
212 LDEBUG <<
" - overlappingEntitiesStrategy :" << m_overlappingEntitiesStrategy;
213 LDEBUG <<
" - testAllVertices :" << m_testAllVertices;
214 LDEBUG <<
" - stopAtFirstSuccess :" << m_stopAtFirstSuccess;
215 LDEBUG <<
" - onlyOneSuccessPerType :" << m_onlyOneSuccessPerType;
216 LDEBUG <<
" - graphId :" << m_graphId;
217 LDEBUG <<
" - dataForStorage :" << m_dataForStorage;
222 auto recoData = std::dynamic_pointer_cast<RecognizerData>(analysis.
getData(
"RecognizerData"));
225 recoData = std::make_shared<RecognizerData>();
226 analysis.
setData(
"RecognizerData", recoData);
229 auto annotationData = std::dynamic_pointer_cast< AnnotationData >(analysis.
getData(
"AnnotationData"));
230 if (annotationData==0)
232 annotationData = std::make_shared<AnnotationData>();
233 if (std::dynamic_pointer_cast<AnalysisGraph>(analysis.
getData(
"AnalysisGraph")) != 0)
235 std::dynamic_pointer_cast<AnalysisGraph>(analysis.
getData(
"AnalysisGraph"))->populateAnnotationGraph(
236 annotationData.get(),
"AnalysisGraph");
238 analysis.
setData(
"AnnotationData",annotationData);
245 recoData->setResultData(resultData);
247 if (m_useSentenceBounds) {
248 for (
auto reco: m_recognizers) {
249 returnCode = processOnEachSentence(analysis, reco.get(), recoData.get());
253 for (
auto reco: m_recognizers) {
254 returnCode = processOnWholeText(analysis, reco.get(), recoData.get());
260 recoData->removeVertices(analysis);
261 recoData->clearVerticesToRemove();
262 recoData->removeEdges(analysis);
263 recoData->clearEdgesToRemove();
266 if (! m_dataForStorage.empty()) {
267 analysis.
setData(m_dataForStorage,resultData);
271 recoData->deleteResultData();
288 auto anagraph = std::dynamic_pointer_cast<AnalysisGraph>(analysis.
getData(recoData->
getGraphId()));
289 if (
nullptr==anagraph)
291 LERROR <<
"graph with id '"<< recoData->
getGraphId() <<
"' is not available";
296 auto sb=std::dynamic_pointer_cast<SegmentationData>(analysis.
getData(m_sentenceBoundsData));
299 LERROR <<
"no sentence bounds "<< m_sentenceBoundsData <<
" defined ! abort";
303 std::vector<RecognizerMatch> seRecognizerResult;
305 std::vector<Segment>::const_iterator boundItr=(sb->getSegments()).begin();
307 while (boundItr!=(sb->getSegments()).end())
313 seRecognizerResult.clear();
314 reco->
apply(*anagraph,beginSentence,
315 endSentence,analysis,seRecognizerResult);
318 if (m_resolveOverlappingEntities)
321 m_overlappingEntitiesStrategy);
334 RecognizerData* recoData )
const
339 auto anagraph = std::dynamic_pointer_cast<AnalysisGraph>(analysis.
getData(recoData->getGraphId()));
340 if (
nullptr == anagraph)
343 LERROR <<
"graph with id '"<< recoData->getGraphId() <<
"' is not available";
349 std::vector<RecognizerMatch> seRecognizerResult;
351 reco->
apply(*anagraph,
352 anagraph->firstVertex(),
353 anagraph->lastVertex(),
354 analysis,seRecognizerResult,
355 m_testAllVertices,m_stopAtFirstSuccess,m_onlyOneSuccessPerType);
358 if (m_resolveOverlappingEntities)
361 m_overlappingEntitiesStrategy);
This file is the main header file for the data related to annotation graphs.
LinguisticGraph::vertex_descriptor LinguisticGraphVertex
Defines a Factory to create Object of type Base.
#define APPLYRECOGNIZER_CLASSID
Holds all data that pass through the ProcessUnits Analysis data are shared pointers,...
void removeData(const QString &id)
remove the analysisData with the given id
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::string & getParamsValueAtKey(const std::string &key)
std::deque< std::string > & getListsValueAtKey(const std::string &key)
return a message when a 'list' was not found
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.
void init(Common::XMLConfigurationFiles::GroupConfigurationStructure &unitConfiguration, Manager *manager) override
initialize with parameters from configuration file.
virtual ~ApplyRecognizer()
LimaStatusCode process(AnalysisContent &analysis) const override
Process on data in analysisContent.
const std::string & getGraphId() const
␈rief a class for the definition of a complete recognizer
uint64_t apply(const LinguisticAnalysisStructure::AnalysisGraph &graph, const LinguisticGraphVertex &begin, const LinguisticGraphVertex &end, AnalysisContent &analysis, std::vector< RecognizerMatch > &result, bool testAllVertices=false, bool stopAtFirstSuccess=true, bool onlyOneSuccessPerType=false, bool returnAtFirstSuccess=false, bool applySameRuleWhileSuccess=false) const
apply the recognizer on a graph
uint64_t resolveOverlappingEntities(std::vector< RecognizerMatch > &listEntities, const OverlapResolutionStrategy &strategy=DEFAULT_OVERLAP_STRATEGY) const
resolve the problem of overlapping entities in the list of entities : when two entities are overlapin...
static const LinguisticResources & single()
const singleton accessor
This file contains a class to control log of informations about time, such as logging cumulated time ...
@ IGNORE_SECOND
the second entity is ignored => assumes the leftmost trigger is more important
@ IGNORE_SMALLEST
the smallest entity is ignored (the one that covers the smallest number of words is assumed to be les...
@ IGNORE_FIRST
the first entity is ignored => assumes the rightmost trigger is more important
launch exception related to the configuration file parsing