24namespace LinguisticProcessing
43 m_verticesToRemove(d.m_verticesToRemove),
44 m_resultData(d.m_resultData),
45 m_currentSentence(d.m_currentSentence),
46 m_nextVertices(d.m_nextVertices),
47 m_entityFeatures(d.m_entityFeatures)
64 AnalysisData::operator=(d);
65 m_verticesToRemove=d.m_verticesToRemove;
66 m_resultData=d.m_resultData;
67 m_currentSentence=d.m_currentSentence;
68 m_nextVertices = d.m_nextVertices;
69 m_entityFeatures = d.m_entityFeatures;
80 if (m_resultData!=0) {
81 m_resultData->push_back(std::vector< Automaton::RecognizerMatch >());
88 for (RecognizerMatch::const_iterator m(result.begin());
93 if (m_verticesToRemove.find((*m).getVertex()) !=
94 m_verticesToRemove.end())
109 for (RecognizerMatch::const_iterator match(result.begin());
110 match!=result.end(); match++)
112 if ((*match).isKept())
116 m_verticesToRemove.insert((*match).getVertex());
119 std::queue<LinguisticGraphVertex> verticesToCheck;
120 verticesToCheck.push((*match).getVertex());
121 while (! verticesToCheck.empty())
126 boost::tie(it_begin,it_end)=in_edges(verticesToCheck.front(),*graph);
131 bool vertexToRemove(
false);
132 if (out_degree(previousVertex,*graph)==1)
140 boost::tie(it_out_begin,it_out_end)=out_edges(previousVertex,*graph);
144 if (m_verticesToRemove.find(target(*it_out,*graph))==
145 m_verticesToRemove.end())
147 vertexToRemove=
false;
152 if (vertexToRemove &&
153 m_verticesToRemove.find(previousVertex)==
154 m_verticesToRemove.end())
157 m_verticesToRemove.insert(previousVertex);
158 verticesToCheck.push(previousVertex);
165 verticesToCheck.pop();
169 verticesToCheck.push((*match).getVertex());
170 while (! verticesToCheck.empty())
175 boost::tie(it_begin,it_end)=out_edges(verticesToCheck.front(),*graph);
179 bool vertexToRemove(
false);
180 if (in_degree(nextVertex,*graph)==1)
188 boost::tie(it_in_begin,it_in_end)=in_edges(nextVertex,*graph);
191 if (m_verticesToRemove.find(source(*it_in,*graph))== m_verticesToRemove.end())
193 vertexToRemove=
false;
198 if (vertexToRemove &&
199 m_verticesToRemove.find(nextVertex)==
200 m_verticesToRemove.end())
202 m_verticesToRemove.insert(nextVertex);
203 verticesToCheck.push(nextVertex);
206 verticesToCheck.pop();
222 LDEBUG <<
"RecognizerData: removing vertices";
225 for (set<LinguisticGraphVertex>::const_reverse_iterator
226 it=m_verticesToRemove.rbegin();
227 it!=m_verticesToRemove.rend(); it++)
230 LDEBUG <<
" clearing vertex " << *it;
244 if (m_resultData==0) {
246 LERROR <<
"RecognizerData: cannot add result: missing data";
249 m_resultData->
insert(result,m_currentSentence);
256 LDEBUG <<
"RecognizerData: removing edges to remove";
261 std::set< std::pair<LinguisticGraphVertex, LinguisticGraphVertex> >::const_iterator it, it_end;
262 it = m_edgesToRemove.begin(); it_end = m_edgesToRemove.end();
263 for (; it != it_end; it++)
266 LDEBUG <<
"RecognizerData::removeEdges removing edge " << (*it).first <<
" - " << (*it).second;
268 boost::remove_edge((*it).first,(*it).second, g);
272 m_edgesToRemove.clear();
283 std::pair<LinguisticGraphVertex, LinguisticGraphVertex> p = std::make_pair(source(e,g),target(e,g));
284 m_edgesToRemove.insert(p);
289 return (m_edgesToRemove.find(std::make_pair(s,t)) != m_edgesToRemove.end());
297 std::set< std::pair<LinguisticGraphVertex, LinguisticGraphVertex > >& storedEdges)
301 LDEBUG <<
"RecognizerData: clearing unreachable vertices from " << from <<
" and to " << to;
303 std::deque< std::deque< LinguisticGraphVertex > > paths;
304 std::deque< LinguisticGraphVertex > current;
305 std::set< std::pair<LinguisticGraphVertex, LinguisticGraphVertex > > validated;
311 current.push_back(from);
312 paths.push_back(current);
313 while (!paths.empty())
315 current = paths.front();
317 if (current.empty())
continue;
319 boost::tie(it_out,it_out_end)=out_edges(current.back(),g);
320 if (it_out == it_out_end)
324 if (tgt == 1)
continue;
326 while (!current.empty())
330 std::pair< LinguisticGraphVertex, LinguisticGraphVertex > p = std::make_pair(src,tgt);
331 if (storedEdges.find(p) == storedEdges.end())
334 LDEBUG <<
"RecognizerData::clearUnreachableVertices removing edge " << src <<
" -> " << tgt;
336 remove_edge(edge(src,tgt,g).first,g);
343 for (; it_out != it_out_end; it_out++)
345 std::pair< LinguisticGraphVertex, LinguisticGraphVertex > p = std::make_pair(source(*it_out,g),source(*it_out,g));
346 if ( (target(*it_out,g) == to)
347 || (validated.find(p) != validated.end()) )
352 while (!current.empty())
356 validated.insert(std::make_pair(src,tgt));
362 std::deque< LinguisticGraphVertex > newpath = current;
363 newpath.push_back(target(*it_out,g));
364 paths.push_front(newpath);
378 LDEBUG <<
"RecognizerData: clearing unreachable vertices from " << from;
385 std::queue<LinguisticGraphVertex> verticesToCheck;
386 verticesToCheck.push( from );
387 while (! verticesToCheck.empty() )
390 LDEBUG <<
" vertices to check size = " << verticesToCheck.size();
393 verticesToCheck.pop();
394 bool toClear =
false;
396 LDEBUG <<
" out degree of " << v <<
" is " << out_degree(v, g);
398 if (out_degree(v, g) == 0 && v != anagraph->
lastVertex())
402 boost::tie(it,it_end)=in_edges(v,g);
403 for (; it!=it_end; it++)
405 verticesToCheck.push(source(*it,g));
409 LDEBUG <<
" in degree of " << v <<
" is " << in_degree(v, g);
411 if (in_degree(v, g) == 0 && v != anagraph->
firstVertex())
415 boost::tie(it,it_end)=out_edges(v,g);
416 for (; it!=it_end; it++)
418 verticesToCheck.push(target(*it,g));
424 LDEBUG <<
" clearing vertex " << v;
439 if (m_resultData != 0) {
449 m_entityFeatures.clear();
459 m_graphId(sourceGraph)
463 push_back(std::vector< Automaton::RecognizerMatch >());
470 m_graphId(d.m_graphId)
481 AnalysisData::operator=(d);
482 std::vector<std::vector< Automaton::RecognizerMatch > >::operator=(d);
483 m_graphId=d.m_graphId;
490 const uint64_t sentenceId)
492 if (sentenceId>= size()) {
494 LERROR <<
"RecognizerResultData: try to access data oustide of vector (sentenceId=" << sentenceId <<
",size=" << size() <<
")";
497 (*this)[sentenceId].push_back(m);
LinguisticGraph::in_edge_iterator LinguisticGraphInEdgeIt
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
boost::adjacency_list< boost::vecS, boost::vecS, boost::bidirectionalS, LinguisticVertexProperties > LinguisticGraph
Property to identify the chains in the graph.
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
just for semantics: base class for analysisData
virtual ~RecognizerData()
void addResult(const Automaton::RecognizerMatch &result)
void storeVerticesToRemove(const Automaton::RecognizerMatch &result, LinguisticGraph *graph)
void removeEdges(AnalysisContent &analysis)
void clearUnreachableVertices(AnalysisContent &analysis, LinguisticGraphVertex from, LinguisticGraphVertex to, std::set< std::pair< LinguisticGraphVertex, LinguisticGraphVertex > > &storedEdges)
remove edges linked to vertices that have no path between from and to excepted those in storedEdges
void clearEntityFeatures()
void setResultData(RecognizerResultData *data)
bool isEdgeToBeRemoved(LinguisticGraphVertex s, LinguisticGraphVertex t) const
void removeVertices(AnalysisContent &analysis) const
void setEdgeToBeRemoved(AnalysisContent &analysis, LinguisticGraphEdge e)
bool matchOnRemovedVertices(const Automaton::RecognizerMatch &result) const
RecognizerResultData(const std::string &sourceGraph)
RecognizerResultData & operator=(const RecognizerResultData &)
void insert(const Automaton::RecognizerMatch &m, const uint64_t sentenceId=0)
const std::string & getGraphId() const
␈rief A class for the description of automata
An AnalysisData containing a LinguisticGraph with a language and an id.
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.
SimpleFactory< MediaProcessUnit, ApplyRecognizer > ApplyRecognizer(APPLYRECOGNIZER_CLASSID)