25#include <boost/algorithm/string.hpp>
34namespace LinguisticProcessing {
35namespace EventAnalysis {
44m_eventData(
"EventTemplateData")
58 LDEBUG <<
"EventTemplateDataXmlLogger::init";
66 LDEBUG <<
"EventTemplateDataXmlLogger: no parameter 'eventTemplateData', use default ('"<<m_eventData <<
"')";
74 LDEBUG <<
"EventTemplateDataXmlLogger::process";
79 ostream& out=dstream->out();
81 const auto annotationData = std::dynamic_pointer_cast< AnnotationData >(analysis.
getData(
"AnnotationData"));
82 if (annotationData==0)
84 LERROR <<
"no annotation graph available !";
88 if (! m_eventData.empty()) {
89 auto data = analysis.
getData(m_eventData);
92 auto eventData = std::dynamic_pointer_cast<const EventTemplateData>(data);
95 LERROR <<
"data '" << m_eventData <<
"' is neither of type EventData nor Events";
99 outputEventData(out, eventData.get(), annotationData.get());
104 LERROR <<
"no data of name " << m_eventData;
111void EventTemplateDataXmlLogger::outputEventData(std::ostream& out,
116 out <<
"<events>" << endl;
117 for (std::vector<EventTemplate>::const_iterator it= eventData->begin(); it!= eventData->end();it++)
120 if (! templateElements.empty()) {
122 out <<
" <event id=\"" << i <<
"\""
123 <<
" w=\"" << (*it).getWeight() <<
"\""
124 <<
" main=\"" << (*it).isMainEvent() <<
"\""
125 <<
" type=\"" << (*it).getType() <<
"\">"
128 out <<
" <entities>" << endl;
129 for(map<string,EventTemplateElement>::const_iterator it1= templateElements.begin(); it1!= templateElements.end();it1++)
132 out <<
" <entity role=\"" << (*it1).first <<
"\""
133 <<
" type=\"" << typeName <<
"\">"
137 outputEntity(out, graph, v,annotationData);
138 out <<
" </entity>" << endl;
141 out <<
" </entities>" << endl;
142 out <<
" </event>" << endl;
145 out <<
"</events>" << endl;
149void EventTemplateDataXmlLogger::outputEntity(std::ostream& out,
159 out <<
" <entityOccurrence"
160 <<
" pos=\"" << token->
position() <<
"\""
161 <<
" len=\"" << token->
length() <<
"\"";
163 string str(
""),norm(
"");
167 std::set< AnnotationGraphVertex > matches = annotationData->
matches(graph->
getGraphId(),v,
"annot");
168 for (std::set< AnnotationGraphVertex >::const_iterator it = matches.begin();
169 it != matches.end(); it++)
176 pointerValue<SpecificEntityAnnotation>();
179 for (Automaton::EntityFeatures::const_iterator
180 featureItr=features.begin(),features_end=features.end();
181 featureItr!=features_end; featureItr++)
183 if (featureItr->getName()==
"value") {
184 norm=xmlString(featureItr->getValueString());
191 out <<
" string=\"" << str <<
"\"";
192 out <<
" norm=\"" << norm <<
"\"";
195 out <<
"</entityOccurrence>" << endl;
198std::string EventTemplateDataXmlLogger::xmlString(
const std::string& inputStr)
const
201 std::string str(inputStr);
202 boost::replace_all(str,
"&",
"&");
203 boost::replace_all(str,
"<",
"<");
204 boost::replace_all(str,
">",
">");
205 boost::replace_all(str,
"\"",
""");
206 boost::replace_all(str,
"\n",
"\n");
This file is the main header file for the data related to annotation graphs.
#define EVENTTEMPLATEDATAXMLLOGGER_CLASSID
LinguisticGraph::vertex_descriptor LinguisticGraphVertex
#define EVENTANALYSISLOGINIT
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.
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.
std::shared_ptr< DumperStream > initialize(AnalysisContent &analysis) const
virtual void init(Common::XMLConfigurationFiles::GroupConfigurationStructure &unitConfiguration, Manager *manager) override
initialize with parameters from configuration file.
a list of generic features: each feature is unique (only one feature for a name)
virtual LimaStatusCode process(AnalysisContent &analysis) const override
Process on data in analysisContent.
virtual ~EventTemplateDataXmlLogger()
EventTemplateDataXmlLogger()
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 std::string & getGraphId(void) const
const LinguisticGraph * getGraph(void) const
Returns the underlying graph structure.
holds surface data of a token
uint64_t position() const
const LimaString & stringForm() const
A representation of a specific entity to store in the annotation graph.
const Automaton::EntityFeatures & getFeatures() const
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_descriptor AnnotationGraphVertex
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)
std::multimap< std::string, EventTemplateElement > TemplateElements
SimpleFactory< MediaProcessUnit, EventTemplateDataXmlLogger > EventTemplateDataXmlLoggerFactory(EVENTTEMPLATEDATAXMLLOGGER_CLASSID)