LIMA
Libre Multilingual Analyzer — C++ API
Loading...
Searching...
No Matches
SyntacticAnalyzer-nochains.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#include "SyntagmaticMatrix.h"
18
24#include "common/LimaCommon.h"
25
26#undef min
27#undef max
28
29using namespace std;
30//using namespace boost;
31using namespace Lima::Common::MediaticData;
33
34namespace Lima
35{
36namespace LinguisticProcessing
37{
38namespace SyntacticAnalysis
39{
40
41static const uint64_t DEFAULT_MAXCHAINSNBBYVERTEX = 30;
42static const uint64_t DEFAULT_MAXCHAINLENGTH = 200;
43
45
47 m_language(),
48 m_chainMatrix(0),
49 m_maxChainsNbByVertex(std::numeric_limits<uint64_t>::max())
50{}
51
54 Manager* manager)
55
56{
58 m_language = manager->getInitializationParameters().media;
59 m_macroAccessor = &(static_cast<const Common::MediaticData::LanguageData&>(Common::MediaticData::MediaticData::single().mediaData(m_language)).getPropertyCodeManager().getPropertyAccessor("MACRO"));
60 m_microAccessor = &(static_cast<const Common::MediaticData::LanguageData&>(Common::MediaticData::MediaticData::single().mediaData(m_language)).getPropertyCodeManager().getPropertyAccessor("MICRO"));
61 try
62 {
63 std::string chainMatrixId = unitConfiguration.getParamsValueAtKey("chainMatrix");
64 m_chainMatrix = std::dynamic_pointer_cast<SyntagmDefStruct>(LinguisticResources::single().getResource(m_language,chainMatrixId));
65 }
67 {
68 LERROR << "no parameter 'chainMatrix' in SyntacticAnalyzerChains group for language " << (int) m_language << " !";
70 }
71 try
72 {
73 std::string maxChainsNbByVertexS=unitConfiguration.getParamsValueAtKey("maxChainsNbByVertex");
74 std::istringstream iss(maxChainsNbByVertexS);
76 }
78 {
79 LWARN << "no parameter 'maxChainsNbByVertex' in SyntacticAnalyzerChains group for language " << (int) m_language << " ! Using default: "<<DEFAULT_MAXCHAINSNBBYVERTEX<<".";
81 }
82 try
83 {
84 std::string maxChainLengthS=unitConfiguration.getParamsValueAtKey("maxChainLength");
85 std::istringstream iss(maxChainLengthS);
86 iss >> m_maxChainLength;
87 }
89 {
90 LWARN << "no parameter 'maxChainLength' in SyntacticAnalyzerChains group for language " << (int) m_language << " ! Using default: "<<DEFAULT_MAXCHAINLENGTH<<".";
92 }
93 try
94 {
95 std::string id=unitConfiguration.getParamsValueAtKey("ponctuCategory");
96 m_ponctuCategory=static_cast<const Common::MediaticData::LanguageData&>(Common::MediaticData::MediaticData::single().mediaData(m_language)).getPropertyCodeManager().getPropertyManager("MACRO").getPropertyValue(id);
97 }
99 {
100 LWARN << "No ponctu macrocategory defined ! use category PONCTU";
101 m_ponctuCategory=static_cast<const Common::MediaticData::LanguageData&>(Common::MediaticData::MediaticData::single().mediaData(m_language)).getPropertyCodeManager().getPropertyManager("MACRO").getPropertyValue("PONCTU");
102 }
103
104}
105
107 AnalysisContent& analysis) const
108{
109 Lima::TimeUtilsController timer("SyntacticAnalysis");
111 LINFO << "start syntactic analysis - nochains";
112 // create syntacticData
113 auto anagraph = std::dynamic_pointer_cast<AnalysisGraph>(analysis.getData("PosGraph"));
114 if (anagraph==0)
115 {
116 LERROR << "no PosGraph ! abort";
117 return MISSING_DATA;
118 }
119 auto sb = std::dynamic_pointer_cast<SegmentationData>(analysis.getData("SentenceBoundaries"));
120 if (sb==0)
121 {
122 LERROR << "no sentence bounds ! abort";
123 return MISSING_DATA;
124 }
125 if (sb->getGraphId() != "PosGraph") {
126 LERROR << "SentenceBounds have been computed on " << sb->getGraphId() << " !";
127 LERROR << "SyntacticAnalyzer-deps needs SentenceBounds on PosGraph";
129 }
130
131 auto syntacticData = std::dynamic_pointer_cast<SyntacticData>(analysis.getData("SyntacticData"));
132 if (syntacticData==0)
133 {
134 syntacticData= std::make_shared<SyntacticData>(anagraph.get(), m_chainMatrix);
135 analysis.setData("SyntacticData",syntacticData);
136 }
137 else if (syntacticData->matrices() == 0)
138 {
139 syntacticData->matrices(m_chainMatrix);
140 }
141 syntacticData->setupDependencyGraph();
142
143 uint64_t chainId = m_firstChainId;
144 std::list<LinguisticCode> ponctuMacroFilter;
145 ponctuMacroFilter.push_back(m_ponctuCategory);
146
147// bool l2r = true;
148 // ??OME2 for (SegmentationData::const_iterator boundItr=sb->begin();
149 // boundItr!=sb->end();
150 for (std::vector<Segment>::const_iterator boundItr=(sb->getSegments()).begin();
151 boundItr!=(sb->getSegments()).end();
152 boundItr++)
153 {
154 LinguisticGraphVertex beginSentence=boundItr->getFirstVertex();
155 LinguisticGraphVertex endSentence=boundItr->getLastVertex();
156 identifyChains(syntacticData.get(), beginSentence, endSentence, chainId);
157 beginSentence=endSentence;
158 }
159
160 LINFO << "end syntactic analysis - nochains";
161 return SUCCESS_ID;
162}
163
164
166 const LinguisticGraphVertex& start,
167 const LinguisticGraphVertex& stop,
168 uint64_t& startChainId) const
169{
170// SACLOGINIT;
171// LDEBUG << "Searching chains from/to (morph): " << start << "/" << stop;
172 if (start == stop)
173 return;
174 VertexChainIdPropertyMap vertexChainIdMap = get( vertex_chain_id, *(data->graph()) );
175 std::set< std::string > alreadyReported;
176 LinguisticGraphVertex first = data->iterator()-> firstVertex();
177 LinguisticGraphVertex last = data->iterator()-> lastVertex();
178// VertexDataPropertyMap dataMap = get(vertex_data, (*data->iterator()->getGraph() ) );
179// VertexTokenPropertyMap tokenMap =get(vertex_token, (*data->iterator()->getGraph() ) );
180
181 std::vector< ChainStackTuple > pile;
182 // std::stack< LinguisticGraphVertex > pileSons;
184// std::stack< std::pair< std::deque< ChainStackTuple >, std::stack< LinguisticGraphVertex > > > tank;
185 std::vector< std::vector< ChainStackTuple > > tank;
186 std::set< LinguisticGraphVertex > alreadyFinished;
187 std::vector<LinguisticGraphVertex> nextVxs;
188// LDEBUG << "Initializing nextVxs with " << start;
189 nextVxs.push_back(start);
190
191
192 while (! ( tank.empty() && nextVxs.empty()) )
193 {
194 if (tank.empty())
195 {
196// LDEBUG << "tank is empty";
197 LinguisticGraphVertex nextVx = nextVxs.back();
198 nextVxs.pop_back();
199 while (alreadyFinished.find(nextVx) != alreadyFinished.end())
200 {
201 if (nextVxs.empty())
202 {
203// LDEBUG << "Nothing more to work on: returning";
204 return;
205 }
206// LDEBUG << "Ignoring next vertex " << nextVx << " because it is already finished.";
207 nextVx = nextVxs.back();
208 nextVxs.pop_back();
209 while ((vertexChainIdMap[nextVx].size() >= m_maxChainsNbByVertex) )
210 {
212 LNOTICE << "Vertex ignored (" << nextVx << ") because there is too much chains on it.";
213// LDEBUG << "Ignoring next vertex " << nextVx << " because there is too much chains on it.";
214 if (nextVxs.empty())
215 {
216// LDEBUG << "Nothing more to work on: returning";
217 return;
218 }
219 nextVx = nextVxs.back();
220 nextVxs.pop_back();
221 }
222 }
223// LDEBUG << "next vertex is " << nextVx;
224 bool canFinish = false;
225 pile.clear();
226// pileSons = std::stack< LinguisticGraphVertex >();
227 if ( (nextVx != first) && (nextVx != last) )
228 {
229// LDEBUG << "next vertex is a nominal chain beginning";
230 canFinish = true;
231 pile.push_back(boost::make_tuple(nextVx, canFinish, std::vector< LinguisticGraphVertex >()));
232 currentType = NOMINAL;
233 }
234 else
235 {
236// LDEBUG << "next vertex " << nextVx << " is not a chain beginning";
237 currentType = NO_CHAIN_TYPE;
238// LDEBUG << "Adding nextVx " << nextVx << " to alreadyFinished";
239// alreadyFinished.insert(nextVx);
240 }
241
242 if (nextVx != stop)
243 {
244 std::vector< LinguisticGraphVertex > sons;
245 LinguisticGraphOutEdgeIt it, it_end;
246 boost::tie(it, it_end) = out_edges(nextVx, *(data->graph()));
247 for (; it != it_end; it++)
248 {
249// LDEBUG << "Looking at the next vertex out edge: " << *it;
250 LinguisticGraphVertex nextNext = target(*it, *(data->graph()));
251 if (nextNext != last)
252 {
253 if ( ( alreadyFinished.find(nextNext) == alreadyFinished.end()) && (currentType != NO_CHAIN_TYPE) )
254 {
255// LDEBUG << "Adding " << nextNext << " to sons of " << nextVx;
256 sons.push_back(nextNext);
257 }
258 else
259 {
260// LDEBUG << "Adding " << nextNext << " to nextVxs";
261 nextVxs.push_back(nextNext);
262 // The addition of the line below seems to solve a loop problem
263 // whithout producing regressions in TVA tests.
264 alreadyFinished.insert(nextVx);
265 }
266 }
267 }
268 if (!sons.empty() && !pile.empty())
269 {
270// LDEBUG << nextVx << " has sons: pushing them to the tank";
271// tank.push_back(std::make_pair(pile, sons));
272 pile.back().get<2>() = sons;
273 tank.push_back(pile);
274 }
275 }
276 }
277 else
278 {
279 LinguisticGraphVertex father = pile.back().get<0>();
280 LinguisticGraphVertex currentSon = pile.back().get<2>().back();
281// LDEBUG << "Father and current son are: " << father << " / " << currentSon;
282 pile.back().get<2>().pop_back();
283 if ( (currentType == NO_CHAIN_TYPE) && (pile.empty()) )
284 {
285 currentType = NOMINAL;
286 }
287
288 if ( currentType != NO_CHAIN_TYPE )
289 {
290// LDEBUG << "Current type is " << currentType;
291 // ------------->
292 // endroit ou mettre le bloc deplace
293 // <-------------
294 if ( currentSon != last )
295 {
296// LDEBUG << father << " -> " << currentSon << " is in the matrix";
297 bool canFinish = true;
298 // bloc ci-dessous a deplacer plus haut pour explorer
299 // toutes les chaines. Pb: rend le parcours tres tres lourd.
300 // ------------->
301 if (!pile.empty() && !pile.back().get<2>().empty())
302 {
303// LDEBUG << father << " has remaining sons: pushing them to the tank";
304// tank.push_back(std::make_pair(pile, pileSons));
305 tank.push_back(pile);
306 }
307 // <-------------
308// LDEBUG << "Pushing " << currentSon << "(" << canFinish << ")";
309 pile.push_back(boost::make_tuple(currentSon, canFinish, std::vector< LinguisticGraphVertex >()));
310 if (currentSon != stop)
311 {
312 std::vector< LinguisticGraphVertex >& sons = pile.back().get<2>();
313 LinguisticGraphOutEdgeIt it, it_end;
314 boost::tie(it, it_end) = out_edges(currentSon, *(data->graph()));
315 for (; it != it_end; it++)
316 {
317// LDEBUG << "Edge is " << *it;
318// LDEBUG << "Adding " << target(*it, *(data->graph())) << " to sons of " << currentSon;
319 sons.push_back(target(*it, *(data->graph())));
320 }
321 }
322 else
323 {
324// LDEBUG << "Stop reached";
325 if (canFinish)
326 {
327// LDEBUG << "currentSon " << currentSon << " is a possible end. Reporting the chain in the graph.";
328 std::string newChainString = stringChain(data, pile, currentType, alreadyFinished,startChainId,currentSon);
329 alreadyReported.insert(newChainString);
330 reportChainInGraph(data, pile, currentType, alreadyFinished,startChainId, currentSon);
331 }
332 else
333 {
334// LDEBUG << "currentSon " << currentSon << " is not a possible end.";
335// LDEBUG << "Trying to find a chain end in the stack";
336 LinguisticGraphVertex lastChainVx = unstackUptoChainEnd(data, pile, currentType);
337 if (lastChainVx!=first) {
338// LDEBUG << "Chain end is " << lastChainVx << ". Reporting the chain in the graph.";
339 std::string newChainString = stringChain(data, pile, currentType, alreadyFinished,startChainId,lastChainVx);
340 alreadyReported.insert(newChainString);
341 reportChainInGraph(data, pile, currentType, alreadyFinished,startChainId,lastChainVx);
342 LinguisticGraphOutEdgeIt it, it_end;
343 boost::tie(it, it_end) = out_edges(lastChainVx, *(data->graph()));
344// LDEBUG << "Initializing for the sons of " << lastChainVx;
345 for (; it != it_end; it++)
346 {
347// LDEBUG << "Looking at an out edge of the chain's last vertex : " << *it;
348 LinguisticGraphVertex nextVx = target(*it, *(data->graph()));
349 if (alreadyFinished.find(nextVx) == alreadyFinished.end())
350 {
351// LDEBUG << "Adding " << nextVx << " to nextVxs";
352 nextVxs.push_back(nextVx);
353 }
354 }
355 }
356// else
357// {
358// LDEBUG << "NoChainEndInStackException catched";
359// }
360 }
361 }
362 }
363 else
364 {
365// LDEBUG << father << " -> " << currentSon << " NOT in the matrix";
366 LinguisticGraphVertex lastChainVx = unstackUptoChainEnd(data, pile, currentType);
367 if (lastChainVx!=first)
368 {
369 std::string newChainString = stringChain(data, pile, currentType, alreadyFinished,startChainId,lastChainVx);
370 if (alreadyReported.find(newChainString) == alreadyReported.end())
371 {
372// LDEBUG << "Reporting chain: " << newChainString;
373 alreadyReported.insert(newChainString);
374 reportChainInGraph(data, pile, currentType, alreadyFinished,startChainId,lastChainVx);
375 LinguisticGraphOutEdgeIt it, it_end;
376 boost::tie(it, it_end) = out_edges(lastChainVx, *(data->graph()));
377// LDEBUG << "Initializing for the sons of " << lastChainVx << " after unstacking";
378 for (; it != it_end; it++)
379 {
380// LDEBUG << "Looking at an out edge of the chain's last vertex : " << *it;
381 LinguisticGraphVertex nextVx = target(*it, *(data->graph()));
382 if (alreadyFinished.find(nextVx) == alreadyFinished.end())
383 {
384// LDEBUG << "Adding " << nextVx << " to nextVxs";
385 nextVxs.push_back(nextVx);
386 }
387 }
388 }
389// else
390// {
391// LDEBUG << "This chain (" << newChainString << ") has already been found. Nothing to do.";
392// }
393 }
394 else
395 {
396// LDEBUG << "No end of chain found in pile";
397 if (alreadyFinished.find(currentSon) == alreadyFinished.end())
398 {
399 if ( parentsFinished(data, father, alreadyFinished ) )
400 {
401// LDEBUG << "Adding father " << father << " to alreadyFinished";
402 alreadyFinished.insert(father);
403 }
404 if (currentSon != last)
405 {
406// LDEBUG << "Adding " << currentSon << " to nextVxs";
407 nextVxs.push_back(currentSon);
408 }
409 else
410 {
411// LDEBUG << "Adding current son " << currentSon << " to alreadyFinished";
412 alreadyFinished.insert(currentSon);
413 }
414 }
415 }
416 }
417 }
418
419 if ( (pile.empty() || pile.back().get<2>().empty()) && (! tank.empty()) )
420 {
421// LDEBUG << "Using a new stack";
422// boost::tie(pile, pileSons) = tank.back();
423 pile = tank.back();
424 tank.pop_back();
425 }
426 }
427 }
428// LDEBUG << "<========= chains search finished";
429}
430
431void SyntacticAnalyzerNoChains::reportChainInGraph(
432 SyntacticData* data,
433 const std::vector< ChainStackTuple >& pile,
435 std::set< LinguisticGraphVertex >& alreadyFinished,
436 uint64_t& chainId,
437 const LinguisticGraphVertex& stop) const
438{
439// SACLOGINIT;
440// LDEBUG << "SyntacticAnalyzerNoChains::reportChainInGraph";
441
442 ChainIdStruct property = ChainIdStruct(type, chainId);
443
444 VertexChainIdPropertyMap vertexChainIdMap = get( vertex_chain_id, *(data->graph()) );
445
446 // std::vector< ChainStackTuple >::const_iterator it, it_end;
447 // it = pile.begin(); it_end = pile.end();
448 // for (; it != it_end; it++)
449 // {
450 // LinguisticGraphVertex current = (*it).get<0>();
451 // if ((vertexChainIdMap[current].size() >= m_maxChainsNbByVertex) )
452 // {
453 // SACLOGINIT;
454 // LNOTICE << "Too much chains on " << current << " ; cannot add a new one.";
455 // return;
456 // }
457 // }
458
459
460 // std::vector< ChainStackTuple >::const_iterator it_beg, it_last;
461 auto it = pile.cbegin(); auto it_beg = pile.cbegin();
462 auto it_end = pile.cend(); auto it_last = --(pile.cend());
463 std::ostringstream oss;
464 for (; it != it_end; it++)
465 {
466 LinguisticGraphVertex current = (*it).get<0>();
467 if (it == it_beg)
468 {
469 if (it_beg == it_last)
470 property = ChainIdStruct(type, chainId, LinguisticAnalysisStructure::UNIGRAM);
471 else
472 property = ChainIdStruct(type, chainId, LinguisticAnalysisStructure::BEGIN);
473 }
474 else if (it == it_last)
475 {
476 property = ChainIdStruct(type, chainId, LinguisticAnalysisStructure::END);
477 }
478 else
479 {
480 property = ChainIdStruct(type, chainId, LinguisticAnalysisStructure::PART);
481 }
482 oss << current;
483 if (current != data->iterator()->firstVertex() && current != data->iterator()->lastVertex()
484 // && (vertexChainIdMap[current].size() < m_maxChainsNbByVertex)
485 )
486 {
487// LDEBUG << "executing: vertexChainIdMap[" << current << "].insert(" << property << ")";
488 vertexChainIdMap[current].insert(property);
489
490 if (pile.size() > 1)
491 {
492 auto it2 = pile.cbegin(); auto it2_end = pile.cend();
493 bool ok = false;
494 for (; it2 != it2_end; it2++)
495 {
496 LinguisticGraphVertex other = (*it2).get<0>();
497 if (other != current)
498 {
499 LinguisticGraphEdge e; bool found;
500 boost::tie (e, found) = edge(current, other, *(data->graph()));
501 if (found)
502 {
503 ok = true;
504 break;
505 }
506 else
507 {
508 boost::tie(e, found) = edge(other, current, *(data->graph()));
509 if (found)
510 {
511 ok = true;
512 break;
513 }
514 }
515 }
516 }
517 if (!ok)
518 {
520 LWARN << "An edge should exist for " << current << " !";
521 }
522 }
523 }
524 // else if (vertexChainIdMap[current].size() >= m_maxChainsNbByVertex)
525 // {
526 // SACLOGINIT;
527 // LNOTICE << "Too much chains on " << current << " ; cannot add a new one.";
528 // }
529 if (current == stop)
530 break;
531 else
532 oss << " ";
533 if (current != data->iterator()->firstVertex() && current != data->iterator()->lastVertex()
534 && (vertexChainIdMap[current].size() < m_maxChainsNbByVertex) )
535 if (parentsFinished(data, current, alreadyFinished))
536 {
537/* LDEBUG << "Parents of " << current << " are finished ; so it too.";
538 alreadyFinished.insert(current);*/
539 }
540 }
541// LDEBUG << "Chain " << chainId << " is : " << (type==NOMINAL?"nominal":"verbal") << " " << oss.str();
542 chainId++;
543 }
544
545bool SyntacticAnalyzerNoChains::parentsFinished(
546 const SyntacticData* data,
547 const LinguisticGraphVertex& v,
548 const std::set< LinguisticGraphVertex >& alreadyFinished) const
549{
550/*
551 Critical function : comment logging messages
552*/
553// SACLOGINIT;
554// LDEBUG << "SyntacticAnalyzerNoChains::parentsFinished";
555
556 LinguisticGraphInEdgeIt it, it_end;
557 boost::tie(it, it_end) = in_edges(v, *(data->graph()));
558 for (; it != it_end; it++)
559 {
560 if (alreadyFinished.find(source(*it, *(data->graph()))) == alreadyFinished.end())
561 return false;
562 }
563 return true;
564}
565
566std::string SyntacticAnalyzerNoChains::stringChain(
567 const SyntacticData* data,
568 const std::vector< ChainStackTuple >& pile,
570 std::set< LinguisticGraphVertex >& alreadyFinished,
571 uint64_t chainId,
572 const LinguisticGraphVertex& stop) const
573{
574/*
575 Critical Function : comment logging messages
576*/
577// SACLOGINIT;
578 ChainIdStruct property = ChainIdStruct(type, chainId);
579
580 std::vector< ChainStackTuple >::const_iterator it, it_beg, it_end, it_last;
581 it = pile.begin(); it_beg = pile.begin();
582 it_end = pile.end(); it_last = --(pile.end());
583 std::ostringstream oss;
584 for (; it != it_end; it++)
585 {
586 if (it == it_beg)
587 {
588 if (it_beg == it_last)
589 property = ChainIdStruct(type, chainId, LinguisticAnalysisStructure::UNIGRAM);
590 else
591 property = ChainIdStruct(type, chainId, LinguisticAnalysisStructure::BEGIN);
592 }
593 else if (it == it_last)
594 {
595 property = ChainIdStruct(type, chainId, LinguisticAnalysisStructure::END);
596 }
597 else
598 {
599 property = ChainIdStruct(type, chainId, LinguisticAnalysisStructure::PART);
600 }
601 oss << (*it).get<0>();
602 LinguisticGraphVertex current = (*it).get<0>();
603 if (current == stop)
604 break;
605 else
606 oss << " ";
607 if (current != data->iterator()->firstVertex() && current != data->iterator()->lastVertex())
608 {
609 if (pile.size() > 1)
610 {
611 std::vector< ChainStackTuple >::const_iterator it2, it2_end;
612 // @todo replace by lookup only previous and next vertex in pile
613 it2 = pile.begin(); it2_end = pile.end();
614 bool ok = false;
615 for (; it2 != it2_end; it2++)
616 {
617 LinguisticGraphVertex other = (*it2).get<0>();
618 if (other != current)
619 {
620 LinguisticGraphEdge e; bool found;
621 boost::tie (e, found) = edge(current, other, *(data->graph()));
622 if (found)
623 {
624 ok = true;
625 break;
626 }
627 else
628 {
629 boost::tie (e, found) = edge(other, current, *(data->graph()));
630 if (found)
631 {
632 ok = true;
633 break;
634 }
635 }
636 }
637 }
638 if (!ok)
639 {
640 SALOGINIT;
641 LWARN << "An edge should exist for " << current << " !";
642 }
643 }
644 }
645 if ( parentsFinished(data, current, alreadyFinished) )
646 {
647// LDEBUG << "Adding current " << current << " to alreadyFinished";
648 alreadyFinished.insert(current);
649 }
650 }
651// LDEBUG << "In stringChain, chain " << chainId << " is : " << (type==NOMINAL?"nominal":"verbal") << " " << oss.str();
652 return oss.str();
653}
654
655LinguisticGraphVertex SyntacticAnalyzerNoChains::unstackUptoChainEnd(
656 const SyntacticData* data,
657 std::vector< ChainStackTuple >& pile,
659 ) const
660{
661/*
662 Critical function : commeng logging messages
663*/
664// SACLOGINIT;
665// LDEBUG << "unstackUptoChainEnd " << (type==NOMINAL?"nominal":(type==VERBAL?"verbal":"none"));
666 CVertexDataPropertyMap dataMap = get( vertex_data, (*data->iterator()->getGraph()) );
667
668 auto rit = pile.rbegin(), rit_end = pile.rend();
669 for (; rit != rit_end; rit++)
670 {
671 if ( data->matrices()->canChainEndBy(dataMap[(*rit).get<0>()], type))
672 break;
673// LDEBUG << "chain cannot finish by " << (*rit).get<0>();
674 }
675
676 if (rit != rit_end)
677 {
678 LinguisticGraphVertex newChainEnd = (*rit).get<0>();
679// LDEBUG << "Chain end found in pile: " << newChainEnd;
680 return (newChainEnd);
681 }
682 else
683 {
684// LDEBUG << "No chain end found in pile !";
685 return data->iterator()->firstVertex();
686 }
687}
688
689} // closing namespace SyntacticAnalysis
690} // closing namespace LinguisticProcessing
691} // closing namespace Lima
#define SACLOGINIT
#define LWARN
Definition LimaCommon.h:160
#define LINFO
Definition LimaCommon.h:158
#define LERROR
Definition LimaCommon.h:161
#define LNOTICE
Definition LimaCommon.h:159
LinguisticGraph::in_edge_iterator LinguisticGraphInEdgeIt
boost::property_map< LinguisticGraph, vertex_data_t >::const_type CVertexDataPropertyMap
boost::property_map< LinguisticGraph, vertex_chain_id_t >::type VertexChainIdPropertyMap
boost::graph_traits< LinguisticGraph >::edge_descriptor LinguisticGraphEdge
typedefs to simplify the access to various graphs elements
LinguisticGraph::vertex_descriptor LinguisticGraphVertex
@ vertex_data
LinguisticGraph::out_edge_iterator LinguisticGraphOutEdgeIt
@ vertex_chain_id
#define SALOGINIT
Defines a Factory to create Object of type Base.
#define SYNTACTICANALYZERNOCHAINS_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.
Holds linguistic data for one language.
const MediaData & mediaData(MediaId media) const
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
const LinguisticGraphVertex & lastVertex(void) const
Returns the last vertex of the graph.
const LinguisticGraph * getGraph(void) const
Returns the underlying graph structure.
const LinguisticGraphVertex & firstVertex(void) const
Returns the first vertex of the graph.
std::shared_ptr< SyntagmDefStruct > m_chainMatrix
A pointer onto the chains definition matrices.
void init(Common::XMLConfigurationFiles::GroupConfigurationStructure &unitConfiguration, Manager *manager) override
Process unit initialization function.
LimaStatusCode process(AnalysisContent &analysis) const override
Process unit main processing function.
void identifyChains(SyntacticData *data, const LinguisticGraphVertex &s, const LinguisticGraphVertex &t, uint64_t &startChainId) const
First step of the syntactic analysis.
uint64_t m_maxChainsNbByVertex
Sets the max number of chains on one vertex.
This class points to a graph, its dependency graph and the structure that holds the maping between th...
std::shared_ptr< SyntagmDefStruct > matrices() const
LinguisticAnalysisStructure::AnalysisGraph * iterator()
static const MediaticData & 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 ...
ChainsType
syntactic chains type
SimpleFactory< MediaProcessUnit, SyntacticAnalyzerNoChains > syntacticAnalyzerNoChainsFactory(SYNTACTICANALYZERNOCHAINS_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.