26using namespace Common;
27using namespace Common::AnnotationGraphs;
29namespace LinguisticProcessing
31using namespace LinguisticAnalysisStructure;
32using namespace SyntacticAnalysis;
56 std::vector< DependencyGraphVertex > getNodes(
const std::vector< DependencyGraphEdge >& relations);
59 std::map< uint64_t, std::set< uint64_t > > computeExclusions(
60 const std::vector< DependencyGraphEdge >& relations);
63 std::map< uint64_t, bool > computeSizes();
66 std::vector< uint64_t > computeOrder(
const std::map< uint64_t, std::set< uint64_t > >& exclusions);
69 void buildTermsFromCompoundsSets(std::list< std::set< uint64_t > >& compoundsSets);
74 const std::set< uint64_t > relations,
75 bool theHead =
false);
86 std::vector< DependencyGraphEdge > getCompoundsRelationsFromWithChain(
90 std::map< uint64_t, std::set< uint64_t > > computeExclusionsWithChain(
91 const std::vector< DependencyGraphEdge >& relations,
94 std::vector< DependencyGraphEdge > getCompoundsRelationsFromNoChain(
97 std::map< uint64_t, std::set< uint64_t > > computeExclusionsNoChain(
98 const std::vector< DependencyGraphEdge >& relations);
107 std::set< DependencyGraphVertex > m_visited;
108 std::set< std::pair< DependencyGraphVertex, LinguisticAnalysisStructure::ChainIdStruct > > m_visitedWithChains;
109 std::set< std::string > m_alreadyInserted;
127 std::vector< boost::tuple<uint64_t,DependencyGraphVertex, std::set<uint64_t> > > m_nodesmap;
130DepGraphCompoundsBuildVisitorPrivate::DepGraphCompoundsBuildVisitorPrivate(
const
131 CompoundsBuilderFromSyntacticData* cpbfsd,
140 m_language(language),
141 m_syntacticData(syntacticData),
142 m_depFailedVertex(syntacticData->depVertexForTokenVertex(iter->firstVertex())),
144 m_depGraph(depGraph),
146 m_annotationData(annotationData)
150 if (m_annotationData->
dumpFunction(
"CompoundTokenAnnotation") == 0)
185 LDEBUG <<
"DepGraphCompoundsBuildVisitor::discover_vertex" << v;
187 if ( (v != m_d->m_syntacticData-> iterator()-> firstVertex()) &&
188 (v != m_d->m_syntacticData-> iterator()-> lastVertex()) )
191 if (m_d->m_visited.find(vd) == m_d->m_visited.end())
193 m_d->buildCompatibilityTermsFromNoChains(vd);
198 LDEBUG <<
"DepGraphCompoundsBuildVisitor::discover_vertex" << v <<
"already visited";
205 LDEBUG <<
"DepGraphCompoundsBuildVisitor::discover_vertex" << v <<
"is first or last vertex";
210void DepGraphCompoundsBuildVisitorPrivate::buildCompatibilityTermsFromWithChains(
DependencyGraphVertex from)
215 LDEBUG <<
"Building compatibility terms with chains from " << from;
219 VertexChainIdProp::const_iterator fromChainsIt, fromChainsIt_end;
220 fromChainsIt = chainsMap[fromTokVertex].begin(); fromChainsIt_end = chainsMap[fromTokVertex].end();
221 for (; fromChainsIt != fromChainsIt_end; fromChainsIt++)
224 LDEBUG <<
"Building compatibility terms with chains from " << from <<
" on chain " << *fromChainsIt;
226 if (m_visitedWithChains.find(std::make_pair(from,*fromChainsIt)) == m_visitedWithChains.end())
229 std::vector< DependencyGraphEdge > relations = getCompoundsRelationsFromWithChain(from, *fromChainsIt);
231 LDEBUG <<
"Got " << relations.size() <<
" compound relations";
233 std::vector< DependencyGraphVertex > nodes = getNodes(relations);
235 LDEBUG <<
"Got " << nodes.size() <<
" compound nodes";
238 std::map< uint64_t, std::set< uint64_t > > exclusions = computeExclusionsWithChain(relations, *fromChainsIt);
240 LDEBUG <<
"Got " << exclusions.size() <<
" exclusions";
243 std::map< uint64_t, bool > sizes = computeSizes();
245 LDEBUG <<
"Got " << sizes.size() <<
" sizes";
248 std::vector< uint64_t > order = computeOrder(exclusions);
250 LDEBUG <<
"Got " << order.size() <<
" order elements";
256 LDEBUG <<
"Got " << compoundsSets.size() <<
" compounds sets" ;
258 std::list< std::set< uint64_t > >::const_iterator compsIt, compsIt_end;
259 compsIt = compoundsSets.begin(); compsIt_end = compoundsSets.end();
260 for (; compsIt != compsIt_end; compsIt++)
262 std::set< uint64_t >::const_iterator compIt, compIt_end;
263 compIt = (*compsIt).begin(); compIt_end = (*compsIt).end();
264 for (; compIt != compIt_end; compIt++)
278 LDEBUG <<
"Building terms from compatibility results";
280 buildTermsFromCompoundsSets(compoundsSets);
284 LDEBUG <<
"Finished Building compatibility terms with chains from " << from;
288void DepGraphCompoundsBuildVisitorPrivate::buildCompatibilityTermsFromNoChains(
294 LDEBUG <<
"Building compatibility terms no chains from " << from;
298 LDEBUG <<
"Building compatibility terms no chains from " << from ;
302 std::vector< DependencyGraphEdge > relations = getCompoundsRelationsFromNoChain(from);
304 LDEBUG <<
"Got " << relations.size() <<
" compound relations";
306 std::vector< DependencyGraphVertex > nodes = getNodes(relations);
308 LDEBUG <<
"Got " << nodes.size() <<
" compound nodes";
311 std::map< uint64_t, std::set< uint64_t > > exclusions = computeExclusionsNoChain(relations);
313 LDEBUG <<
"Got " << exclusions.size() <<
" exclusions";
316 std::map< uint64_t, bool > sizes = computeSizes();
318 LDEBUG <<
"Got " << sizes.size() <<
" sizes";
321 std::vector< uint64_t > order = computeOrder(exclusions);
323 LDEBUG <<
"Got " << order.size() <<
" order elements";
326 CompoundsCompatibilityBuilder builder;
329 LDEBUG <<
"Got " << compoundsSets.size() <<
" compounds sets" ;
331 std::list< std::set< uint64_t > >::const_iterator compsIt, compsIt_end;
332 compsIt = compoundsSets.begin(); compsIt_end = compoundsSets.end();
333 for (; compsIt != compsIt_end; compsIt++)
335 std::set< uint64_t >::const_iterator compIt, compIt_end;
336 compIt = (*compsIt).begin(); compIt_end = (*compsIt).end();
337 for (; compIt != compIt_end; compIt++)
351 LDEBUG <<
"Building terms from compatibility results";
353 buildTermsFromCompoundsSets(compoundsSets);
357 LDEBUG <<
"Finished Building compatibility terms no chains from " << from;
362void DepGraphCompoundsBuildVisitorPrivate::buildTermsFromCompoundsSets(
363 std::list< std::set< uint64_t > >& compoundsSets)
369 for (
auto currentSet: compoundsSets)
376 LWARN <<
"No final source of compound found => no term built here.";
380 buildTermFor(head,currentSet,
true);
385bool DepGraphCompoundsBuildVisitorPrivate::isDepEdgeACompoundNounRelation(
const DependencyGraphEdge& e)
const
395 LDEBUG <<
"isDepEdgeACompoundNounRelation: Relation name" << relName;
401 LERROR <<
"Unknown type " << relType
402 <<
" while testing edge for compound relation.";
415std::vector< DependencyGraphVertex > DepGraphCompoundsBuildVisitorPrivate::getNodes(
416 const std::vector< DependencyGraphEdge >& relations)
423 std::vector< DependencyGraphVertex > nodes;
424 std::set< DependencyGraphVertex > snodes;
425 std::vector< DependencyGraphEdge >::const_iterator it, it_end;
426 it = relations.begin(); it_end = relations.end();
427 for (; it != it_end; it++)
429 if (snodes.find(source(*it, *m_depGraph)) == snodes.end())
431 snodes.insert(source(*it, *m_depGraph));
432 nodes.push_back(source(*it, *m_depGraph));
434 if (snodes.find(target(*it, *m_depGraph)) == snodes.end())
436 snodes.insert(target(*it, *m_depGraph));
437 nodes.push_back(target(*it, *m_depGraph));
444std::map< uint64_t, std::set< uint64_t > > DepGraphCompoundsBuildVisitorPrivate::computeExclusions(
445 const std::vector< DependencyGraphEdge >& relations)
449 LDEBUG <<
"Computing exclusions";
451 std::map< uint64_t, std::set< uint64_t > > exclusions;
456 std::vector< DependencyGraphEdge >::const_iterator relsit, relsit_end;
457 relsit = relations.begin(); relsit_end = relations.end();
459 for (; relsit != relsit_end; relsit++)
467 uint64_t srcPos = srcToken->position();
468 uint64_t tgtPos = tgtToken->position();
469 std::set<uint64_t> srcChains;
470 VertexChainIdProp::const_iterator srcChainsIt, srcChainsIt_end;
471 srcChainsIt = chainsMap[srcTokVertex].begin(); srcChainsIt_end = chainsMap[srcTokVertex].end();
472 for ( ; srcChainsIt != srcChainsIt_end; srcChainsIt++)
474 srcChains.insert((*srcChainsIt).chainId());
476 std::set<uint64_t> tgtChains;
477 VertexChainIdProp::const_iterator tgtChainsIt, tgtChainsIt_end;
478 tgtChainsIt = chainsMap[tgtTokVertex].begin(); tgtChainsIt_end = chainsMap[tgtTokVertex].end();
479 for ( ; tgtChainsIt != tgtChainsIt_end; tgtChainsIt++)
481 tgtChains.insert((*tgtChainsIt).chainId());
488 m_relsmap.push_back(std::make_pair(boost::make_tuple(srcPos,srcTokVertex,srcChains,relType),boost::make_tuple(tgtPos,tgtTokVertex,tgtChains,relType)));
489 m_nodesmap.push_back(boost::make_tuple(srcPos,srcTokVertex,srcChains));
490 m_nodesmap.push_back(boost::make_tuple(tgtPos,tgtTokVertex,tgtChains));
492 for (uint64_t i = 0; i < m_relsmap.size(); i++)
494 exclusions.insert(std::make_pair(i, std::set< uint64_t >()));
496 for (uint64_t i = m_relsmap.size(); i < m_relsmap.size()+m_nodesmap.size(); i++)
498 exclusions.insert(std::make_pair(i, std::set< uint64_t >()));
561std::map< uint64_t, bool > DepGraphCompoundsBuildVisitorPrivate::computeSizes()
568 std::map< uint64_t, bool > sizes;
569 for (uint64_t i = 0; i < m_relsmap.size(); i++)
571 sizes.insert(std::make_pair(i,
true));
573 for (uint64_t i = m_relsmap.size(); i < m_relsmap.size()+m_nodesmap.size(); i++)
575 sizes.insert(std::make_pair(i,
false));
581std::vector< uint64_t > DepGraphCompoundsBuildVisitorPrivate::computeOrder(
582 const std::map< uint64_t,
583 std::set< uint64_t > >& exclusions)
590 std::vector< uint64_t > order;
591 std::multimap< uint64_t, uint64_t > tmp;
592 std::map< uint64_t, std::set< uint64_t > >::const_iterator it, it_end;
593 it = exclusions.begin(); it_end = exclusions.end();
594 for (; it != it_end; it++)
596 tmp.insert(std::make_pair((*it).second.size(), (*it).first));
599 std::multimap< uint64_t, uint64_t >::const_reverse_iterator tmpIt, tmpIt_end;
600 tmpIt = tmp.rbegin(); tmpIt_end = tmp.rend();
601 for (; tmpIt != tmpIt_end; tmpIt++)
603 order.push_back((*tmpIt).second);
609 std::set< uint64_t >& relations)
620 if (relations.empty())
623 LERROR <<
"Trying to find a source of compound in an empty set !";
627 std::set< DependencyGraphVertex > sources, targets;
628 std::set< uint64_t >::const_iterator it, it_end;
629 it = relations.begin(); it_end = relations.end();
630 for (; it != it_end; it++)
632 sources.insert(m_relsmap[*it].first.get<1>());
633 targets.insert(m_relsmap[*it].second.get<1>());
635 std::set< DependencyGraphVertex > res;
636 std::insert_iterator< std::set< DependencyGraphVertex > > ins(res, res.end());
637 std::set_difference(targets.begin(), targets.end(),
638 sources.begin(), sources.end(), ins );
649 relations.erase(*relations.rbegin());
650 return findFinalSourceOfCompoundInRelationsSet(relations);
667 const std::set< uint64_t > relations,
673 LDEBUG <<
"DepGraphCompoundsBuildVisitorPrivate::buildTermFor" << vx << vxTokVertex << theHead;
684 m_annotationData->
addMatching(
"PosGraph", vxTokVertex,
"cpdHead", cpdAnnotVertex);
693 boost::tie(init, init_end) = in_edges(vx, *m_depGraph);
694 for (; init != init_end; init++)
696 if ( !isDepEdgeACompoundNounRelation(*init) )
699 LDEBUG <<
"building annotation for non-compound relation " << source( *init, *m_depGraph ) <<
" -> " << target( *init, *m_depGraph );
705 ConceptModifier modifier= createModifierFor(inSrcMorph);
707 if (modifier.getConceptType() == m_context->
getConceptType(
"LatticeDown"))
710 LDEBUG <<
"DepGraphCompoundsBuildVisitorPrivate::buildTermFor Not storable concept type" << modifier.getConceptType()
711 <<
". aborting this annotation.";
717 CompoundTokenAnnotation annot;
718 GenericAnnotation ga(annot);
723 annot->push_back(modifier);
727 LERROR <<
"DepGraphCompoundsBuildVisitor::buildTermFor annotation CompoundTokenAnnotation has not been created for" << cpdAnnotVertex;
733 std::set< DependencyGraphVertex > governors;
736 for (
auto it = relations.cbegin(), it_end = relations.cend();
740 if (m_relsmap[*it].second.get<1>() == vx)
744 LDEBUG <<
"building annotation for compound relation " << srcDepVertex <<
" -> " << vx;
747 if (governors.find(srcDepVertex) == governors.end())
749 governors.insert(srcDepVertex);
751 LDEBUG <<
"recursive call from" << vx << vxTokVertex;
756 LDEBUG <<
"returned from recursive call on" << srcDepVertex << srcTokVertex;
760 if (!m_annotationData->
hasAnnotation(srcAnnotVertex,
"cpdExt"))
762 m_annotationData->
annotate(srcAnnotVertex,
"cpdExt", 1);
765 if (!m_annotationData->
hasAnnotation(srcAnnotVertex, cpdAnnotVertex,
"CompoundTokenAnnotation"))
767 CompoundTokenAnnotation edgeAnnot;
768 GenericAnnotation ga(edgeAnnot);
771 if (!m_annotationData->
hasAnnotation(srcAnnotVertex, cpdAnnotVertex,
"CompoundTokenAnnotation"))
774 LERROR <<
"DepGraphCompoundsBuildVisitor::buildTermFor annotation CompoundTokenAnnotation has not been created for" << srcAnnotVertex <<
"->" << cpdAnnotVertex;
783 Lima::Common::MediaticData::ConceptType type = m_context->
getConceptType(
"Complementer");
784 ConceptModifier mod(
static_cast<StringsPoolIndex
>(0),type);
787 edgeAnnot->push_back(mod);
798 StringsPoolIndex modString =
static_cast<StringsPoolIndex
>(0);
799 std::vector< uint64_t > modReferences;
801 boost::tie(modInit, modInit_end) = in_edges(srcDepVertex, *m_depGraph);
802 for (; modInit != modInit_end; modInit++)
804 uint64_t modRelType = relTypeMap[*modInit];
808 const MorphoSyntacticData* data = dataMap[source(*modInit, *m_depGraph)];
809 if (data != 0 && !data->empty())
811 modString = *(data->allLemma().begin());
824 edgeAnnot->push_back(mod);
830 LDEBUG <<
"DepGraphCompoundsBuildVisitor: == DONE buildTermFor " << vx;
832 return cpdAnnotVertex;
840 LDEBUG <<
"Creating annotation for morph vertex " << v;
844 m_annotationData->
addMatching(
"PosGraph", v,
"cpd", agv);
850 m_annotationData->annotate(agv, Common::Misc::utf8stdstring2limastring("cpd"), 1);
856 LDEBUG <<
"Built annotation vertex " << agv;
862std::vector< DependencyGraphEdge >
863 DepGraphCompoundsBuildVisitorPrivate::getCompoundsRelationsFromWithChain(
865 const ChainIdStruct& chId)
869 LDEBUG <<
"DepGraphCompoundsBuildVisitorPrivate::getCompoundsRelationsFromWithChain"
870 << from <<
" on chain " << chId;
871 LDEBUG <<
"Critical function : comment logging messages";
873 std::set< DependencyGraphVertex > stackedVxs;
874 std::list< DependencyGraphVertex > vxsToExplore;
875 vxsToExplore.push_back(from);
876 stackedVxs.insert(from);
877 std::vector< DependencyGraphEdge > collectedEdges;
878 std::set< std::pair<DependencyGraphVertex, DependencyGraphVertex> > collectedEdgesSet;
881 while (!vxsToExplore.empty())
885 LDEBUG <<
"Exploring from" << vx;
887 m_visited.insert(vx);
888 vxsToExplore.pop_front();
890 boost::tie(outit, outit_end) = out_edges(vx, *m_depGraph);
891 for (; outit != outit_end; outit++)
894 LDEBUG <<
"Looking at " << vx <<
" out relation ";
897 if ( isDepEdgeACompoundNounRelation(*outit) &&
898 chainsMap[tgtTokVertex].find(chId) != chainsMap[tgtTokVertex].end())
903 if (stackedVxs.find(target(*outit, *m_depGraph)) == stackedVxs.end())
905 vxsToExplore.push_back(target(*outit, *m_depGraph));
906 stackedVxs.insert(target(*outit, *m_depGraph));
908 if (collectedEdgesSet.find(std::make_pair(source(*outit,*m_depGraph),target(*outit,*m_depGraph))) == collectedEdgesSet.end())
911 LDEBUG <<
" and collected";
913 collectedEdges.push_back(*outit);
914 collectedEdgesSet.insert(std::make_pair(source(*outit,*m_depGraph),target(*outit,*m_depGraph)));
915 m_visitedWithChains.insert(std::make_pair(target(*outit, *m_depGraph),chId));
920 LDEBUG <<
" but not collected";
927 LDEBUG <<
"Not collected because not electable because ";
929 LDEBUG <<
"\t- or " << chId <<
" is not a chain of " << tgtTokVertex;
934 boost::tie(init, init_end) = in_edges(vx, *m_depGraph);
935 for (; init != init_end; init++)
938 LDEBUG <<
"Looking at " << vx <<
" in relation ";
943 if ( isDepEdgeACompoundNounRelation(*init) &&
944 chainsMap[srcTokVertex].find(chId) != chainsMap[srcTokVertex].end())
947 if (stackedVxs.find(source(*init, *m_depGraph)) == stackedVxs.end())
949 vxsToExplore.push_back(source(*init, *m_depGraph));
950 stackedVxs.insert(source(*init, *m_depGraph));
952 if (collectedEdgesSet.find(std::make_pair(source(*init,*m_depGraph),target(*init,*m_depGraph))) == collectedEdgesSet.end())
955 collectedEdges.push_back(*init);
956 collectedEdgesSet.insert(std::make_pair(source(*init,*m_depGraph),target(*init,*m_depGraph)));
957 m_visitedWithChains.insert(std::make_pair(source(*init, *m_depGraph),chId));
972 return collectedEdges;
975std::vector< DependencyGraphEdge >
976 DepGraphCompoundsBuildVisitorPrivate::getCompoundsRelationsFromNoChain(
981 LDEBUG <<
"DepGraphCompoundsBuildVisitorPrivate::getCompoundsRelationsFromNoChain"
983 LDEBUG <<
"Critical function : comment logging messages";
985 std::set< DependencyGraphVertex > stackedVxs;
986 std::list< DependencyGraphVertex > vxsToExplore;
987 vxsToExplore.push_back(from);
988 stackedVxs.insert(from);
989 std::vector< DependencyGraphEdge > collectedEdges;
990 std::set< std::pair<DependencyGraphVertex, DependencyGraphVertex> > collectedEdgesSet;
992 while (!vxsToExplore.empty())
996 LDEBUG <<
"Exploring from" << vx;
998 m_visited.insert(vx);
999 vxsToExplore.pop_front();
1001 boost::tie(outit, outit_end) = out_edges(vx, *m_depGraph);
1002 for (; outit != outit_end; outit++)
1005 LDEBUG <<
"Looking at " << vx <<
" out relation ";
1007 if ( isDepEdgeACompoundNounRelation(*outit) )
1012 if (stackedVxs.find(target(*outit, *m_depGraph)) == stackedVxs.end())
1014 vxsToExplore.push_back(target(*outit, *m_depGraph));
1015 stackedVxs.insert(target(*outit, *m_depGraph));
1017 if (collectedEdgesSet.find(std::make_pair(source(*outit,*m_depGraph),target(*outit,*m_depGraph))) == collectedEdgesSet.end())
1020 LDEBUG <<
" and collected";
1022 collectedEdges.push_back(*outit);
1023 collectedEdgesSet.insert(std::make_pair(source(*outit,*m_depGraph),target(*outit,*m_depGraph)));
1028 LDEBUG <<
" but not collected";
1035 LDEBUG <<
"Not collected because not electable because ";
1041 boost::tie(init, init_end) = in_edges(vx, *m_depGraph);
1042 for (; init != init_end; init++)
1045 LDEBUG <<
"Looking at " << vx <<
" in relation ";
1049 if ( isDepEdgeACompoundNounRelation(*init) )
1052 if (stackedVxs.find(source(*init, *m_depGraph)) == stackedVxs.end())
1054 vxsToExplore.push_back(source(*init, *m_depGraph));
1055 stackedVxs.insert(source(*init, *m_depGraph));
1057 if (collectedEdgesSet.find(std::make_pair(source(*init,*m_depGraph),target(*init,*m_depGraph))) == collectedEdgesSet.end())
1060 collectedEdges.push_back(*init);
1061 collectedEdgesSet.insert(std::make_pair(source(*init,*m_depGraph),target(*init,*m_depGraph)));
1071 return collectedEdges;
1075std::map< uint64_t, std::set< uint64_t > >
1076 DepGraphCompoundsBuildVisitorPrivate::computeExclusionsWithChain(
1077 const std::vector< DependencyGraphEdge >& relations,
1078 const ChainIdStruct& chId)
1083 std::map< uint64_t, std::set< uint64_t > > exclusions;
1088 std::vector< DependencyGraphEdge >::const_iterator relsit, relsit_end;
1089 relsit = relations.begin(); relsit_end = relations.end();
1091 for (uint64_t relNum=0; relsit != relsit_end; relsit++,relNum++)
1099 uint64_t srcPos = srcToken->position();
1100 uint64_t tgtPos = tgtToken->position();
1101 std::set<uint64_t> srcChains;
1102 srcChains.insert(chId.chainId());
1103 std::set<uint64_t> tgtChains;
1104 tgtChains.insert(chId.chainId());
1107 m_relsmap.push_back(std::make_pair(boost::make_tuple(srcPos,srcTokVertex,srcChains,relType),boost::make_tuple(tgtPos,tgtTokVertex,tgtChains,relType)));
1108 m_nodesmap.push_back(boost::make_tuple(srcPos,srcTokVertex,srcChains));
1109 m_nodesmap.push_back(boost::make_tuple(tgtPos,tgtTokVertex,tgtChains));
1111 for (uint64_t i = 0; i < m_relsmap.size(); i++)
1113 exclusions.insert(std::make_pair(i, std::set< uint64_t >()));
1115 for (uint64_t i = m_relsmap.size(); i < m_relsmap.size()+m_nodesmap.size(); i++)
1117 exclusions.insert(std::make_pair(i, std::set< uint64_t >()));
1121 for (uint64_t i = 0; i < m_relsmap.size(); i++)
1124 for (uint64_t j = i+1; j < m_relsmap.size(); j++)
1128 ( (m_relsmap[i].first.get<0>() == m_relsmap[j].first.get<0>())
1135 ( (m_relsmap[i].first.get<0>() == m_relsmap[j].second.get<0>())
1136 && ( m_relsmap[i].first.get<1>() != m_relsmap[j].second.get<1>()
1141 ( (m_relsmap[i].second.get<0>() == m_relsmap[j].first.get<0>())
1142 && ( m_relsmap[i].second.get<1>() != m_relsmap[j].first.get<1>()
1146 ( (m_relsmap[i].second.get<0>() == m_relsmap[j].second.get<0>())
1147 && ( m_relsmap[i].second.get<1>() != m_relsmap[j].second.get<1>()
1152 exclusions[i].insert(j);
1153 exclusions[j].insert(i);
1163 for (uint64_t j = 0; j < m_nodesmap.size(); j++)
1167 (m_relsmap[i].first.get<0>() == m_nodesmap[j].get<0>() && m_relsmap[i].first.get<1>() != m_nodesmap[j].get<1>())
1169 || (m_relsmap[i].second.get<0>() == m_nodesmap[j].get<0>() && m_relsmap[i].second.get<1>() != m_nodesmap[j].get<1>()) )
1172 exclusions[i].insert(i+j);
1173 exclusions[i+j].insert(i);
1182 for (uint64_t i = 0; i < m_nodesmap.size(); i++)
1184 for (uint64_t j = 0; j < m_nodesmap.size(); j++)
1187 if ( (m_nodesmap[i].get<0>() == m_nodesmap[j].get<0>()) && (m_nodesmap[i].get<1>() != m_nodesmap[j].get<1>()))
1190 exclusions[m_relsmap.size()+i].insert(m_relsmap.size()+i+j);
1191 exclusions[m_relsmap.size()+i+j].insert(m_relsmap.size()+i);
1204std::map< uint64_t, std::set< uint64_t > >
1205 DepGraphCompoundsBuildVisitorPrivate::computeExclusionsNoChain(
1206 const std::vector< DependencyGraphEdge >& relations)
1211 std::map< uint64_t, std::set< uint64_t > > exclusions;
1215 std::vector< DependencyGraphEdge >::const_iterator relsit, relsit_end;
1216 relsit = relations.begin(); relsit_end = relations.end();
1218 for (uint64_t relNum=0; relsit != relsit_end; relsit++,relNum++)
1226 uint64_t srcPos = srcToken->position();
1227 uint64_t tgtPos = tgtToken->position();
1228 std::set<uint64_t> srcChains;
1229 std::set<uint64_t> tgtChains;
1232 m_relsmap.push_back(std::make_pair(boost::make_tuple(srcPos,srcTokVertex,srcChains,relType),boost::make_tuple(tgtPos,tgtTokVertex,tgtChains,relType)));
1233 m_nodesmap.push_back(boost::make_tuple(srcPos,srcTokVertex,srcChains));
1234 m_nodesmap.push_back(boost::make_tuple(tgtPos,tgtTokVertex,tgtChains));
1236 for (uint64_t i = 0; i < m_relsmap.size(); i++)
1238 exclusions.insert(std::make_pair(i, std::set< uint64_t >()));
1240 for (uint64_t i = m_relsmap.size(); i < m_relsmap.size()+m_nodesmap.size(); i++)
1242 exclusions.insert(std::make_pair(i, std::set< uint64_t >()));
1246 for (uint64_t i = 0; i < m_relsmap.size(); i++)
1249 for (uint64_t j = i+1; j < m_relsmap.size(); j++)
1253 ( (m_relsmap[i].first.get<0>() == m_relsmap[j].first.get<0>())
1260 ( (m_relsmap[i].first.get<0>() == m_relsmap[j].second.get<0>())
1261 && ( m_relsmap[i].first.get<1>() != m_relsmap[j].second.get<1>()
1266 ( (m_relsmap[i].second.get<0>() == m_relsmap[j].first.get<0>())
1267 && ( m_relsmap[i].second.get<1>() != m_relsmap[j].first.get<1>()
1271 ( (m_relsmap[i].second.get<0>() == m_relsmap[j].second.get<0>())
1272 && ( m_relsmap[i].second.get<1>() != m_relsmap[j].second.get<1>()
1277 exclusions[i].insert(j);
1278 exclusions[j].insert(i);
1288 for (uint64_t j = 0; j < m_nodesmap.size(); j++)
1292 (m_relsmap[i].first.get<0>() == m_nodesmap[j].get<0>() && m_relsmap[i].first.get<1>() != m_nodesmap[j].get<1>())
1294 || (m_relsmap[i].second.get<0>() == m_nodesmap[j].get<0>() && m_relsmap[i].second.get<1>() != m_nodesmap[j].get<1>()) )
1297 exclusions[i].insert(i+j);
1298 exclusions[i+j].insert(i);
1307 for (uint64_t i = 0; i < m_nodesmap.size(); i++)
1309 for (uint64_t j = 0; j < m_nodesmap.size(); j++)
1312 if ( (m_nodesmap[i].get<0>() == m_nodesmap[j].get<0>()) && (m_nodesmap[i].get<1>() != m_nodesmap[j].get<1>()))
1315 exclusions[m_relsmap.size()+i].insert(m_relsmap.size()+i+j);
1316 exclusions[m_relsmap.size()+i+j].insert(m_relsmap.size()+i);
1328ConceptModifier DepGraphCompoundsBuildVisitorPrivate::createModifierFor(
1336 const MorphoSyntacticData* data = dataMap[inSrcMorph];
1337 LinguisticCode macro;
1338 StringsPoolIndex realization =
static_cast<StringsPoolIndex
>(0);
1339 if (data != 0 && !data->empty())
1341 macro = m_macroAccessor->
readValue(data->begin()->properties);
1342 if (!data->allLemma().empty())
1344 realization = *(data->allLemma().begin());
1350 std::vector< uint64_t > references;
1358 || conceptType == m_context->
getConceptType(
"SemanticModifier") )
1360 references.push_back(inSrcMorph);
1362 return ConceptModifier(realization, conceptType, references);
This file is the main header file for the data related to annotation graphs.
DependencyGraph::edge_descriptor DependencyGraphEdge
typedefs to simplify the acces to various graphs elements
DependencyGraph::in_edge_iterator DependencyGraphInEdgeIt
DependencyGraph::out_edge_iterator DependencyGraphOutEdgeIt
boost::property_map< DependencyGraph, edge_deprel_type_t >::type EdgeDepRelTypePropertyMap
DependencyGraph::vertex_descriptor DependencyGraphVertex
boost::adjacency_list< boost::vecS, boost::vecS, boost::bidirectionalS, DepVertexProperties, DepEdgeProperties > DependencyGraph
The dependency graph class.
boost::property_map< LinguisticGraph, vertex_chain_id_t >::type VertexChainIdPropertyMap
boost::property_map< LinguisticGraph, vertex_data_t >::type VertexDataPropertyMap
LinguisticGraph::vertex_descriptor LinguisticGraphVertex
Data used for the syntactic analyzis of texts.
Holds an annotation graph and gives an API to manipulate it.
void addMatching(const std::string &first, AnnotationGraphVertex firstVx, const std::string &second, AnnotationGraphVertex secondVx)
Adds a symetric matching between two vertices of two graphs identified by the two string parameters.
const GenericAnnotation & annotation(AnnotationGraphVertex v1, AnnotationGraphVertex v2, const LimaString &annot) const
AnnotationGraphVertex createAnnotationVertex()
Creates a new annotation vertex in the graph.
ValueType * pointerValue()
Provide function to read write and check a property.
LinguisticCode readValue(const LinguisticCode &code) const
read a property in a coded int.
bool isACompoundRel(const std::string &rel) const
Lima::Common::MediaticData::ConceptType getConceptType(const std::string &typeName) const
Lima::Common::MediaticData::ConceptType getConceptForMacro(const LinguisticCode ¯o) const
std::list< std::set< uint64_t > > computeCompatibilitiesWithChain(std::map< uint64_t, std::set< uint64_t > > &exclusions, std::map< uint64_t, bool > &sizes, std::vector< uint64_t > &order)
This enumeration lists the types of annotations used to specify the role of an annotation in a compou...
virtual ~DepGraphCompoundsBuildVisitor()
DepGraphCompoundsBuildVisitor(const Lima::LinguisticProcessing::Compounds::CompoundsBuilderFromSyntacticData *cpbfsd, MediaId language, SyntacticAnalysis::SyntacticData *syntacticData, DependencyGraph *depGraph, LinguisticAnalysisStructure::AnalysisGraph *iter, LinguisticGraphVertex startVertex, LinguisticGraphVertex stopVertex, Common::AnnotationGraphs::AnnotationData *annotationData)
void discover_vertex(LinguisticGraphVertex v)
An AnalysisData containing a LinguisticGraph with a language and an id.
const LinguisticGraph * getGraph(void) const
Returns the underlying graph structure.
Property to identify the chains in the graph.
This class points to a graph, its dependency graph and the structure that holds the maping between th...
LinguisticGraphVertex tokenVertexForDepVertex(const DependencyGraphVertex &v) const
LinguisticGraph * graph()
DependencyGraphVertex depVertexForTokenVertex(const LinguisticGraphVertex &v) const
static const MediaticData & single()
const singleton accessor
static MediaticData & changeable()
singleton accessor
void dumpFunction(const std::string &annot, const Dumper *f)
AnnotationGraph::vertex_descriptor AnnotationGraphVertex
bool hasAnnotation(AnnotationGraphVertex v, const LimaString &annot) const
void annotate(AnnotationGraphVertex v, const LimaString &annot, uint64_t value)
LimaString utf8stdstring2limastring(const std::string &src)