21#include <boost/algorithm/string.hpp>
28namespace LinguisticProcessing {
29namespace EventAnalysis {
38m_eventData(
"EventData")
52 LDEBUG <<
"EventXmlLogger::init";
65 LDEBUG <<
"EventXmlLogger::process";
70 ostream& out=dstream->out();
72 if (! m_eventData.empty()) {
73 auto data = analysis.
getData(m_eventData);
76 auto events = std::dynamic_pointer_cast<const Events>(data);
78 LDEBUG <<
"data '" << m_eventData <<
"' is of type Events";
79 outputEvents(out, events.get());
83 auto eventData = std::dynamic_pointer_cast<const EventData>(data);
85 LDEBUG <<
"data '" << m_eventData <<
"' is of type EventData";
86 outputEventData(out, eventData.get());
90 auto eventTemplateData = std::dynamic_pointer_cast<const EventTemplateData>(data);
91 if (eventTemplateData!=0) {
92 LDEBUG <<
"data '" << m_eventData <<
"' is of type EventTemplateData";
94 auto annotationData = std::dynamic_pointer_cast< AnnotationData >(analysis.
getData(
"AnnotationData"));
95 if (annotationData==0)
97 LERROR <<
"no annotation graph available !";
101 outputEvents(out, eventTemplateData->convertToEvents(annotationData.get()));
105 LERROR <<
"data '" << m_eventData <<
"' is neither of type EventData nor Events";
112 LERROR <<
"no data of name " << m_eventData;
119void EventXmlLogger::outputEvents(std::ostream& out,
120 const Events* eventData)
const
123 out <<
"<events>" << endl;
124 for (std::vector<Event*>::const_iterator iT= eventData->begin(); iT!= eventData->end();iT++)
127 out <<
"<event id=\"" << i <<
"\""
128 <<
" w=\"" << (*iT)->get_weight() <<
"\""
129 <<
" main=\"" << (*iT)->getMain() <<
"\">" << endl;
130 out <<
"<segments>" << endl;
132 for(std::vector<EventParagraph*>::const_iterator iT1= (*iT)->begin(); iT1!= (*iT)->end();iT1++)
134 out <<
" <paragraph id=\"" << j <<
"\" pos=\"" << (*iT1)->getPosition() <<
"\" len=\"" << (*iT1)->getLength() <<
"\">" << endl;
135 std::map<Common::MediaticData::EntityType,std::vector<Entity *> > otherEntities=(*iT1)->getOtherEntities();
136 out <<
" <entities>" << endl;
141 out <<
" <entity type=\"" << entityTypeName <<
"\">" << endl;
142 for(std::vector<Entity *>::const_iterator iT3=(*iT2).second.begin();iT3!=(*iT2).second.end();iT3++)
144 outputEntity(out,**iT3);
146 out <<
" </entity>" << endl;
148 std::pair<Common::MediaticData::EntityType,std::vector<Entity *> > eventEntities=(*iT1)->getEventEntities();
149 if (! eventEntities.second.empty()) {
150 out <<
" <entity type=\"" << eventEntities.first <<
"\">" << endl;
151 for(std::vector<Entity *>::const_iterator iT3=eventEntities.second.begin();iT3!=eventEntities.second.end();iT3++)
153 outputEntity(out,**iT3);
155 out <<
" </entity>" << endl;
157 out <<
" </entities>" << endl;
158 out <<
" </paragraph>" << endl;
161 out <<
"</segments>" << endl;
162 out <<
"</event>" << endl;
164 out <<
"</events>" << endl;
167void EventXmlLogger::outputEventData(std::ostream& out,
168 const EventData* eventData)
const
170 out <<
"<events>" << endl;
171 out <<
"<event id=\"" << 1 <<
"\""
172 <<
" w=\"" << 1 <<
"\""
173 <<
" main=\"true\">" << endl;
174 out <<
" <entities>" << endl;
175 const map<Common::MediaticData::EntityType,vector<Entity> >&
entities=eventData->getEntities();
179 for(std::vector<Entity>::const_iterator e=(*it).second.begin(),e_end=(*it).second.end();e!=e_end;e++)
181 outputEntity(out,*e);
183 out <<
" </entity>" << endl;
185 out <<
" </entities>" << endl;
187 out <<
"</event>" << endl;
188 out <<
"</events>" << endl;
191void EventXmlLogger::outputEntity(std::ostream& out,
const Entity& e)
const
193 out <<
" <entityOccurrence"
194 <<
" pos=\"" << e.getPosition() <<
"\""
195 <<
" len=\"" <<e.getLength() <<
"\"";
196 string str(
""),norm(
""),role(
"");
197 const Automaton::EntityFeatures& features=e.getFeatures();
198 for (Automaton::EntityFeatures::const_iterator
199 featureItr=features.begin(),features_end=features.end();
200 featureItr!=features_end; featureItr++)
202 if (featureItr->getName()==
"value") {
203 str=xmlString(featureItr->getValueString());
206 else if (featureItr->getName()==
"role") {
207 role=xmlString(featureItr->getValueString());
210 norm=xmlString(featureItr->getValueString());
213 if (! role.empty()) {
214 out <<
" role=\"" << role <<
"\"";
217 out <<
" string=\"" << str <<
"\"";
218 out <<
" norm=\"" << str <<
"\"";
220 out <<
" main=\"true\"";
222 if (! norm.empty()) {
231 out <<
" main=\"true\"";
235 out <<
"</entityOccurrence>" << endl;
238std::string EventXmlLogger::xmlString(
const std::string& inputStr)
const
241 std::string str(inputStr);
242 boost::replace_all(str,
"&",
"&");
243 boost::replace_all(str,
"<",
"<");
244 boost::replace_all(str,
">",
">");
245 boost::replace_all(str,
"\"",
""");
246 boost::replace_all(str,
"\n",
"\n");
#define EVENTXMLLOGGER_CLASSID
#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
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.
virtual void init(Lima::Common::XMLConfigurationFiles::GroupConfigurationStructure &unitConfiguration, Manager *manager) override
initialize with parameters from configuration file.
virtual ~EventXmlLogger()
virtual LimaStatusCode process(AnalysisContent &analysis) const override
Process on data in analysisContent.
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
std::string limastring2utf8stdstring(const Lima::LimaString &phrase, uint32_t size0)
Convert a wide string to a string , in dest up to size bytes.
SimpleFactory< MediaProcessUnit, EventXmlLogger > EventXmlLoggerFactory(EVENTXMLLOGGER_CLASSID)
static const struct TextHtmlEntity entities[]