76 uint64_t
id = currentVertex;
77 std::set< uint64_t> chainsToIgnore;
78 Path initialPath(
id, chainsToIgnore);
79 m_hypsStack.push_front(initialPath);
86 const std::set< ChainIdStruct >& currentVertexChains = chainsMap[currentVertex];
87 uint64_t
id = currentVertex;
88 if (currentVertexChains.empty())
90 std::set< uint64_t> chainsToIgnore;
91 Path initialPath(
id, chainsToIgnore);
95 m_hypsStack.push_front(initialPath);
99 unsigned char type = 1;
100 std::set< ChainIdStruct >::const_iterator currentChainIt, currentChainIt_end;
101 currentChainIt = currentVertexChains.begin();
102 currentChainIt_end = currentVertexChains.end();
103 for (; currentChainIt != currentChainIt_end ; currentChainIt++)
105 std::set< uint64_t> chainsToIgnore;
106 std::set< ChainIdStruct >::const_iterator otherChainIt, otherChainIt_end;
107 otherChainIt = currentVertexChains.begin();
108 otherChainIt_end = currentVertexChains.end();
109 for (; otherChainIt != otherChainIt_end ; otherChainIt++)
111 if (currentChainIt != otherChainIt)
113 chainsToIgnore.insert(otherChainIt->chainId());
116 Path initialPath(
id, chainsToIgnore, type, currentChainIt->chainId());
122 m_hypsStack.push_front(initialPath);
133 while (!m_hypsStack.empty())
136 m_hypsStack.pop_back();
137 Path currentHyp = m_hypsStack.front();
138 m_hypsStack.pop_front();
139 if (currentHyp.
key().
id() == m_tgtVertex)
141 m_completePaths.insert(currentHyp);
145 Key& currentKey = currentHyp.
key();
147 const std::set< ChainIdStruct >& currentVertexChains = chainsMap[currentVertex];
149 const Elem& currentElem = *(currentHyp.
elems().rbegin());
152 boost::tie(it, it_end) = boost::out_edges(currentVertex, *graph);
153 uint64_t branchNum = 0;
154 for (; it != it_end; it++)
156 if (++branchNum >= m_depGraphMaxBranchingFactor)
159 LWARN <<
"Breaking computePaths inner loop on "<<currentVertex<<
" due to excessive branching factor.";
165 if (currentVertex==0 && nextVertex==1)
167 const std::set< ChainIdStruct >& nextVertexChains = chainsMap[nextVertex];
170 if (nextData == 0 || nextData->empty())
173 LWARN <<
"vertex " << nextVertex <<
" has no data";
179 nextMicroCateg = nextData->
firstValue(*m_microAccessor);
182 if ( currentElem.
type() == 0 )
186 if (nextVertexChains.empty())
189 Path newHyp(currentHyp);
190 Key newKey(nextVertex);
191 Elem newElem(nextVertex);
192 newHyp.
elems().push_back(newElem);
194 newHyp.
updateParams(nextMicroCateg,
false,
true, m_language);
195 m_hypsStack.push_front(newHyp);
197 m_hypsStack.pop_back();
200 else if (nextVertexChains.size() == 1)
203 Path newHyp(currentHyp);
204 Key newKey(nextVertex);
205 ChainIdStruct nextVertexChain = (*(nextVertexChains.begin()));
206 uint64_t nextVertexChainId = nextVertexChain.
chainId();
207 Elem newElem(nextVertex);
211 newElem =
Elem(nextVertexChainId, 1);
212 newElem.
elems().push_back(nextVertex);
213 newHyp.
updateParams(nextMicroCateg,
true,
false, m_language);
218 newHyp.
updateParams(nextMicroCateg,
false,
true, m_language);
220 newHyp.
elems().push_back(newElem);
222 m_hypsStack.push_front(newHyp);
224 m_hypsStack.pop_back();
230 startWithSeveralChainsOnNewVertex(nextVertex, nextVertexChains, currentHyp);
236 uint64_t currentElemChainId = currentElem.
id();
238 std::set< ChainIdStruct >::const_iterator currentVertexChainsIt, currentVertexChainsIt_end;
239 currentVertexChainsIt = currentVertexChains.begin();
240 currentVertexChainsIt_end = currentVertexChains.end();
241 for (; currentVertexChainsIt != currentVertexChainsIt_end; currentVertexChainsIt++)
243 if ( (*currentVertexChainsIt).chainId() == currentElemChainId )
245 currentElemChainIdStruct = *currentVertexChainsIt;
249 if (currentVertexChainsIt == currentVertexChainsIt_end)
250 throw std::runtime_error(
"Current elem chain id not found in current elem chains.");
252 if (nextVertexChains.empty())
255 if ( (currentElemChainIdStruct.
elemType() ==
END) ||
259 Path newHyp(currentHyp);
260 Key newKey(nextVertex);
261 Elem newElem(nextVertex);
263 newHyp.
elems().push_back(newElem);
264 newHyp.
updateParams(nextMicroCateg,
false,
true, m_language);
265 m_hypsStack.push_front(newHyp);
267 m_hypsStack.pop_back();
277 Path newHyp(currentHyp);
278 cancelCurrentChain(currentElem, newHyp);
279 Key newKey(nextVertex);
280 Elem newElem(nextVertex);
282 newHyp.
elems().push_back(newElem);
283 newHyp.
updateParams(nextMicroCateg,
false,
true, m_language);
284 m_hypsStack.push_front(newHyp);
286 m_hypsStack.pop_back();
290 else if (nextVertexChains.size() == 1)
298 if ( (*(nextVertexChains.begin())).chainId() == currentElem.
id() )
301 Path newHyp(currentHyp);
302 Key newKey(nextVertex);
303 Elem& newElem = *(newHyp.
elems().rbegin());
304 newElem.
elems().push_back(nextVertex);
306 newHyp.
updateParams(nextMicroCateg,
false,
false, m_language);
307 m_hypsStack.push_front(newHyp);
309 m_hypsStack.pop_back();
316 Path newHyp(currentHyp);
320 if (!( (currentElemChainIdStruct.
elemType() ==
END) ||
325 cancelCurrentChain(currentElem, newHyp);
328 Key newKey(nextVertex);
329 ChainIdStruct nextVertexChain = (*(nextVertexChains.begin()));
330 uint64_t nextVertexChainId = nextVertexChain.
chainId();
331 Elem newElem(nextVertex);
335 newElem =
Elem(nextVertexChainId, 1);
336 newElem.
elems().push_back(nextVertex);
337 newHyp.
updateParams(nextMicroCateg,
true,
false, m_language);
342 newHyp.
updateParams(nextMicroCateg,
false,
true, m_language);
344 newHyp.
elems().push_back(newElem);
346 m_hypsStack.push_front(newHyp);
348 m_hypsStack.pop_back();
360 bool currentChainFound =
false;
361 std::set< uint64_t > nextVertexChainsIdsToIgnore;
362 std::set< ChainIdStruct >::const_iterator nextVertexChainsIt, nextVertexChainsIt_end;
363 nextVertexChainsIt = nextVertexChains.begin();
364 nextVertexChainsIt_end = nextVertexChains.end();
365 for(; nextVertexChainsIt != nextVertexChainsIt_end; nextVertexChainsIt++)
367 if ( (*nextVertexChainsIt).chainId() == currentElem.
id() )
368 currentChainFound =
true;
370 nextVertexChainsIdsToIgnore.insert((*nextVertexChainsIt).chainId());
373 if (currentChainFound)
376 Path newHyp(currentHyp);
377 Key newKey(nextVertex, nextVertexChainsIdsToIgnore);
378 Elem& newElem = *(newHyp.
elems().rbegin());
379 newElem.
elems().push_back(nextVertex);
381 newHyp.
updateParams(nextMicroCateg,
false,
false, m_language);
382 m_hypsStack.push_front(newHyp);
384 m_hypsStack.pop_back();
391 Path newHyp(currentHyp);
395 if (!( (currentElemChainIdStruct.
elemType() ==
END) ||
400 cancelCurrentChain(currentElem, newHyp);
404 startWithSeveralChainsOnNewVertex(nextVertex, nextVertexChains, currentHyp);
411 uint64_t currentElemChainId = currentElem.
id();
413 std::set< ChainIdStruct >::const_iterator currentVertexChainsIt, currentVertexChainsIt_end;
414 currentVertexChainsIt = currentVertexChains.begin();
415 currentVertexChainsIt_end = currentVertexChains.end();
416 for (; currentVertexChainsIt != currentVertexChainsIt_end; currentVertexChainsIt++)
418 if ( (*currentVertexChainsIt).chainId() == currentElemChainId )
420 currentElemChainIdStruct = *currentVertexChainsIt;
424 if (currentVertexChainsIt == currentVertexChainsIt_end)
425 throw std::runtime_error(
"Current elem chain id not found in current elem chains.");
427 if (nextVertexChains.empty())
431 if ( (currentElemChainIdStruct.
elemType() ==
END) ||
435 Path newHyp(currentHyp);
437 Elem newElem(nextVertex);
439 newHyp.
elems().push_back(newElem);
440 newHyp.
updateParams(nextMicroCateg,
false,
true, m_language);
441 m_hypsStack.push_front(newHyp);
443 m_hypsStack.pop_back();
451 Path newHyp(currentHyp);
452 cancelCurrentChain(currentElem, newHyp);
455 Elem newElem(nextVertex);
457 newHyp.
elems().push_back(newElem);
458 newHyp.
updateParams(nextMicroCateg,
false,
true, m_language);
459 m_hypsStack.push_front(newHyp);
461 m_hypsStack.pop_back();
465 else if (nextVertexChains.size() == 1)
473 if ( (*(nextVertexChains.begin())).chainId() == currentElem.
id() )
476 Path newHyp(currentHyp);
477 Key newKey(nextVertex);
478 Elem& newElem = *(newHyp.
elems().rbegin());
479 newElem.
elems().push_back(nextVertex);
481 newHyp.
updateParams(nextMicroCateg,
false,
false, m_language);
482 m_hypsStack.push_front(newHyp);
484 m_hypsStack.pop_back();
492 Path newHyp(currentHyp);
496 if (!( (currentElemChainIdStruct.
elemType() ==
END) ||
500 cancelCurrentChain(currentElem, newHyp);
510 ChainIdStruct nextVertexChain = (*(nextVertexChains.begin()));
511 uint64_t nextVertexChainId = nextVertexChain.
chainId();
512 Elem newElem(nextVertex);
517 newElem =
Elem(nextVertexChainId, 1);
518 newElem.
elems().push_back(nextVertex);
519 newHyp.
updateParams(nextMicroCateg,
true,
false, m_language);
524 newHyp.
updateParams(nextMicroCateg,
false,
true, m_language);
526 newHyp.
elems().push_back(newElem);
528 m_hypsStack.push_front(newHyp);
530 m_hypsStack.pop_back();
541 bool currentChainFound =
false;
542 std::set< uint64_t > nextVertexChainsIdsToIgnore = currentKey.
chainsToIgnore();
543 std::set< ChainIdStruct >::const_iterator nextVertexChainsIt, nextVertexChainsIt_end;
544 nextVertexChainsIt = nextVertexChains.begin();
545 nextVertexChainsIt_end = nextVertexChains.end();
546 for(; nextVertexChainsIt != nextVertexChainsIt_end; nextVertexChainsIt++)
548 if ( (*nextVertexChainsIt).chainId() == currentElem.
id() )
549 currentChainFound =
true;
551 nextVertexChainsIdsToIgnore.insert((*nextVertexChainsIt).chainId());
554 if (currentChainFound)
557 Path newHyp(currentHyp);
558 Key newKey(nextVertex, nextVertexChainsIdsToIgnore);
559 Elem& newElem = *(newHyp.
elems().rbegin());
560 newElem.
elems().push_back(nextVertex);
562 newHyp.
updateParams(nextMicroCateg,
false,
false, m_language);
563 m_hypsStack.push_front(newHyp);
565 m_hypsStack.pop_back();
573 Path newHyp(currentHyp);
577 if (!( (currentElemChainIdStruct.
elemType() ==
END) ||
580 cancelCurrentChain(currentElem, newHyp);
583 startWithSeveralChainsOnNewVertex(nextVertex, nextVertexChains, newHyp);
672 if (m_completePaths.empty())
return;
673 std::set< Path > updatedPaths;
674 std::multiset< Path >::const_iterator pathsIt, pathsIt_end;
675 pathsIt = m_completePaths.begin();
676 pathsIt_end = m_completePaths.end();
677 for (; pathsIt != pathsIt_end ; pathsIt++)
679 Path path = *pathsIt;
680 uint64_t nb = computeDepsNb(path);
683 updatedPaths.insert(path);
685 const Path& selectedPath = *(updatedPaths.begin());
687 std::set< LinguisticGraphVertex > selectedVertices;
688 std::list< Elem >::const_iterator it, it_end;
689 it = selectedPath.
elems().begin();
690 it_end = selectedPath.
elems().end();
691 for (; it != it_end; it++)
693 const Elem& elem = *it;
694 if (elem.
type() == 0)
695 selectedVertices.insert(elem.
id());
698 std::vector< uint64_t >::const_iterator elit, elit_end;
699 elit = elem.
elems().begin();
700 elit_end = elem.
elems().end();
701 for (; elit != elit_end; elit++)
703 selectedVertices.insert(*elit);
709 std::list< LinguisticGraphVertex > verticesToExplore;
710 std::set< LinguisticGraphVertex > scheduledVertices;
711 verticesToExplore.push_back(m_srcVertex);
712 scheduledVertices.insert(m_srcVertex);
715 while (! verticesToExplore.empty() )
718 verticesToExplore.pop_front();
720 boost::tie(it, it_end) = boost::out_edges(currentVertex, graph);
721 for (; it != it_end; it++)
724 if ( (nextVertex != m_tgtVertex) && (nextVertex != 1) &&
725 (scheduledVertices.find(nextVertex) == scheduledVertices.end() ) )
727 scheduledVertices.insert(nextVertex);
728 verticesToExplore.push_back(nextVertex);
731 if (selectedVertices.find(currentVertex) == selectedVertices.end())
735 boost::clear_vertex(currentVertex, graph);
744 it = selectedPath.
elems().begin();
745 it_end = selectedPath.
elems().end();
746 for (; it != it_end; it++)
748 const Elem& elem = *it;
749 if (elem.
type() == 0)
752 chainsMap[currentVertex] = std::set< ChainIdStruct >();
772 uint64_t chainId = elem.
id();
774 std::set< ChainIdStruct >& currentVertexChains = chainsMap[currentVertex];
776 std::set< ChainIdStruct >::const_iterator currentVertexChainsIt, currentVertexChainsIt_end;
777 currentVertexChainsIt = currentVertexChains.begin();
778 currentVertexChainsIt_end = currentVertexChains.end();
779 for (; currentVertexChainsIt != currentVertexChainsIt_end; currentVertexChainsIt++)
781 if ( (*currentVertexChainsIt).chainId() == chainId)
783 cisToKeep = *currentVertexChainsIt;
788 throw std::runtime_error(
"Selected chain not found on current vertex");
789 std::vector< uint64_t >::const_iterator elit, elit_end;
790 elit = elem.
elems().begin();
791 elit_end = elem.
elems().end();
792 for (; elit != elit_end; elit++)
794 std::set< ChainIdStruct > newCurrentVertexChains;
796 if (elem.
elems().size() == 1)
798 else if (elit == elem.
elems().begin())
800 else if ( (elit+1) == elem.
elems().end())
804 newCurrentVertexChains.insert(cisToKeepCopy);
805 chainsMap[*elit] = newCurrentVertexChains;
809 boost::tie(dit, dit_end) = boost::out_edges(currentDepVertex, depGraph);
810 std::list< LinguisticGraphEdge > edgesToRemove;
811 while (dit != dit_end)
820 std::list< LinguisticGraphEdge >::iterator itr, itr_end;
821 itr = edgesToRemove.begin(); itr_end = edgesToRemove.end();
822 for (; itr != itr_end; itr++)
824 remove_edge(*itr, depGraph);