50using namespace boost::tuples;
61typedef boost::color_traits<boost::default_color_type>
Color;
64namespace LinguisticProcessing {
65namespace AnalysisDumpers {
75 m_annotXmlDumperPtr(0),
76 m_dumpFullTokens(true),
91 LDEBUG <<
"fullXmlDumper init!";
100 LWARN <<
"dumpTokens parameter not found, using default: "
118 LERROR <<
"FullXmlDumper::init: Missing parameter handler in FullXmlDumper configuration";
130 auto metadata = std::dynamic_pointer_cast<LinguisticMetaData>(analysis.
getData(
"LinguisticMetaData"));
132 LERROR <<
"FullXmlDumper::process: no LinguisticMetaData ! abort";
137 auto h = std::dynamic_pointer_cast<AnalysisHandlerContainer>(analysis.
getData(
"AnalysisHandlerContainer"));
141 LERROR <<
"FullXmlDumper::process: handler " <<
m_handler <<
" has not been given to the core client";
145 auto graph = std::dynamic_pointer_cast<AnalysisGraph>(analysis.
getData(
m_graph));
151 auto syntacticData = std::dynamic_pointer_cast<SyntacticData>(analysis.
getData(
"SyntacticData"));
152 if (syntacticData==0)
154 syntacticData = std::make_shared<SyntacticAnalysis::SyntacticData>(graph.get(),
nullptr);
155 syntacticData->setupDependencyGraph();
156 analysis.
setData(
"SyntacticData",syntacticData);
168 auto sb = std::dynamic_pointer_cast<SegmentationData>(analysis.
getData(
"SentenceBoundaries"));
171 LDEBUG <<
"FullXmlDumper: SentenceBounds not found "<< analysis.
getData(
"SentenceBoundaries").get();
172 sb = std::make_shared<SegmentationData>(
m_graph);
173 analysis.
setData(
"SentenceBoundaries",sb);
175 auto annotationData = std::dynamic_pointer_cast< AnnotationData >(analysis.
getData(
"AnnotationData"));
176 if (annotationData==0)
178 annotationData = std::make_shared<AnnotationData>();
179 if (std::dynamic_pointer_cast<AnalysisGraph>(analysis.
getData(
"AnalysisGraph")) != 0)
181 std::dynamic_pointer_cast<AnalysisGraph>(analysis.
getData(
"AnalysisGraph"))->populateAnnotationGraph(annotationData.get(),
"AnalysisGraph");
183 analysis.
setData(
"AnnotationData",annotationData);
188 std::ostream outputStream(&hsb);
189 std::set< std::pair<size_t, size_t> > alreadyDumped;
191 LDEBUG <<
"FullXmlDumper::process before printing heading";
193 outputStream <<
"<?xml version='1.0' encoding='UTF-8'?>" << std::endl;
194 outputStream <<
"<!DOCTYPE lima_analysis_dump SYSTEM \"lima-xml-output.dtd\">" << std::endl;
195 outputStream <<
"<lima_analysis_dump>" << std::endl;
200 std::vector<Segment>::iterator sbItr=(sb->getSegments()).begin();
202 auto anagraph = std::dynamic_pointer_cast<AnalysisGraph>(analysis.
getData(
"AnalysisGraph"));
205 LDEBUG <<
"FullXmlDumper:: inside if anagraph: ";
206 std::vector< bool > alreadyDumpedTokens;
207 std::map< LinguisticAnalysisStructure::Token*, uint64_t > fullTokens;
211 alreadyDumpedTokens.resize(num_vertices(*anagraph->getGraph()));
212 LDEBUG <<
"FullXmlDumper: begin of anagraph for"<< id;
213 for (boost::tie(i, i_end) = vertices(*anagraph->getGraph()); i != i_end; ++i)
215 alreadyDumpedTokens[id] =
false;
216 fullTokens[get(
vertex_token, *anagraph->getGraph(), *i)] = id;
220 LDEBUG <<
"FullXmlDumper: end of anagraph for"<< id;
222 anagraph->firstVertex(),
223 anagraph->lastVertex(),
227 false, alreadyDumpedTokens, fullTokens);
229 auto posgraph = std::dynamic_pointer_cast<AnalysisGraph>(analysis.
getData(
"PosGraph"));
232 LDEBUG <<
"FullXmlDumper:: inside if posgraph: ";
233 std::vector< bool > alreadyDumpedTokens;
234 std::map< LinguisticAnalysisStructure::Token*, uint64_t > fullTokens;
237 alreadyDumpedTokens.resize(num_vertices(*posgraph->getGraph()));
238 LDEBUG <<
"FullXmlDumper: begin of posgraph for"<< id;
239 for (boost::tie(i, i_end) = vertices(*posgraph->getGraph()); i != i_end; ++i)
241 alreadyDumpedTokens[id] =
false;
242 fullTokens[get(
vertex_token, *posgraph->getGraph(), *i)] = id;
247 LDEBUG <<
"FullXmlDumper: end of posgraph for: sbItr "<< sbItr->getLastVertex() <<
" sb-end() " << (sb->getSegments()).end()->getLastVertex();
248 outputStream <<
"<PosGraph>" << std::endl;
250 while (sbItr!=(sb->getSegments()).end())
253 LDEBUG <<
"FullXmlDumper: inside posgraph while ";
262 true, alreadyDumpedTokens, fullTokens);
269 outputStream <<
" <DetachedVertices>" << std::endl;
271 LDEBUG <<
"FullXmlDumper:: dump non-connex nodes and related edges: ";
273 for (boost::tie(i, i_end) = vertices(*posgraph->getGraph()); i != i_end; ++i)
275 LDEBUG <<
" adding non-connex vertex "<< id;
277 *posgraph->getGraph(),
285 outputStream <<
" </DetachedVertices>" << std::endl;
287 outputStream <<
"</PosGraph>" << std::endl;
298 outputStream <<
"</lima_analysis_dump>" << std::endl;
314 const std::string& graphId,
316 std::vector< bool >& alreadyDumpedTokens,
317 std::map< LinguisticAnalysisStructure::Token*, uint64_t >& fullTokens)
const
322 LDEBUG <<
"FullXmlDumper::dumpLimaData parameters: ";
323 LDEBUG <<
"begin = "<< begin;
324 LDEBUG <<
"end = " << end ;
327 LDEBUG <<
"graphId= " << graphId ;
328 LDEBUG <<
"bySentence= " << bySentence ;
330 for (uint64_t i=0; i<alreadyDumpedTokens.size(); i++) {
331 if (alreadyDumpedTokens[i]) {
LDEBUG <<
"already_dumped_tokens[" << i <<
"]=" << alreadyDumpedTokens[i];}
336 LDEBUG <<
"after LinguisticGraph" ;
338 fullTokens, alreadyDumpedTokens,
340 LDEBUG <<
"after DumpGraphVisitor" ;
343 os <<
" <sentence>" << std::endl;
347 os <<
"<"<<graphId<<
">" << std::endl;
357 LDEBUG <<
"inside dumpLimaData's try" ;
359 for (boost::tie(i, i_end) = vertices(*graph); i != i_end; ++i)
361 put(boost::vertex_color, *graph, *i, Color::white());
364 boost::breadth_first_visit(*graph, begin, boost::visitor(vis));
365 LDEBUG <<
"breadth_first_visit arguments: ";
374 os <<
" </sentence>" << std::endl;
378 os <<
"</"<<graphId<<
">" << std::endl;
389 std::ostringstream pos;
397 std::ostream& xmlStream,
398 std::map< LinguisticAnalysisStructure::Token*, uint64_t >& fullTokens,
399 std::vector< bool >& alreadyDumpedTokens,
400 const std::string& graphId)
const
404 uint64_t tokenId = (*(fullTokens.find(token))).second;
405 bool alreadyDumped = alreadyDumpedTokens[tokenId];
413 xmlStream <<
" <vertex id=\"_" << v <<
"\" />" << std::endl;
419 LWARN <<
"No token (vertex_token) for vertex " << v;
420 xmlStream <<
" <vertex id=\"_" << v <<
"\" />" << std::endl;
424 xmlStream <<
" <vertex id=\"_" << v <<
"\"";
428 if (chains.size() > 0)
430 xmlStream <<
" chains=\"";
431 VertexChainIdProp::const_iterator itChains, itChains_end;
432 itChains = chains.begin(); itChains_end = chains.end();
433 xmlStream << (*itChains); itChains++;
434 for (; itChains != itChains_end; itChains++)
436 xmlStream <<
"," << (*itChains);
440 xmlStream <<
" >" << std::endl;
442 if (graphId !=
"AnalysisGraph")
446 if (out_degree(depV, *depGraph) > 0)
449 xmlStream <<
" <deps>" << std::endl;
451 boost::tie(depIt, depIt_end) = out_edges(depV, *depGraph);
452 for (; depIt != depIt_end; depIt++)
459 LDEBUG <<
"dep " << v <<
" -> " << targV <<
" ( " << relationName <<
" )";
461 xmlStream <<
" <dep v=\"_" << targV;
463 xmlStream <<
"\" t=\"" << relationName <<
"\" />" << std::endl;
465 xmlStream <<
" </deps>" << std::endl;
474 LWARN <<
"No morphosyntactic (vertex_data) data for vertex " << v;
486 xmlStream <<
" <ref>" << tokenId <<
"</ref>" << std::endl;
488 alreadyDumpedTokens[tokenId] =
true;
489 xmlStream <<
" </vertex>" << std::endl;
495 std::ostream& xmlStream)
const
497 xmlStream <<
" <edge src=\"" << source(e, graph)
498 <<
"\" targ=\"" << target(e, graph) <<
"\" />" << std::endl;
512 if (v == m_lastVertex)
514 bool finished =
true;
516 boost::tie(it, it_end) = in_edges(v, g);
517 while (finished && (it != it_end))
519 if (get(boost::vertex_color, g,source(*it, g)) != Color::black())
539 m_dumper.outputEdge(e, g, m_os);
545 m_dumper.outputVertex(v, graph, m_syntacticData,
546 m_os, m_fullTokens, m_alreadyDumpedFullTokens, m_graphId);
This file is the main header file for the data related to annotation graphs.
A graph that stores the relations of syntactic dependency between the elements of a DependencyGraph.
DependencyGraph::out_edge_iterator DependencyGraphOutEdgeIt
DependencyGraph::vertex_descriptor DependencyGraphVertex
boost::property_map< DependencyGraph, edge_deprel_type_t >::const_type CEdgeDepRelTypePropertyMap
boost::adjacency_list< boost::vecS, boost::vecS, boost::bidirectionalS, DepVertexProperties, DepEdgeProperties > DependencyGraph
The dependency graph class.
A graph structure for linguistic analysis.
LinguisticGraph::in_edge_iterator LinguisticGraphInEdgeIt
std::set< Lima::LinguisticProcessing::LinguisticAnalysisStructure::ChainIdStruct > VertexChainIdProp
Property to identify the chains in the graph.
boost::graph_traits< LinguisticGraph >::edge_descriptor LinguisticGraphEdge
typedefs to simplify the access to various graphs elements
LinguisticGraph::vertex_iterator LinguisticGraphVertexIt
LinguisticGraph::vertex_descriptor LinguisticGraphVertex
boost::adjacency_list< boost::vecS, boost::vecS, boost::bidirectionalS, LinguisticVertexProperties > LinguisticGraph
Property to identify the chains in the graph.
Defines a Factory to create Object of type Base.
virtual void startAnalysis()=0
function called by the LIMA analyzer on start of a new document
virtual void endAnalysis()=0
function called by the LIMA analyzer on the end of a text part that is to be analyzed
defines callback interface
Holds all data that pass through the ProcessUnits Analysis data are shared pointers,...
std::shared_ptr< AnalysisData > getData(const QString &id)
return AnalysisData by id
void setData(const QString &id, std::shared_ptr< AnalysisData > data)
set an analysisData with the given id.
std::string & getParamsValueAtKey(const std::string &key)
return a message when a 'param' was not found
Manage initialization of InitializableObjects using configuration module and parameters.
const InitializationParameters & getInitializationParameters() const
get Initialization Parameters
Use this exception to signal an error in one of the configuration files.
LimaStatusCode dump(AnalysisContent &analysis, const std::string &prologue="") const
a visitor for going through the graph between two points and storing a BoWToken for every vertex that...
void discover_vertex(LinguisticGraphVertex v, const LinguisticGraph &g)
void examine_vertex(LinguisticGraphVertex v, const LinguisticGraph &g)
void examine_edge(LinguisticGraphEdge e, const LinguisticGraph &g)
LimaString getPosition(const uint64_t position) const
void dumpLimaData(std::ostream &os, const LinguisticGraphVertex begin, const LinguisticGraphVertex end, const LinguisticAnalysisStructure::AnalysisGraph *anagraph, const SyntacticAnalysis::SyntacticData *syntacticData, const std::string &graphId, bool bySentence, std::vector< bool > &alreadyDumpedTokens, std::map< LinguisticAnalysisStructure::Token *, uint64_t > &fullTokens) const
void outputEdge(const LinguisticGraphEdge e, const LinguisticGraph &graph, std::ostream &xmlStream) const
const Common::PropertyCode::PropertyCodeManager * m_propertyCodeManager
void init(Common::XMLConfigurationFiles::GroupConfigurationStructure &unitConfiguration, Manager *manager) override
initialize with parameters from configuration file.
LimaStatusCode process(AnalysisContent &analysis) const override
Process on data in analysisContent.
void outputVertex(const LinguisticGraphVertex v, const LinguisticGraph &graph, const SyntacticAnalysis::SyntacticData *syntacticData, std::ostream &xmlStream, std::map< LinguisticAnalysisStructure::Token *, uint64_t > &fullTokens, std::vector< bool > &alreadyDumpedFullTokens, const std::string &graphId) const
AnnotationGraphXmlDumper * m_annotXmlDumperPtr
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.
const LinguisticGraphVertex & firstVertex(void) const
Returns the first vertex of the graph.
Holds morphosyntactic informations.
void outputXml(std::ostream &xmlStream, const Common::PropertyCode::PropertyCodeManager &pcm, const FsaStringsPool &sp) const
holds surface data of a token
virtual void outputXml(std::ostream &xmlStream, const Common::PropertyCode::PropertyCodeManager &pcm, const FsaStringsPool &sp) const
This class points to a graph, its dependency graph and the structure that holds the maping between th...
DependencyGraphVertex depVertexForTokenVertex(const LinguisticGraphVertex &v) const
LinguisticAnalysisStructure::AnalysisGraph * iterator()
DependencyGraph * dependencyGraph()
static const MediaticData & single()
const singleton accessor
static MediaticData & changeable()
singleton accessor
static void logElapsedTime(const std::string &mess, const std::string &taskCategory=std::string(""))
log the number of microseconds since last UpdateCurrentTime
static void updateCurrentTime(const std::string &taskCategory=std::string(""))
store current time for new elapsed time computation
boost::color_traits< boost::default_color_type > Color
dump the full content of the analysis graph in XML format
#define FULLXMLDUMPER_CLASSID
LimaString utf8stdstring2limastring(const std::string &src)
SimpleFactory< MediaProcessUnit, FullXmlDumper > fullXmlDumperFactory(FULLXMLDUMPER_CLASSID)
launch exception related to the configuration file parsing