29namespace LinguisticProcessing
31namespace SpecificEntities
38 m_compactFormat(false),
44 LDEBUG <<
"SpecificEntitiesXmlLogger::SpecificEntitiesXmlLogger()";
54 LDEBUG <<
"SpecificEntitiesXmlLogger::init";
66 LWARN <<
"No 'graph' parameter in unit configuration '"
67 << unitConfiguration.
getName() <<
"' ; using PosGraph";
68 m_graph = string(
"PosGraph");
73 if (val ==
"yes" || val ==
"true" || val ==
"1")
75 m_compactFormat =
true;
83 m_followGraph = (str ==
"1" || str ==
"true" || str ==
"yes");
92 LDEBUG <<
"SpecificEntitiesXmlLogger::process";
95 auto annotationData = std::dynamic_pointer_cast< AnnotationData >(analysis.
getData(
"AnnotationData"));
96 if (annotationData ==
nullptr)
99 LERROR <<
"no annotationData ! abort";
103 auto graphp = std::dynamic_pointer_cast<LinguisticAnalysisStructure::AnalysisGraph>(analysis.
getData(m_graph));
104 if (graphp ==
nullptr)
107 LERROR <<
"no graph "<< m_graph <<
" ! abort";
110 const auto& graph = *graphp;
114 auto metadata = std::dynamic_pointer_cast<LinguisticMetaData>(analysis.
getData(
"LinguisticMetaData"));
115 if (metadata ==
nullptr)
118 LERROR <<
"no LinguisticMetaData ! abort";
123 auto& out = dstream->out();
128 offset = QString::fromStdString(metadata->getMetaData(
"StartOffset")).toUInt();
135 uint64_t offsetIndexingNode = 0;
138 offsetIndexingNode = QString::fromStdString(
139 metadata->getMetaData(
"StartOffsetIndexingNode")).toUInt();
149 docId = metadata->getMetaData(
"DocId");
158 out <<
"<entities docid=\"" << docId
159 <<
"\" offsetNode=\"" << offsetIndexingNode
160 <<
"\" offset=\"" << offset
161 <<
"\">" << std::endl;
165 out <<
"<specific_entities>" << std::endl;
176 auto tokenList = std::dynamic_pointer_cast<AnalysisGraph>(analysis.
getData(m_graph));
177 if (tokenList ==
nullptr)
179 LERROR <<
"graph " << m_graph <<
" has not been produced: check pipeline";
182 auto graph = tokenList->getGraph();
185 std::queue<LinguisticGraphVertex> toVisit;
186 std::set<LinguisticGraphVertex> visited;
187 toVisit.push(tokenList->firstVertex());
190 while (!toVisit.empty())
192 auto v = toVisit.front();
194 if (v == tokenList->lastVertex())
199 for (boost::tie(outItr, outItrEnd) = out_edges(v, *graph);
200 outItr != outItrEnd; outItr++)
202 auto next = target(*outItr, *graph);
203 if (visited.find(next) == visited.end())
205 visited.insert(next);
209 const auto annot = getSpecificEntityAnnotation(v, annotationData.get());
212 outputEntity(annotationData.get(), out, v, annot, tokenMap, offset);
220 boost::tie(itv, itv_end) = vertices(annotationData->getGraph());
221 for (; itv != itv_end; itv++)
224 if (annotationData->hasAnnotation(*itv, QString::fromUtf8(
"SpecificEntity")))
230 annot = annotationData->annotation(
233 catch (
const boost::bad_any_cast& )
236 LERROR <<
"This annotation is not a SpecificEntity; SE not logged";
242 if (!annotationData->hasIntAnnotation(*itv,
243 QString::fromStdString(m_graph)))
249 v = annotationData->intAnnotation(*itv, QString::fromStdString(m_graph));
250 outputEntity(annotationData.get(), out, v, annot, tokenMap, offset);
258 out <<
"</entities>" << std::endl;
262 out <<
"</specific_entities>" << std::endl;
269void SpecificEntitiesXmlLogger::outputEntity(
AnnotationData* annotationData,
274 uint64_t offset)
const
276 auto vToken = tokenMap[v];
278 if (vToken ==
nullptr)
281 LERROR <<
"SpecificEntitiesXmlLogger::outputEntity: Vertex " << v
282 <<
" has no entry in the analysis graph token map. This should not happen !!";
296 <<
"<pos>" << offset+annot->
getPosition() <<
"</pos>"
297 <<
"<len>" << annot->
getLength() <<
"</len>"
304 for (
auto featureItr = features.cbegin(), features_end = features.cend();
305 featureItr != features_end; featureItr++)
309 out <<
"<" << featureItr->getName();
310 out <<
" pos=\"" << featureItr->getPosition() <<
"\"";
311 out <<
" len=\"" << featureItr->getLength() <<
"\"";
314 QString::fromStdString(
315 featureItr->getValueString())
317 <<
"</" << featureItr->getName() <<
">";
323 auto matches = annotationData->
matches(m_graph,v,
"annot");
326 auto it = matches.begin();
327 for(; it != matches.end(); it++)
331 LDEBUG <<
"SpecificEntitiesXmlLogger::outputEntity: get agv = " << va1;
333 va1, QString::fromStdString(
"SpecificEntity")))
336 if( it == matches.end() )
339 LERROR <<
"SpecificEntitiesXmlLogger::outputEntity: could not find annotation of node "
340 << v <<
"in LinguisticGraph";
345 LDEBUG <<
"SpecificEntitiesXmlLogger::outputEntity: agv " << va1
346 <<
" is a SpecificEntity Annotation";
349 boost::tie(it1, it1_end) = boost::out_edges(va1, annotationData->
getGraph());
350 for (; it1 != it1_end; it1++)
352 if ( annotationData->
intAnnotation((*it1), QString::fromUtf8(
"holds"))==1)
355 LDEBUG <<
"SpecificEntitiesXmlLogger::outputEntity: embeded agv = "
359 va2, QString::fromStdString(m_graph));
360 LDEBUG <<
"SpecificEntitiesXmlLogger::outputEntity: vertex in "
361 << m_graph <<
" is " << v2;
364 va2, QString::fromUtf8(
"SpecificEntity")))
367 va2, QString::fromUtf8(
"SpecificEntity")
369 LDEBUG <<
"SpecificEntitiesXmlLogger::outputEntity: annot2 = " << annot2;
370 outputEntity(annotationData,out, v2, annot2, tokenMap, offset);
376 out <<
"</components>"
377 <<
"<normalization>";
379 LDEBUG <<
"SpecificEntitiesXmlLogger::outputEntity: features:" << features;
380 for (
auto featureItr = features.begin(), features_end=features.end();
381 featureItr != features_end; featureItr++)
385 out <<
"<" << featureItr->getName() <<
">";
387 QString::fromStdString(featureItr->getValueString())).toStdString();
388 out <<
"</" << featureItr->getName() <<
">";
391 out <<
"</normalization>"
392 <<
"</entity>" << std::endl;
398 out <<
"<specific_entity>" << std::endl;
401 <<
"</string>" << std::endl;
402 out <<
" <position>" << vToken->position()<<
"</position>" << endl;
403 out <<
" <length>" << vToken->length() <<
"</length>" << endl;
406 <<
"</type>" << std::endl;
407 out <<
" <normalization>" << std::endl;
410 LDEBUG <<
"SpecificEntitiesXmlLogger::outputEntity: features:" << features;
411 for (
auto featureItr = features.begin(), features_end = features.end();
412 featureItr != features_end; featureItr++)
416 out <<
" <" << featureItr->getName() <<
">";
418 QString::fromStdString(featureItr->getValueString())).toStdString();
419 out <<
"</" << featureItr->getName() <<
">" << std::endl;
422 out <<
" </normalization>" << std::endl;
423 out <<
"</specific_entity>" << std::endl;
428const SpecificEntityAnnotation* SpecificEntitiesXmlLogger::getSpecificEntityAnnotation(
432 const SpecificEntityAnnotation* se =
nullptr;
436 auto matches = annotationData->
matches(m_graph,v,
"annot");
437 for (
auto it = matches.cbegin(); it != matches.cend(); it++)
440 if (annotationData->
hasAnnotation(vx, QString::fromUtf8(
"SpecificEntity")))
445 QString::fromUtf8(
"SpecificEntity")).pointerValue<SpecificEntityAnnotation>();
This file is the main header file for the data related to annotation graphs.
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.
Defines a Factory to create Object of type Base.
#define SPECIFICENTITIESXMLLOGGER_CLASSID
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
Holds an annotation graph and gives an API to manipulate it.
uint64_t intAnnotation(AnnotationGraphVertex v1, AnnotationGraphVertex v2, const LimaString &annot) const
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.
const GenericAnnotation & annotation(AnnotationGraphVertex v1, AnnotationGraphVertex v2, const LimaString &annot) const
ValueType * pointerValue()
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
std::shared_ptr< DumperStream > initialize(AnalysisContent &analysis) const
virtual void init(Common::XMLConfigurationFiles::GroupConfigurationStructure &unitConfiguration, Manager *manager) override
initialize with parameters from configuration file.
virtual LimaStatusCode process(AnalysisContent &analysis) const override
Process on data in analysisContent.
virtual void init(Common::XMLConfigurationFiles::GroupConfigurationStructure &unitConfiguration, Manager *manager) override
initialize with parameters from configuration file.
SpecificEntitiesXmlLogger()
A representation of a specific entity to store in the annotation graph.
const Automaton::EntityFeatures & getFeatures() const
uint64_t getLength() const
Common::MediaticData::EntityType getType() const
uint64_t getPosition() const
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
AnnotationGraph & getGraph()
AnnotationGraph::vertex_iterator AnnotationGraphVertexIt
AnnotationGraph::vertex_descriptor AnnotationGraphVertex
AnnotationGraph::out_edge_iterator AnnotationGraphOutEdgeIt
bool hasAnnotation(AnnotationGraphVertex v, const LimaString &annot) const
LimaString transcodeToXmlEntities(const LimaString &str)
SimpleFactory< MediaProcessUnit, SpecificEntitiesXmlLogger > specificEntitiesXmlLoggerFactory(SPECIFICENTITIESXMLLOGGER_CLASSID)