32using namespace boost::tuples;
37typedef boost::color_traits<boost::default_color_type>
Color;
41namespace LinguisticProcessing
43namespace SyntacticAnalysis
72 auto metadata = std::dynamic_pointer_cast<LinguisticMetaData>(analysis.
getData(
"LinguisticMetaData"));
75 LERROR <<
"no LinguisticMetaData ! abort";
80 std::ostream& outputStream=dstream->out();
91 auto syntacticData = std::dynamic_pointer_cast<const SyntacticData>(analysis.
getData(
"SyntacticData"));
94 LERROR <<
"no SyntacticData ! abort";
98 auto anagraph = std::dynamic_pointer_cast<AnalysisGraph>(analysis.
getData(
"PosGraph"));
101 LERROR <<
"no AnalysisGraph ! abort";
104 auto sb = std::dynamic_pointer_cast<SegmentationData>(analysis.
getData(
"SentenceBoundaries"));
107 LERROR <<
"no SentenceBounds ! abort";
112 std::set< std::pair<size_t, size_t> > alreadyDumped;
114 outputStream <<
"<?xml version='1.0' encoding='UTF-8'?>" << std::endl;
115 outputStream <<
"<syntactic_analysis_dump>" << std::endl;
119 std::vector<Segment>::iterator sbItr=(sb->getSegments()).begin();
121 while (sbItr!=(sb->getSegments()).end())
126 dumpLimaData(outputStream,
130 syntacticData.get());
135 outputStream <<
"</syntactic_analysis_dump>" << std::endl;
145void SyntacticAnalysisXmlLogger::dumpLimaData(std::ostream& os,
150 const uint64_t offsetBegin)
const
152 std::vector< bool > alreadyDumpedTokens;
153 std::map< LinguisticAnalysisStructure::Token*, uint64_t > tokens;
157 DumpGraphVisitor vis(*
this, os,end, syntacticData,
158 tokens, alreadyDumpedTokens,
159 m_language,offsetBegin);
161 os <<
"<sentence>" << std::endl;
172 alreadyDumpedTokens.resize(num_vertices(*graph));
173 for (boost::tie(i, i_end) = vertices(*graph); i != i_end; ++i)
175 put(boost::vertex_color, *graph, *i, Color::white());
176 alreadyDumpedTokens[id] =
false;
180 boost::breadth_first_visit(*graph, begin, boost::visitor(vis));
182 catch (DumpGraphVisitor::EndOfSearch&)
185 os <<
"</sentence>" << std::endl;
193LimaString SyntacticAnalysisXmlLogger::getPosition(
194 const uint64_t position,
195 const uint64_t offsetBegin)
197 return QString::number(offsetBegin+position);
202 const uint64_t offsetBegin,
204 std::ostream& xmlStream,
205 std::map< LinguisticAnalysisStructure::Token*, uint64_t >& tokens,
206 std::vector< bool >& alreadyDumpedTokens)
const
211 xmlStream <<
"<vertex id=\"" << v <<
"\" />" << std::endl;
216 auto tokenId = (*(tokens.find(token))).second;
219 xmlStream <<
"<vertex id=\"" << v <<
"\" form=\""
220 << token->stringForm().toStdString() <<
"\" pos=\""
221 << getPosition(token->position(), offsetBegin).toStdString()
224 xmlStream <<
" >" << std::endl;
225 if (chains.size() > 0)
227 xmlStream <<
"<chains>" << std::endl;
228 auto itChains = chains.cbegin();
auto itChains_end = chains.cend();
229 for (; itChains != itChains_end; itChains++)
231 const auto& ids = (*itChains);
232 xmlStream <<
"<chain type=\"";
239 xmlStream <<
"\" id=\"" << (ids.chainId()) <<
"\" />" << std::endl;
241 xmlStream <<
"</chains>" << std::endl;
246 if (out_degree(depV, *depGraph) > 0)
249 xmlStream <<
"<dependents>" << std::endl;
251 boost::tie(depIt, depIt_end) = out_edges(depV, *depGraph);
252 for (; depIt != depIt_end; depIt++)
254 auto depTargV = target(*depIt, *depGraph);
255 auto targV = syntacticData-> tokenVertexForDepVertex(depTargV);
258 xmlStream <<
"<dep v=\"" << targV;
267 xmlStream <<
"\" t=\"" << relName <<
"\" />" << std::endl;
269 xmlStream <<
"</dependents>" << std::endl;
275 word->outputXml(xmlStream, *m_propertyCodeManager, sp);
276 xmlStream <<
"<ref>" << tokenId <<
"</ref>" << std::endl;
277 alreadyDumpedTokens[tokenId] =
true;
278 xmlStream <<
"</vertex>" << std::endl;
284 std::ostream& xmlStream)
const
286 xmlStream <<
" <edge src=\"" << source(e, graph)
287 <<
"\" targ=\"" << target(e, graph) <<
"\" />" << std::endl;
301 if (v == m_lastVertex)
303 bool finished =
true;
305 boost::tie(it, it_end) = in_edges(v, g);
306 while (finished && (it != it_end))
308 if (get(boost::vertex_color, g,source(*it, g)) != Color::black())
328 m_dumper.outputEdge(e, g, m_os);
334 m_dumper.outputVertex(v, graph, m_offsetBegin, m_syntacticData,
335 m_os, m_tokens, m_alreadyDumpedTokens);
DependencyGraph::out_edge_iterator DependencyGraphOutEdgeIt
boost::property_map< DependencyGraph, edge_deprel_type_t >::const_type CEdgeDepRelTypePropertyMap
LinguisticGraph::in_edge_iterator LinguisticGraphInEdgeIt
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.
boost::color_traits< boost::default_color_type > Color
Debug logger for dependency graphs.
#define SYNTACTICANALYSISXMLLOGGER_CLASSID
Data used for the syntactic analyzis of texts.
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
Manage initialization of InitializableObjects using configuration module and parameters.
const InitializationParameters & getInitializationParameters() const
get Initialization Parameters
std::shared_ptr< DumperStream > initialize(AnalysisContent &analysis) const
virtual void init(Common::XMLConfigurationFiles::GroupConfigurationStructure &unitConfiguration, Manager *manager) override
initialize with parameters from configuration file.
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.
virtual LimaStatusCode process(AnalysisContent &analysis) const override
Do the job of logging the dependency graph of the given text analysis.
virtual ~SyntacticAnalysisXmlLogger()
Default destructor.
virtual void init(Common::XMLConfigurationFiles::GroupConfigurationStructure &unitConfiguration, Manager *manager) override
MediaProcessUnit initialization method.
SyntacticAnalysisXmlLogger()
Default constructor.
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 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
SimpleFactory< MediaProcessUnit, SyntacticAnalysisXmlLogger > syntacticAnalysisXmlLoggerFactory(SYNTACTICANALYSISXMLLOGGER_CLASSID)