49namespace LinguisticProcessing {
50namespace SemanticAnalysis {
79 LWARN <<
"No 'graph' parameter in unit configuration '"
80 << unitConfiguration.
getName() <<
"' ; using PosGraph";
81 m_graph=string(
"PosGraph");
91 LDEBUG <<
"SemanticRelationsXmlLogger";
93 auto annotationData = std::dynamic_pointer_cast< AnnotationData >(analysis.
getData(
"AnnotationData"));
95 const auto& graph = *(std::dynamic_pointer_cast<LinguisticAnalysisStructure::AnalysisGraph>(analysis.
getData(m_graph)));
99 auto metadata = std::dynamic_pointer_cast<LinguisticMetaData>(analysis.
getData(
"LinguisticMetaData"));
102 LERROR <<
"no LinguisticMetaData ! abort";
107 std::ostream& outputStream=dstream->out();
118 offset=atoi(metadata->getMetaData(
"StartOffset").c_str());
124 uint64_t offsetIndexingNode(0);
126 offsetIndexingNode=atoi(metadata->getMetaData(
"StartOffsetIndexingNode").c_str());
132 std::string docId(
"");
134 docId=metadata->getMetaData(
"DocId");
140 outputStream <<
"<?xml version='1.0' encoding='UTF-8'?>" << std::endl;
141 outputStream <<
"<semantic_relation_dump>" << std::endl;
143 outputStream <<
"<relations docid=\"" << docId
144 <<
"\" offsetNode=\"" << offsetIndexingNode
151 boost::tie(itv, itv_end) = vertices(annotationData->getGraph());
152 for (; itv != itv_end; itv++)
154 LDEBUG <<
"SemanticRelationsXmlLogger on annotation vertex " << *itv;
164 catch (
const boost::bad_any_cast& e)
167 LERROR <<
"This annotation is not a SemanticRelation";
172 outputStream <<
"<annotation type=\"" << annot->
getType() <<
"\">" << endl
173 << vertexStringForSemanticAnnotation(
"vertex", *itv, tokenMap, annotationData.get(), offset)
174 <<
"</annotation>" << endl;
181 boost::tie(it, it_end) = edges(annotGraph);
182 for (; it != it_end; it++) {
183 LDEBUG <<
"SemanticRelationsXmlLogger on annotation edge "
184 << source(*it,annotGraph) <<
"->" << target(*it,annotationData->getGraph());
188 LDEBUG <<
"found semantic relation";
195 catch (
const boost::bad_any_cast& e)
198 LERROR <<
"This annotation is not a SemanticAnnotation";
203 outputStream <<
"<relation type=\"" << annot->
type() <<
"\">" << endl
204 << vertexStringForSemanticAnnotation(
"source",source(*it,annotGraph),tokenMap,annotationData.get(),offset)
205 << vertexStringForSemanticAnnotation(
"target",target(*it,annotGraph),tokenMap,annotationData.get(),offset)
206 <<
"</relation>" << endl;
212 outputStream <<
"</relations>" << endl;
214 outputStream <<
"</semantic_relation_dump>" << std::endl;
220std::string SemanticRelationsXmlLogger::
221vertexStringForSemanticAnnotation(
const std::string& vertexRole,
225 uint64_t offset)
const
243 LERROR <<
"Vertex " << v <<
" has no entry in the analysis graph token map. This should not happen !!";
252 std::set< AnnotationGraphVertex > matches = annotationData->
matches(m_graph,v,
"annot");
253 for (std::set< AnnotationGraphVertex >::const_iterator it = matches.begin();
254 it != matches.end(); it++)
260 .pointerValue<SpecificEntityAnnotation>();
262 catch (
const boost::bad_any_cast& e) {
264 LERROR <<
"This annotation is not a SemanticAnnotation";
268 oss <<
" <" << vertexRole
270 <<
" pos=\"" << offset+vToken->
position() <<
"\""
271 <<
" len=\"" << vToken->
length() <<
"\""
This file is the main header file for the data related to annotation graphs.
boost::adjacency_list< boost::vecS, boost::vecS, boost::bidirectionalS, AGVertexProperties, AGEdgeProperties > AnnotationGraph
The graph class.
boost::property_map< LinguisticGraph, vertex_token_t >::type VertexTokenPropertyMap
LinguisticGraph::vertex_descriptor LinguisticGraphVertex
boost::adjacency_list< boost::vecS, boost::vecS, boost::bidirectionalS, LinguisticVertexProperties > LinguisticGraph
Property to identify the chains in the graph.
#define SEMANTICANALYSISLOGINIT
#define SEMANTICRELATIONSXMLLOGGER_CLASSID
Defines a Factory to create Object of type Base.
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
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.
holds surface data of a token
uint64_t position() const
const LimaString & stringForm() const
const std::string & getType() const
An annotation between two annotation graph vertices denoting the semantic relation(s) holding between...
SemanticRelationsXmlLogger()
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.
virtual ~SemanticRelationsXmlLogger()
A representation of a specific entity to store in the annotation graph.
Common::MediaticData::EntityType getType() 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::vertex_iterator AnnotationGraphVertexIt
AnnotationGraph::edge_iterator AnnotationGraphEdgeIt
AnnotationGraph::vertex_descriptor AnnotationGraphVertex
bool hasIntAnnotation(AnnotationGraphVertex v, const LimaString &annot) const
bool hasAnnotation(AnnotationGraphVertex v, const LimaString &annot) const
std::string limastring2utf8stdstring(const Lima::LimaString &phrase, uint32_t size0)
Convert a wide string to a string , in dest up to size bytes.
LimaString utf8stdstring2limastring(const std::string &src)
SimpleFactory< MediaProcessUnit, SemanticRelationsXmlLogger > semanticRelationsXmlLoggerFactory(SEMANTICRELATIONSXMLLOGGER_CLASSID)