LIMA
Libre Multilingual Analyzer — C++ API
Loading...
Searching...
No Matches
AnalysisGraph.h
Go to the documentation of this file.
1// Copyright 2002-2020 CEA LIST
2// SPDX-FileCopyrightText: 2022 CEA LIST <gael.de-chalendar@cea.fr>
3//
4// SPDX-License-Identifier: MIT
5
6/***************************************************************************
7 * Copyright (C) 2004-2020 by CEA LIST *
8 * *
9 ***************************************************************************/
10#ifndef LIMA_LINGUISTICPROCESSING_LINGUISTICANALYSISSTRUCTUREANALYSISGRAPH_H
11#define LIMA_LINGUISTICPROCESSING_LINGUISTICANALYSISSTRUCTUREANALYSISGRAPH_H
12
13
15#include "LinguisticGraph.h"
18
19namespace Lima
20{
21namespace Common
22{
23namespace AnnotationGraphs
24{
25 class AnnotationData;
26}
27}
28namespace LinguisticProcessing
29{
30}
31}
32
33namespace Lima
34{
35
36namespace LinguisticProcessing
37{
38
39namespace LinguisticAnalysisStructure
40{
41
47{
48public:
49 AnalysisGraph(const std::string& graphId,
50 MediaId language,
51 bool deleteTokenWhenDestroyed,
52 bool deleteDataWhenDestroyed);
53 AnalysisGraph(const std::string& graphId,
54 MediaId language,
55 bool deleteTokenWhenDestroyed,
56 bool deleteDataWhenDestroyed,
57 const AnalysisGraph& graph);
58
59 virtual ~AnalysisGraph();
60
63 const LinguisticGraphVertex& firstVertex(void) const { return m_firstVertex; }
64
67 const LinguisticGraphVertex& lastVertex(void) const { return m_lastVertex; }
68
73 const LinguisticGraph* getGraph(void) const { return m_graph; }
74
79 LinguisticGraph* getGraph(void) { return m_graph; }
80
81 const std::string& getGraphId(void) const { return m_graphId; }
82
90 LinguisticGraphVertex nextMainPathVertex(
92 const Common::PropertyCode::PropertyAccessor& microAccessor,
93 const std::list<LinguisticCode> microFilters,
95
109 LinguisticGraphVertex nextChainsBreakFrom(
110 const LinguisticGraphVertex& v,
111 const Common::PropertyCode::PropertyAccessor& macroAccessor,
112 const LinguisticCode& ponctu,
113 const Common::PropertyCode::PropertyAccessor& microAccessor,
114 LinguisticGraphVertex& nextSentenceBreak);
115
116 //bool isFirstWordOfSentence(const LinguisticGraphVertex& v, MediaId language) const;
117
124 void populateAnnotationGraph(
126 const std::string& src);
127
128 inline bool ownsTokens() const {return m_deleteTokenWhenDestroyed;}
129
130 inline bool ownsMorphData() const {return m_deleteDataWhenDestroyed;}
131
132private:
133
138 AnalysisGraph& operator = (const AnalysisGraph&);
145 void createGraph();
146
150 void deleteGraph();
151
153 LinguisticGraph* m_graph;
154
157 LinguisticGraphVertex m_firstVertex;
158
161 LinguisticGraphVertex m_lastVertex;
162
165 bool m_deleteTokenWhenDestroyed;
166
169 bool m_deleteDataWhenDestroyed;
170
171 MediaId m_language;
172 std::string m_graphId;
173};
174
175
176template<class T> inline
178 const LinguisticGraphVertex v,
179 T& output_container)
180{
181 LinguisticGraphOutEdgeIt outEdge,outEdge_end;
182 boost::tie (outEdge,outEdge_end)=out_edges(v,*(graph.getGraph()));
183 for (; outEdge!=outEdge_end; outEdge++)
184 {
185 output_container.insert(target(*outEdge,*(graph.getGraph())));
186 }
187}
188
189template<class T> inline
191 const LinguisticGraphVertex v)
192{
193 T followingNodes;
194 getFollowingNodes<T>(graph, v, followingNodes);
195 return followingNodes;
196}
197
198inline
200 const LinguisticGraphVertex v)
201{
202 LinguisticGraphOutEdgeIt outEdge,outEdge_end;
203 boost::tie (outEdge,outEdge_end)=out_edges(v,*(graph.getGraph()));
205 while (outEdge!=outEdge_end)
206 {
207 result=target(*outEdge,*(graph.getGraph()));
208 outEdge++;
209 if (outEdge!=outEdge_end)
210 {
211 throw std::logic_error("getOneFollowingNode assumes that there is one and only one following node. Multiple nodes detected.");
212 }
213 return result;
214 }
215
216 throw std::logic_error("getOneFollowingNode assumes that there is one and only one following node. No preceding nodes found.");
217}
218
219template<class T> inline
221 const LinguisticGraphVertex& v,
222 T& output_container)
223{
224 LinguisticGraphInEdgeIt inEdge,inEdge_end;
225 boost::tie (inEdge,inEdge_end)=in_edges(v,*(graph.getGraph()));
226 for (; inEdge!=inEdge_end; inEdge++)
227 {
228 output_container.insert(source(*inEdge,*(graph.getGraph())));
229 }
230}
231
232template<class T> inline
234 const LinguisticGraphVertex v)
235{
236 T precedingNodes;
237 getPrecedingNodes<T>(graph, v, precedingNodes);
238 return precedingNodes;
239}
240
241inline
243 const LinguisticGraphVertex v)
244{
245 LinguisticGraphInEdgeIt inEdge,inEdge_end;
246 boost::tie (inEdge,inEdge_end)=in_edges(v,*(graph.getGraph()));
248 while (inEdge!=inEdge_end)
249 {
250 result=source(*inEdge,*(graph.getGraph()));
251 inEdge++;
252 if (inEdge!=inEdge_end)
253 {
254 throw std::logic_error("getOnePrecedingNode assumes that there is one and only one preceding node. Multiple nodes detected.");
255 }
256 return result;
257 }
258
259 throw std::logic_error("getOnePrecedingNode assumes that there is one and only one preceding node. No preceding nodes found.");
260}
261
262}
263
264}
265
266}
267
268#endif
#define LIMA_LINGUISTICANALYSISSTRUCTURE_EXPORT
A graph structure for linguistic analysis.
LinguisticGraph::in_edge_iterator LinguisticGraphInEdgeIt
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.
just for semantics: base class for analysisData
Holds an annotation graph and gives an API to manipulate it.
Provide function to read write and check a property.
An AnalysisData containing a LinguisticGraph with a language and an id.
LinguisticGraph * getGraph(void)
Returns the underlying graph structure.
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.
LinguisticGraphVertex getOnePrecedingNode(const LinguisticAnalysisStructure::AnalysisGraph &graph, const LinguisticGraphVertex v)
void getPrecedingNodes(const LinguisticAnalysisStructure::AnalysisGraph &graph, const LinguisticGraphVertex &v, T &output_container)
void getFollowingNodes(const LinguisticAnalysisStructure::AnalysisGraph &graph, const LinguisticGraphVertex v, T &output_container)
LinguisticGraphVertex getOneFollowingNode(const LinguisticAnalysisStructure::AnalysisGraph &graph, const LinguisticGraphVertex v)
NAUTITIA.