36namespace LinguisticProcessing
38namespace SyntacticAnalysis
49 m_maxChainsNbByVertex(
std::numeric_limits<uint64_t>::max())
68 LERROR <<
"no parameter 'chainMatrix' in SyntacticAnalyzerChains group for language " << (int)
m_language <<
" !";
73 std::string maxChainsNbByVertexS=unitConfiguration.
getParamsValueAtKey(
"maxChainsNbByVertex");
74 std::istringstream iss(maxChainsNbByVertexS);
85 std::istringstream iss(maxChainLengthS);
100 LWARN <<
"No ponctu macrocategory defined ! use category PONCTU";
111 LINFO <<
"start syntactic analysis - nochains";
113 auto anagraph = std::dynamic_pointer_cast<AnalysisGraph>(analysis.
getData(
"PosGraph"));
116 LERROR <<
"no PosGraph ! abort";
119 auto sb = std::dynamic_pointer_cast<SegmentationData>(analysis.
getData(
"SentenceBoundaries"));
122 LERROR <<
"no sentence bounds ! abort";
125 if (sb->getGraphId() !=
"PosGraph") {
126 LERROR <<
"SentenceBounds have been computed on " << sb->getGraphId() <<
" !";
127 LERROR <<
"SyntacticAnalyzer-deps needs SentenceBounds on PosGraph";
131 auto syntacticData = std::dynamic_pointer_cast<SyntacticData>(analysis.
getData(
"SyntacticData"));
132 if (syntacticData==0)
134 syntacticData= std::make_shared<SyntacticData>(anagraph.get(),
m_chainMatrix);
135 analysis.
setData(
"SyntacticData",syntacticData);
137 else if (syntacticData->matrices() == 0)
141 syntacticData->setupDependencyGraph();
143 uint64_t chainId = m_firstChainId;
144 std::list<LinguisticCode> ponctuMacroFilter;
150 for (std::vector<Segment>::const_iterator boundItr=(sb->getSegments()).begin();
151 boundItr!=(sb->getSegments()).end();
156 identifyChains(syntacticData.get(), beginSentence, endSentence, chainId);
157 beginSentence=endSentence;
160 LINFO <<
"end syntactic analysis - nochains";
168 uint64_t& startChainId)
const
175 std::set< std::string > alreadyReported;
181 std::vector< ChainStackTuple > pile;
185 std::vector< std::vector< ChainStackTuple > > tank;
186 std::set< LinguisticGraphVertex > alreadyFinished;
187 std::vector<LinguisticGraphVertex> nextVxs;
189 nextVxs.push_back(start);
192 while (! ( tank.empty() && nextVxs.empty()) )
199 while (alreadyFinished.find(nextVx) != alreadyFinished.end())
207 nextVx = nextVxs.back();
212 LNOTICE <<
"Vertex ignored (" << nextVx <<
") because there is too much chains on it.";
219 nextVx = nextVxs.back();
224 bool canFinish =
false;
227 if ( (nextVx != first) && (nextVx != last) )
231 pile.push_back(boost::make_tuple(nextVx, canFinish, std::vector< LinguisticGraphVertex >()));
244 std::vector< LinguisticGraphVertex > sons;
246 boost::tie(it, it_end) = out_edges(nextVx, *(data->
graph()));
247 for (; it != it_end; it++)
251 if (nextNext != last)
253 if ( ( alreadyFinished.find(nextNext) == alreadyFinished.end()) && (currentType !=
NO_CHAIN_TYPE) )
256 sons.push_back(nextNext);
261 nextVxs.push_back(nextNext);
264 alreadyFinished.insert(nextVx);
268 if (!sons.empty() && !pile.empty())
272 pile.back().get<2>() = sons;
273 tank.push_back(pile);
282 pile.back().get<2>().pop_back();
294 if ( currentSon != last )
297 bool canFinish =
true;
301 if (!pile.empty() && !pile.back().get<2>().empty())
305 tank.push_back(pile);
309 pile.push_back(boost::make_tuple(currentSon, canFinish, std::vector< LinguisticGraphVertex >()));
310 if (currentSon != stop)
312 std::vector< LinguisticGraphVertex >& sons = pile.back().get<2>();
314 boost::tie(it, it_end) = out_edges(currentSon, *(data->
graph()));
315 for (; it != it_end; it++)
319 sons.push_back(target(*it, *(data->
graph())));
328 std::string newChainString = stringChain(data, pile, currentType, alreadyFinished,startChainId,currentSon);
329 alreadyReported.insert(newChainString);
330 reportChainInGraph(data, pile, currentType, alreadyFinished,startChainId, currentSon);
337 if (lastChainVx!=first) {
339 std::string newChainString = stringChain(data, pile, currentType, alreadyFinished,startChainId,lastChainVx);
340 alreadyReported.insert(newChainString);
341 reportChainInGraph(data, pile, currentType, alreadyFinished,startChainId,lastChainVx);
343 boost::tie(it, it_end) = out_edges(lastChainVx, *(data->
graph()));
345 for (; it != it_end; it++)
349 if (alreadyFinished.find(nextVx) == alreadyFinished.end())
352 nextVxs.push_back(nextVx);
367 if (lastChainVx!=first)
369 std::string newChainString = stringChain(data, pile, currentType, alreadyFinished,startChainId,lastChainVx);
370 if (alreadyReported.find(newChainString) == alreadyReported.end())
373 alreadyReported.insert(newChainString);
374 reportChainInGraph(data, pile, currentType, alreadyFinished,startChainId,lastChainVx);
376 boost::tie(it, it_end) = out_edges(lastChainVx, *(data->
graph()));
378 for (; it != it_end; it++)
382 if (alreadyFinished.find(nextVx) == alreadyFinished.end())
385 nextVxs.push_back(nextVx);
397 if (alreadyFinished.find(currentSon) == alreadyFinished.end())
399 if ( parentsFinished(data, father, alreadyFinished ) )
402 alreadyFinished.insert(father);
404 if (currentSon != last)
407 nextVxs.push_back(currentSon);
412 alreadyFinished.insert(currentSon);
419 if ( (pile.empty() || pile.back().get<2>().empty()) && (! tank.empty()) )
431void SyntacticAnalyzerNoChains::reportChainInGraph(
433 const std::vector< ChainStackTuple >& pile,
435 std::set< LinguisticGraphVertex >& alreadyFinished,
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++)
469 if (it_beg == it_last)
474 else if (it == it_last)
488 vertexChainIdMap[current].insert(property);
492 auto it2 = pile.cbegin();
auto it2_end = pile.cend();
494 for (; it2 != it2_end; it2++)
497 if (other != current)
500 boost::tie (e, found) = edge(current, other, *(data->
graph()));
508 boost::tie(e, found) = edge(other, current, *(data->
graph()));
520 LWARN <<
"An edge should exist for " << current <<
" !";
535 if (parentsFinished(data, current, alreadyFinished))
545bool SyntacticAnalyzerNoChains::parentsFinished(
548 const std::set< LinguisticGraphVertex >& alreadyFinished)
const
557 boost::tie(it, it_end) = in_edges(v, *(data->
graph()));
558 for (; it != it_end; it++)
560 if (alreadyFinished.find(source(*it, *(data->
graph()))) == alreadyFinished.end())
566std::string SyntacticAnalyzerNoChains::stringChain(
568 const std::vector< ChainStackTuple >& pile,
570 std::set< LinguisticGraphVertex >& alreadyFinished,
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++)
588 if (it_beg == it_last)
593 else if (it == it_last)
601 oss << (*it).get<0>();
611 std::vector< ChainStackTuple >::const_iterator it2, it2_end;
613 it2 = pile.begin(); it2_end = pile.end();
615 for (; it2 != it2_end; it2++)
618 if (other != current)
621 boost::tie (e, found) = edge(current, other, *(data->
graph()));
629 boost::tie (e, found) = edge(other, current, *(data->
graph()));
641 LWARN <<
"An edge should exist for " << current <<
" !";
645 if ( parentsFinished(data, current, alreadyFinished) )
648 alreadyFinished.insert(current);
657 std::vector< ChainStackTuple >& pile,
668 auto rit = pile.rbegin(), rit_end = pile.rend();
669 for (; rit != rit_end; rit++)
671 if ( data->
matrices()->canChainEndBy(dataMap[(*rit).get<0>()], type))
680 return (newChainEnd);
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
LinguisticGraph::out_edge_iterator LinguisticGraphOutEdgeIt
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.
std::string & getParamsValueAtKey(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.
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.
Property to identify the chains in the graph.
MediaId m_language
The language of the analyzed text.
uint64_t m_maxChainLength
Sets the max length of a chain.
const Common::PropertyCode::PropertyAccessor * m_microAccessor
LinguisticCode m_ponctuCategory
std::shared_ptr< SyntagmDefStruct > m_chainMatrix
A pointer onto the chains definition matrices.
SyntacticAnalyzerNoChains()
Default constructor.
void init(Common::XMLConfigurationFiles::GroupConfigurationStructure &unitConfiguration, Manager *manager) override
Process unit initialization function.
const Common::PropertyCode::PropertyAccessor * m_macroAccessor
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
LinguisticGraph * graph()
LinguisticAnalysisStructure::AnalysisGraph * iterator()
static const MediaticData & single()
const singleton accessor
This file contains a class to control log of informations about time, such as logging cumulated time ...
static const uint64_t DEFAULT_MAXCHAINSNBBYVERTEX
static const uint64_t DEFAULT_MAXCHAINLENGTH
SimpleFactory< MediaProcessUnit, SyntacticAnalyzerNoChains > syntacticAnalyzerNoChainsFactory(SYNTACTICANALYZERNOCHAINS_CLASSID)