25namespace LinguisticProcessing {
27namespace LinguisticAnalysisStructure {
36 m_deleteTokenWhenDestroyed(deleteTokenWhenDestroyed),
37 m_deleteDataWhenDestroyed(deleteDataWhenDestroyed),
46 m_firstVertex(anagraph.m_firstVertex),
47 m_lastVertex(anagraph.m_lastVertex),
48 m_deleteTokenWhenDestroyed(deleteTokenWhenDestroyed),
49 m_deleteDataWhenDestroyed(deleteDataWhenDestroyed),
58 m_firstVertex(g.m_firstVertex),
59 m_lastVertex(g.m_lastVertex),
60 m_deleteTokenWhenDestroyed(g.m_deleteTokenWhenDestroyed),
61 m_deleteDataWhenDestroyed(g.m_deleteDataWhenDestroyed),
62 m_language(g.m_language)
81 m_firstVertex=g.m_firstVertex;
82 m_lastVertex=g.m_lastVertex;
83 m_language=g.m_language;
91void AnalysisGraph::createGraph()
102 if (num_vertices(*m_graph) != 0)
104 throw LinguisticProcessingException(
"AnalysisGraph::createGraph() - graph is not empy");
112 tokenMap[vertex1] = 0;
113 dataMap[vertex1] = 0;
114 m_firstVertex = vertex1;
118 tokenMap[vertex2] = 0;
119 dataMap[vertex2] = 0;
120 m_lastVertex = vertex2;
125 boost::tie(beginEndEdge, b) = add_edge(vertex1, vertex2, *m_graph);
128 throw LinguisticProcessingException(
"AnalysisGraph::createGraph - could not bind beginEndEdge");
132void AnalysisGraph::deleteGraph()
138 if (m_graph == 0)
return;
140 if (m_deleteTokenWhenDestroyed)
145 std::set<Token*> deletedToken;
147 boost::tie(it, it_end) = vertices(*m_graph);
148 for (; it != it_end; it++)
150 Token* ft = tokenMap[*it];
151 if ( ft != 0 && (deletedToken.find(ft) == deletedToken.end()) &&
155 deletedToken.insert(ft);
160 if (m_deleteDataWhenDestroyed)
165 std::set<MorphoSyntacticData*> deletedData;
167 boost::tie(it, it_end) = vertices(*m_graph);
168 for (; it != it_end; it++)
170 MorphoSyntacticData* data = dataMap[*it];
171 if ( data != 0 && (deletedData.find(data) == deletedData.end()) &&
175 deletedData.insert(data);
192 const std::list<LinguisticCode> microFilters,
205 std::set<LinguisticGraphVertex> visited;
209 std::queue<LinguisticGraphVertex,std::list<LinguisticGraphVertex> > toVisit;
212 size_t accumulator=out_degree(start,*m_graph);
213 boost::tie (outItr,outItrEnd) = out_edges(start,*m_graph);
214 for (;outItr!=outItrEnd;outItr++)
216 toVisit.push(target(*outItr,*m_graph));
221 while (!toVisit.empty())
225 visited.insert(current);
230 Token* ft = tokenMap[current];
232 accumulator-=in_degree(current,*m_graph);
240 LDEBUG <<
"AnalysisGraph::nextMainPathVertex micro, return" << current;
247 LDEBUG <<
"AnalysisGraph::nextMainPathVertex sentence break, return" << current;
252 accumulator+=out_degree(current,*m_graph);
254 boost::tie (outItr,outItrEnd) = out_edges(current,*m_graph);
255 if (outItr==outItrEnd)
258 LERROR <<
"no next vertex in graph whereas current vertex is not last vertex !!";
259 throw std::runtime_error(
"no next vertex in graph whereas current vertex is not last vertex !!");
261 for (;outItr!=outItrEnd;outItr++)
265 boost::tie(inItr,inItrEnd) = in_edges(next,*m_graph);
267 for (;inItr!=inItrEnd;inItr++)
269 if (visited.find(source(*inItr,*m_graph))==visited.end())
313 size_t accumulator=out_degree(current,*m_graph);
317 boost::tie (it, it_end) = out_edges(current, *m_graph);
321 if ( (source((*it), *m_graph) == m_firstVertex) && (target((*it), *m_graph) == m_lastVertex) )
329 if (next == m_lastVertex || next==nextSentenceBreak)
331 if (next != nextSentenceBreak)
334 LERROR <<
"In nextChainsBreakFrom: went beyond next sentence break " << nextSentenceBreak;
335 LERROR <<
" returning graph's last vertex " << next;
338 LDEBUG <<
"Next chains break is: " << next;
342 accumulator-=in_degree(next,*m_graph);
345 if ( (accumulator == 0) && (msd->
countValues(microAccessor) == 1) )
370 if (msd->begin() != msd->end()) {
371 macro=macroAccessor.
readValue(msd->begin()->properties);
382 if ( macro == ponctu)
385 accumulator+=out_degree(next,*m_graph);
389 LERROR <<
"In nextChainsBreakFrom: cannot go beyond " << current;
399 const std::string& src)
403 boost::tie(it, it_end) = vertices(*m_graph);
404 for (; it != it_end; it++)
406 if (annotData->
matches(src, *it,
"annot").empty())
This file is the main header file for the data related to annotation graphs.
LinguisticGraph::in_edge_iterator LinguisticGraphInEdgeIt
boost::property_map< LinguisticGraph, vertex_data_t >::type VertexDataPropertyMap
boost::graph_traits< LinguisticGraph >::edge_descriptor LinguisticGraphEdge
typedefs to simplify the access to various graphs elements
LinguisticGraph::vertex_iterator LinguisticGraphVertexIt
boost::property_map< LinguisticGraph, vertex_token_t >::type VertexTokenPropertyMap
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.
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.
std::set< AnnotationGraphVertex > matches(const std::string &first, AnnotationGraphVertex firstVx, const std::string &second) const
Gets the set of vertices matched in the second graph by the given vertex of the first graph.
AnnotationGraphVertex createAnnotationVertex()
Creates a new annotation vertex in the graph.
Provide function to read write and check a property.
LinguisticCode readValue(const LinguisticCode &code) const
read a property in a coded int.
void unregisterUser(void *p)
void registerUser(void *p)
An AnalysisData containing a LinguisticGraph with a language and an id.
AnalysisGraph(const std::string &graphId, MediaId language, bool deleteTokenWhenDestroyed, bool deleteDataWhenDestroyed)
LinguisticGraphVertex nextChainsBreakFrom(const LinguisticGraphVertex &v, const Common::PropertyCode::PropertyAccessor ¯oAccessor, const LinguisticCode &ponctu, const Common::PropertyCode::PropertyAccessor µAccessor, LinguisticGraphVertex &nextSentenceBreak)
Finds the next vertex after the input vertex that:
LinguisticGraphVertex nextMainPathVertex(LinguisticGraphVertex start, const Common::PropertyCode::PropertyAccessor µAccessor, const std::list< LinguisticCode > microFilters, LinguisticGraphVertex end)
Finds the next unambiguated vertex for which micro categories are all included in the microFilters li...
const LinguisticGraphVertex & lastVertex(void) const
Returns the last vertex of the graph.
void populateAnnotationGraph(Common::AnnotationGraphs::AnnotationData *annotData, const std::string &src)
Creates the annotations in the agdata corresponding to this graphs vertices.
const LinguisticGraphVertex & firstVertex(void) const
Returns the first vertex of the graph.
Holds morphosyntactic informations.
uint64_t countValues(const Common::PropertyCode::PropertyAccessor &propertyAccessor)
bool hasUniqueMicro(const Lima::Common::PropertyCode::PropertyAccessor µAccessor, const std::list< Lima::LinguisticCode > µFilter)
return true if there is only one micro, and this micro is in microfilter
StatusType getStatus() const
holds surface data of a token
const TStatus & status() const
static const MediaticData & single()
const singleton accessor
static MediaticData & changeable()
singleton accessor
AnnotationGraph::vertex_descriptor AnnotationGraphVertex
void annotate(AnnotationGraphVertex v, const LimaString &annot, uint64_t value)
LimaString utf8stdstring2limastring(const std::string &src)