33using namespace boost::tuples;
46namespace LinguisticProcessing
48namespace EventAnalysis
72 LDEBUG <<
"EventAnalyzer::init()...";
90 LERROR <<
"No DateEntity defined in "<<unitConfiguration.
getName()<<
" configuration group for language " << m_language;
99 LERROR <<
"No EventEntity defined in "<<unitConfiguration.
getName()<<
" configuration group for language " << m_language;
104 for(deque<string>::iterator itr=otherEntities.begin();itr !=otherEntities.end();itr++)
111 LERROR <<
"No OtherEntities defined in "<<unitConfiguration.
getName()<<
" configuration group for language " << m_language;
115 std::map<std::string,std::string>& weights=unitConfiguration.
getMapAtKey(
"EntitiesWeights");
116 LDEBUG <<
"Weights map size =" << weights.size();
117 for (std::map<std::string,std::string>::const_iterator it=weights.begin();
121 LDEBUG <<
"Init EntitiesWeights: "
125 <<
" , weight " << atoi((it->second).c_str());
131 LERROR <<
"No map 'EntitiesWeigths' in "<<unitConfiguration.
getName()<<
" configuration group for language " << m_language;
147 LDEBUG <<
"start EventAnalyzer";
150 auto anagraph = std::dynamic_pointer_cast<AnalysisGraph>(analysis.
getData(m_graphId));
153 LERROR <<
"no "<< m_graphId <<
" ! abort";
156 auto annotationData = std::dynamic_pointer_cast< AnnotationData >(analysis.
getData(
"AnnotationData"));
157 if (annotationData==0)
159 LERROR <<
"no AnnotationData ! abort";
162 auto sb = std::dynamic_pointer_cast<SegmentationData>(analysis.
getData(
"SentenceBoundaries"));
165 LERROR <<
"no SentenceBoundaries ! abort";
168 auto pb = std::dynamic_pointer_cast<SegmentationData>(analysis.
getData(
"ParagraphBoundaries"));
171 LERROR <<
"no ParagraphBoundaries ! abort";
174 std::vector<Paragraph*> v_paragraph;
175 compute_paragraphs(v_paragraph,anagraph->getGraph(),anagraph.get(),sb.get(), pb.get(), annotationData.get());
177 std::map<std::string,Event*> map_event;
178 compute_events(map_event,v_paragraph,anagraph->getGraph(), annotationData.get(), m_graphId);
183 uint64_t max_weight=0;
185 for (std::map<std::string,Event*>::const_iterator iT=map_event.begin();iT!=map_event.end();iT++)
188 if ((*iT).second->get_weight() > max_weight)
190 max_weight=(*iT).second->get_weight();
191 main_event=(*iT).second;
194 eventData->push_back((*iT).second);
196 LDEBUG <<
"Le nombre d'évènements différents est égal à = " << map_event.size();
198 LDEBUG <<
"set new data 'EventData' of type Events";
199 analysis.
setData(
"EventData",eventData);
203 LDEBUG <<
"Le meilleur poids est égal à = " << max_weight;
209 for (std::vector<Event*>::const_iterator iT= eventData->begin(); iT!= eventData->end();iT++)
212 LDEBUG <<
"Event N° " << i;
213 LDEBUG <<
" a pour poids " << (*iT)->get_weight();
214 LDEBUG <<
" a pour valeur main " << (*iT)->getMain();
215 LDEBUG <<
" est composé des fragments de texte suivants ";
217 for(std::vector<EventParagraph*>::const_iterator iT1= (*iT)->begin(); iT1!= (*iT)->end();iT1++)
219 LDEBUG <<
" paragraph " << j <<
" position = " << (*iT1)->getPosition() <<
" , longueur = " << (*iT1)->getLength() ;
220 std::map<Common::MediaticData::EntityType,std::vector<Entity *> > otherEntities=(*iT1)->getOtherEntities();
221 LDEBUG <<
" les entités sont";
224 LDEBUG <<
" type=" << (*iT2).first;
225 for(std::vector<Entity *>::const_iterator iT3=(*iT2).second.begin();iT3!=(*iT2).second.end();iT3++)
227 LDEBUG <<
" position=" << (*iT3)->getPosition() <<
" ,longueur = " <<(*iT3)->getLength()<<
", main =" << (*iT3)->getMain();
229 for (Automaton::EntityFeatures::const_iterator
230 featureItr=features.begin(),features_end=features.end();
231 featureItr!=features_end; featureItr++)
233 LDEBUG <<
" Feature=" << featureItr->getName() <<
", value=" << featureItr->getValueString();
237 std::pair<Common::MediaticData::EntityType,std::vector<Entity *> > eventEntities=(*iT1)->getEventEntities();
238 LDEBUG <<
" Event type=" << eventEntities.first;
239 for(std::vector<Entity *>::const_iterator iT3=eventEntities.second.begin();iT3!=eventEntities.second.end();iT3++)
241 LDEBUG <<
" position=" << (*iT3)->getPosition() <<
" ,longueur = " <<(*iT3)->getLength()<<
", main =" << (*iT3)->getMain();
243 for (Automaton::EntityFeatures::const_iterator
244 featureItr=features.begin(),features_end=features.end();
245 featureItr!=features_end; featureItr++)
247 LDEBUG <<
" Feature=" << featureItr->getName() <<
", value=" << featureItr->getValueString();
260 std::string graphId)
const
265 for (uint64_t i=0; i<v_par.size();i++)
274 LDEBUG <<
"Paragraph numéro : " << (i+1) <<
" a filtrer ";
278 LDEBUG <<
"Paragraph numéro : " << (i+1) <<
" a étudier ayant comme nombre de date = " << p->
getDatesSize();
283 std::pair<string,LinguisticGraphVertex> date=p->
getDate();
284 if (map_event.find(date.first)!=map_event.end())
286 Event *ev=map_event[date.first];
287 ev->
addParagraph(p,
true,
false,annotationData,graphId,graph);
288 map_event[date.first]=ev;
293 ev->
setDate(make_pair(m_dateEntity,date));
294 LDEBUG <<
"Creation d'un nouvel évènement ";
295 ev->
addParagraph(p,
true,
false,annotationData,graphId,graph);
296 map_event[date.first]=ev;
301 bool first_time=
true;
306 std::pair<std::string,LinguisticGraphVertex> date1=p->
extractDate();
307 std::pair<std::string,LinguisticGraphVertex> date2=p->
getDate();
310 p1->
addDate(date1.first,date1.second);
335 LDEBUG <<
"EventAnalyzer evententities type " << evententities.first;
345 std::pair<string,LinguisticGraphVertex> date=p1->
getDate();
346 if (map_event.find(date.first)!=map_event.end())
348 Event *ev=map_event[date.first];
349 ev->
addParagraph(p1,first_time,
true,annotationData,graphId,graph);
350 map_event[date.first]=ev;
355 ev->
setDate(make_pair(m_dateEntity,date));
356 LDEBUG <<
"Creation d'un nouvel évènement ";
357 ev->
addParagraph(p1,first_time,
true,annotationData,graphId,graph);
358 map_event[date.first]=ev;
369 std::pair<string,LinguisticGraphVertex> date=p->
getDate();
370 if (map_event.find(date.first)!=map_event.end())
372 Event *ev=map_event[date.first];
373 ev->
addParagraph(p,
false,
false,annotationData,graphId,graph);
374 map_event[date.first]=ev;
379 ev->
setDate(make_pair(m_dateEntity,date));
380 LDEBUG <<
"Creation d'un nouvel évènement ";
381 ev->
addParagraph(p,
false,
false,annotationData,graphId,graph);
382 map_event[date.first]=ev;
405 std::set<LinguisticGraphVertex> visited;
406 std::queue<LinguisticGraphVertex> toVisit;
407 LDEBUG <<
"compute_paragraphs: push vertex " << firstVx;
408 toVisit.push(firstVx);
413 uint64_t id_paragraph=1;
414 p->
setId(id_paragraph);
417 Token* previous_token=0;
422 std::string current_date=
"00-00-00";
424 while (!toVisit.empty())
427 LDEBUG <<
"compute_paragraphs: pop vertex " << v;
432 for (boost::tie(outItr,outItrEnd)=out_edges(v,*graph);
437 if (visited.find(next)==visited.end())
439 visited.insert(next);
440 LDEBUG <<
"compute_paragraphs: push vertex " << next;
445 if (v != firstVx && v != lastVx)
447 LDEBUG <<
"Traitement du vertex " << v;
448 LDEBUG <<
"current_date du vertex " << current_date;
454 LDEBUG <<
"Je suis dans le Début d'un nouveau paragraphe ";
455 current_date=
"00-00-00";
457 uint64_t par_position=v_par[v_par.size()-1]->getPosition();
458 uint64_t last_position=previous_token->
position()+previous_token->
length()-1;
459 v_par[v_par.size()-1]->setLength(last_position-par_position+1);
464 v_par[v_par.size()-1]->setId(id_paragraph);
465 v_par[v_par.size()-1]->setPosition(position);
470 LDEBUG <<
"Je suis dans un vertex de type Entité nommée ";
474 string date=
getDate(v,annotationData,m_dateEntity);
475 LDEBUG <<
"Je suis dans Date ";
476 LDEBUG <<
"Valeur de la Date =" << date;
477 if (date.compare(
"00-00-00")==0)
480 LDEBUG <<
"Date mal normalisée à ignorer";
484 v_par[v_par.size()-1]->addDate(date,v);
492 LDEBUG <<
"Je suis dans Evenement ";
493 v_par[v_par.size()-1]->addEventEntity(m_eventEntity,v);
499 LDEBUG <<
"Je suis dans les autres types d'EN ";
501 v_par[v_par.size()-1]->addEntity(e,v);
509 LDEBUG <<
"Je suis dans fin d'une phrase ";
511 v_par[v_par.size()-1]->addSentence(v);
518 uint64_t par_position=v_par[v_par.size()-1]->getPosition();
519 uint64_t last_position=previous_token->
position()+previous_token->
length()-1;
520 v_par[v_par.size()-1]->setLength(last_position-par_position+1);
521 LDEBUG <<
"par_position " << par_position <<
", last_position" << last_position;
525 previous_token=token;
534 for (std::vector<Segment>::const_iterator it=(tb->
getSegments()).begin(),
538 if ((*it).getLastVertex() == v)
return true;
548 LDEBUG <<
"is_specific_entity at " << v <<
" according to annot?";
549 std::set< AnnotationGraphVertex > matches = annotationData->
matches(m_graphId,v,
"annot");
550 for (std::set< AnnotationGraphVertex >::const_iterator it = matches.begin();
551 it != matches.end(); it++)
557 LDEBUG <<
" ...return true";
561 LDEBUG <<
" ...return false";
568 std::set< AnnotationGraphVertex > matches = annotationData->
matches(m_graphId,v,
"annot");
573 LDEBUG <<
"is_specific_entity(" << entityName <<
" at " << v <<
" ) ?";
575 for (std::set< AnnotationGraphVertex >::const_iterator it = matches.begin();
576 it != matches.end(); it++)
580 LDEBUG <<
"Looking at annotation graph vertex " << vx <<
" for " << entityName;
588 LDEBUG <<
"is_specific_entity(" << entityName <<
" at " << v <<
" ) return true";
595 LDEBUG <<
"is_specific_entity(" << entityName <<
" at " << v <<
" ) return false";
601 ,std::string graphId)
const
604 std::set< AnnotationGraphVertex > matches = annotationData->
matches(graphId,v,
"annot");
605 for (std::set< AnnotationGraphVertex >::const_iterator it = matches.begin();
606 it != matches.end(); it++)
623 std::string normalizedForm=
"00-00-00";
624 std::string year=
"00";
625 std::string month=
"00";
626 std::string day=
"00";
628 std::set< AnnotationGraphVertex > matches = annotationData->
matches(m_graphId,v,
"annot");
629 for (std::set< AnnotationGraphVertex >::const_iterator it = matches.begin();
630 it != matches.end(); it++)
633 LDEBUG <<
"Looking at annotation graph vertex " << vx;
645 for (Automaton::EntityFeatures::const_iterator
646 featureItr=features.begin(),features_end=features.end();
647 featureItr!=features_end; featureItr++)
649 LDEBUG <<
"Looking for feature=" << featureItr->getName() <<
", value=" << featureItr->getValueString();
650 if (featureItr->getName().compare(
"date") == 0)
651 return (featureItr->getValueString());
652 if (featureItr->getName().compare(
"year") == 0)
653 year=featureItr->getValueString();
654 if (featureItr->getName().compare(
"month") == 0)
655 month=featureItr->getValueString();
656 if (featureItr->getName().compare(
"day") == 0)
657 day=featureItr->getValueString();
662 normalizedForm= year;
663 normalizedForm.insert(normalizedForm.end(),
'-');
664 normalizedForm.append(month);
665 normalizedForm.insert(normalizedForm.end(),
'-');
666 normalizedForm.append(day);
667 LDEBUG <<
"Returned normalizedForm = " << normalizedForm;
668 return (normalizedForm);
675 LDEBUG <<
"is_specific_entity_in( at " << v <<
" ) ?";
676 std::set< AnnotationGraphVertex > matches = annotationData->
matches(m_graphId,v,
"annot");
677 for (std::set< AnnotationGraphVertex >::const_iterator it = matches.begin();
678 it != matches.end(); it++)
682 LDEBUG <<
"Looking at annotation graph vertex " << vx;
688 if (eset.find(e)!=eset.end())
690 LDEBUG <<
"is_specific_entity_in( at " << v <<
" ) return true";
696 LDEBUG <<
"is_specific_entity_in( at " << v <<
" ) return false";
#define EVENTANALYZERPU_CLASSID
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.
#define EVENTANALYZERLOGINIT
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
void setData(const QString &id, std::shared_ptr< AnalysisData > data)
set an analysisData with the given 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)
std::deque< std::string > & getListsValueAtKey(const std::string &key)
std::map< std::string, std::string > & getMapAtKey(const std::string &key)
return a message when a 'map' was not found
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
a list of generic features: each feature is unique (only one feature for a name)
void compute_paragraphs(std::vector< Paragraph * > &, LinguisticGraph *, LinguisticAnalysisStructure::AnalysisGraph *, SegmentationData *, SegmentationData *, Common::AnnotationGraphs::AnnotationData *) const
bool is_specific_entity(LinguisticGraphVertex, Common::AnnotationGraphs::AnnotationData *) const
void compute_events(std::map< std::string, Event * > &, std::vector< Paragraph * >, LinguisticGraph *, Common::AnnotationGraphs::AnnotationData *, std::string) const
void init(Common::XMLConfigurationFiles::GroupConfigurationStructure &unitConfiguration, Manager *manager) override
initialize with parameters from configuration file.
std::string getDate(LinguisticGraphVertex, Common::AnnotationGraphs::AnnotationData *, Common::MediaticData::EntityType) const
LimaStatusCode process(AnalysisContent &analysis) const override
bool is_specific_entity_in(LinguisticGraphVertex, Common::AnnotationGraphs::AnnotationData *, std::set< Common::MediaticData::EntityType >) const
Common::MediaticData::EntityType getEntityType(LinguisticGraphVertex, Common::AnnotationGraphs::AnnotationData *, std::string graphId) const
bool is_a_bound(LinguisticGraphVertex, SegmentationData *) const
This class represents a list of elements, that are pointers on polymmorphic annotations that can be d...
void setDate(std::pair< Common::MediaticData::EntityType, std::pair< std::string, LinguisticGraphVertex > >)
void compute_main_entities()
void addParagraph(Paragraph *, bool, bool, Common::AnnotationGraphs::AnnotationData *, std::string graphId, LinguisticGraph *graph)
void compute_entities_weight(std::map< Common::MediaticData::EntityType, unsigned short >, Common::AnnotationGraphs::AnnotationData *, std::string graphId)
This class represents a list of elements, that are pointers on polymmorphic annotations that can be d...
std::pair< std::string, LinguisticGraphVertex > extractDate()
LinguisticGraphVertex extractSentence()
void setPosition(uint64_t)
std::map< Common::MediaticData::EntityType, std::deque< LinguisticGraphVertex > > extractEntitiesBeforeVertex(LinguisticGraphVertex v, LinguisticGraph *graph)
void addEventEntities(Paragraph *p)
std::pair< std::string, LinguisticGraphVertex > getDate()
std::pair< Common::MediaticData::EntityType, std::deque< LinguisticGraphVertex > > extractEventEntitiesBeforeVertex(LinguisticGraphVertex v, LinguisticGraph *graph)
void addEntities(Paragraph *p)
void addDate(std::string, LinguisticGraphVertex)
void addSentence(LinguisticGraphVertex)
uint64_t getSentencesSize()
An AnalysisData containing a LinguisticGraph with a language and an id.
const LinguisticGraphVertex & lastVertex(void) const
Returns the last vertex of the graph.
const LinguisticGraphVertex & firstVertex(void) const
Returns the first vertex of the graph.
holds surface data of a token
uint64_t position() const
const std::vector< Segment > & getSegments() 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_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)
SimpleFactory< MediaProcessUnit, EventAnalyzer > EventAnalyzerFactory(EVENTANALYZERPU_CLASSID)
static const struct TextHtmlEntity entities[]