25namespace LinguisticProcessing {
26namespace SyntacticAnalysis {
31 std::shared_ptr<SyntagmDefStruct> matrices) :
33 m_graph(anagraph->getGraph()),
40 m_relationStoredForSelectionalConstraint(0,0,0)
51 std::vector<Token*>::iterator itTokens, itTokens_end;
52 itTokens = m_ownedTokens.begin(); itTokens_end = m_ownedTokens.end();
53 for (; itTokens != itTokens_end; itTokens++)
58 std::vector<MorphoSyntacticData*>::iterator itMorphData, itMorphData_end;
59 itMorphData = m_ownedMorphData.begin(); itMorphData_end = m_ownedMorphData.end();
60 for (; itMorphData != itMorphData_end; itMorphData++)
81 m_mapping.first.clear();
82 m_mapping.second.clear();
85 std::tie(itg, itg_end) = vertices(*m_graph);
87 std::tie(itd, itd_end) = vertices(*m_depGraph);
89 while (itg != itg_end)
91 m_mapping.first.insert(std::make_pair(*itg, *itd));
92 m_mapping.second.insert(std::make_pair(*itd, *itg));
113 m_mapping.first.insert(std::make_pair(morph, synt));
114 m_mapping.second.insert(std::make_pair(synt, morph));
115 return std::make_pair(morph, synt);
121 if (m_mapping.first.find(v) == m_mapping.first.end())
123 std::ostringstream oss;
124 oss <<
"SyntacticData::depVertexForTokenVertex: searched dependency vertex " << v <<
" not found";
127 return (*(m_mapping.first.find(v))).second;
135 if (m_mapping.second.find(v) == m_mapping.second.end())
136 throw LimaException(
"SyntacticData::tokenVertexForDepVertex: searched morphosyntactic vertex not found");
137 return (*(m_mapping.second.find(v))).second;
149 std::list< LinguisticGraphVertex > verticesToLookAt;
150 verticesToLookAt.push_back(srcVertex);
151 while (!verticesToLookAt.empty())
154 verticesToLookAt.pop_front();
156 nb += out_degree(depVertex, *m_depGraph);
159 for (std::tie(it, it_end) = out_edges(depVertex, *m_depGraph); it != it_end; it++)
163 if ( outVertex != m_anagraph->
lastVertex() && outVertex != tgtVertex)
165 verticesToLookAt.push_back(outVertex);
173std::vector<LinguisticGraphVertex>
177 std::vector<LinguisticGraphVertex> related;
182 std::tie(outIt, outIt_end) = out_edges(v, *m_depGraph);
183 for (; outIt != outIt_end; outIt++) {
184 if (depRelMap[*outIt] ==
relation) {
185 related.push_back(target(*outIt,*m_depGraph));
190 std::tie(inIt, inIt_end) = in_edges(v, *m_depGraph);
191 for (; inIt != inIt_end; inIt++) {
193 related.push_back(source(*inIt,*m_depGraph));
201std::vector<LinguisticGraphVertex>
203 const std::set<Common::MediaticData::SyntacticRelationId>& relations)
205 std::vector<LinguisticGraphVertex> related;
210 std::tie(outIt, outIt_end) = out_edges(v, *m_depGraph);
211 for (; outIt != outIt_end; outIt++) {
212 if (relations.find(depRelMap[*outIt]) != relations.end()) {
213 related.push_back(target(*outIt,*m_depGraph));
218 std::tie(inIt, inIt_end) = in_edges(v, *m_depGraph);
219 for (; inIt != inIt_end; inIt++) {
220 if (relations.find(depRelMap[*inIt]) != relations.end()) {
221 related.push_back(source(*inIt,*m_depGraph));
236 LDEBUG <<
"Adding relation " << relType <<
" between "
237 << src <<
" and " << dest <<
" for no chain";
246 std::tie(edge, success) = add_edge(v1, v2, *m_depGraph);
252 LDEBUG <<
"Storing relation "<<v1<<
","<<v2<<
"," << relType;
258 LERROR <<
"Was not able to add relation (" << relType <<
") between "
259 << src <<
" and " << dest <<
" for no chain";
260 throw std::runtime_error(
"Was not able to add relation");
277 std::tie(outItr, outItrEnd) = out_edges(v1, *m_depGraph);
278 for (; outItr != outItrEnd; outItrEnd++)
280 if(target(*outItr, *m_depGraph) != v2)
291 LERROR <<
"Was not able to modify relation (" << relType <<
") between "
292 << src <<
" and " << dest <<
" to " << newType;
293 throw std::runtime_error(
"Was not able to modify relation");
303 LDEBUG <<
"SyntacticData::removeDependency " << v1 <<
", " << v2 <<
", " << relationType;
310 LDEBUG <<
"SyntacticData::removeDependency dep vertices are " << dv1 <<
", " << dv2;
313 std::tie (outIt, outIt_end) = boost::out_edges(dv1, *m_depGraph);
314 for (; outIt != outIt_end; outIt++)
316 if (target(*outIt, *m_depGraph) == dv2 && relTypeMap[*outIt] == relationType)
319 LDEBUG <<
"SyntacticData::removeDependency dependency found. Removing it.";
321 boost::remove_edge(*outIt, *m_depGraph);
326 LDEBUG <<
"SyntacticData::removeDependency dependency NOT found.";
DependencyGraph::edge_descriptor DependencyGraphEdge
typedefs to simplify the acces to various graphs elements
DependencyGraph::in_edge_iterator DependencyGraphInEdgeIt
DependencyGraph::vertex_iterator DependencyGraphVertexIt
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.
LinguisticGraph::vertex_iterator LinguisticGraphVertexIt
LinguisticGraph::vertex_descriptor LinguisticGraphVertex
Data used for the syntactic analyzis of texts.
The main LIMA exception class.
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.
Property to identify the chains in the graph.
uint64_t depsBetween(const LinguisticGraphVertex &srcVertex, const LinguisticGraphVertex &tgtVertex)
Computes the number of dependency relations in the graph between the given source and taget morphosyn...
LinguisticGraphVertex tokenVertexForDepVertex(const DependencyGraphVertex &v) const
void setupDependencyGraph()
This method is used to setup the search of the dependency relations when the PoS tagging is done and ...
std::pair< LinguisticGraphVertex, DependencyGraphVertex > addVertex()
This method is used to setup the search of the dependency relations when the PoS tagging is done and ...
SyntacticData(LinguisticAnalysisStructure::AnalysisGraph *pit, std::shared_ptr< SyntagmDefStruct > matrices)
This constructor uses the given graph to construct a dependency graph with the same number of vertice...
std::vector< LinguisticGraphVertex > findRelated(const LinguisticGraphVertex, const Common::MediaticData::SyntacticRelationId &relation)
find vertices related to a given vertex by a given relation (related vertices can be either source or...
DependencyGraphVertex depVertexForTokenVertex(const LinguisticGraphVertex &v) const
void modifyRelationNoChain(const Common::MediaticData::SyntacticRelationId &relType, const LinguisticGraphVertex &src, const LinguisticGraphVertex &dest, const Common::MediaticData::SyntacticRelationId &newType)
bool removeDependency(const LinguisticGraphVertex &v1, const LinguisticGraphVertex &v2, const Common::MediaticData::SyntacticRelationId relationType=0)
void addRelationNoChain(const Common::MediaticData::SyntacticRelationId &relType, const LinguisticGraphVertex &src, const LinguisticGraphVertex &dest)