33using namespace boost::tuples;
46namespace LinguisticProcessing
48namespace EventAnalysis
88 LERROR <<
"No DateEntity defined in "<<unitConfiguration.
getName()<<
" configuration group for language " << m_language;
97 LERROR <<
"No EventEntity defined in "<<unitConfiguration.
getName()<<
" configuration group for language " << m_language;
102 for(deque<string>::iterator itr=otherEntities.begin();itr !=otherEntities.end();itr++)
109 LERROR <<
"No OtherEntities defined in "<<unitConfiguration.
getName()<<
" configuration group for language " << m_language;
113 std::map<std::string,std::string>& weights=unitConfiguration.
getMapAtKey(
"EntitiesWeights");
114 LDEBUG <<
"Weights map size =" << weights.size();
115 for (std::map<std::string,std::string>::const_iterator it=weights.begin();
126 LERROR <<
"No map 'EntitiesWeigths' in "<<unitConfiguration.
getName()<<
" configuration group for language " << m_language;
141 LDEBUG <<
"start EventSegmentation";
144 auto anagraph = std::dynamic_pointer_cast<AnalysisGraph>(analysis.
getData(m_graphId));
147 LERROR <<
"no "<< m_graphId <<
" ! abort";
150 auto annotationData = std::dynamic_pointer_cast< AnnotationData >(analysis.
getData(
"AnnotationData"));
151 if (annotationData==0)
153 LERROR <<
"no AnnotationData ! abort";
156 auto sb = std::dynamic_pointer_cast<SegmentationData>(analysis.
getData(
"SentenceBoundaries"));
159 LERROR <<
"no SentenceBoundaries ! abort";
162 auto pb = std::dynamic_pointer_cast<SegmentationData>(analysis.
getData(
"ParagraphBoundaries"));
165 LERROR <<
"no ParagraphBoundaries ! abort";
169 std::vector<Paragraph*> v_paragraph;
170 compute_paragraphs(v_paragraph,anagraph->getGraph(),anagraph.get(),sb.get(), pb.get(), annotationData.get());
172 std::map<std::string,Event*> map_event;
173 compute_events(map_event,v_paragraph,anagraph->getGraph(),annotationData.get(),m_graphId);
178 uint64_t max_weight=0;
180 for (std::map<std::string,Event*>::const_iterator iT=map_event.begin();iT!=map_event.end();iT++)
183 if ((*iT).second->get_weight() > max_weight)
185 max_weight=(*iT).second->get_weight();
186 main_event=(*iT).second;
189 eventData->push_back((*iT).second);
191 LDEBUG <<
"Le nombre d'évènements différents est égal à = " << map_event.size();
195 LDEBUG <<
"Le meilleur poids est égal à = " << max_weight;
202 for (Events::const_iterator it=eventData->begin(),it_end=eventData->end();it!=it_end;it++) {
205 if (event->getMain()) {
211 for (Event::const_iterator it2=event->begin(),it2_end=
event->end();it2!=it2_end;it2++) {
218 analysis.
setData(
"EventSegmentationData",segmData);
229 for (uint64_t i=0; i<v_par.size();i++)
238 LDEBUG <<
"Paragraph numéro : " << (i+1) <<
" a filtrer ";
242 LDEBUG <<
"Paragraph numéro : " << (i+1) <<
" a étudier ayant comme nombre de date = " << p->
getDatesSize();
247 std::pair<string,LinguisticGraphVertex> date=p->
getDate();
248 if (map_event.find(date.first)!=map_event.end())
250 Event *ev=map_event[date.first];
251 ev->
addParagraph(p,
true,
false,annotationData,graphId,graph);
252 map_event[date.first]=ev;
257 ev->
setDate(make_pair(m_dateEntity,date));
258 LDEBUG <<
"Creation d'un nouvel évènement ";
259 ev->
addParagraph(p,
true,
false,annotationData,graphId,graph);
260 map_event[date.first]=ev;
265 bool first_time=
true;
270 std::pair<std::string,LinguisticGraphVertex> date1=p->
extractDate();
271 std::pair<std::string,LinguisticGraphVertex> date2=p->
getDate();
274 p1->
addDate(date1.first,date1.second);
299 LDEBUG <<
"EventSegmentation evententities type " << evententities.first;
309 std::pair<string,LinguisticGraphVertex> date=p1->
getDate();
310 if (map_event.find(date.first)!=map_event.end())
312 Event *ev=map_event[date.first];
313 ev->
addParagraph(p1,first_time,
true,annotationData,graphId,graph);
314 map_event[date.first]=ev;
319 ev->
setDate(make_pair(m_dateEntity,date));
320 LDEBUG <<
"Creation d'un nouvel évènement ";
321 ev->
addParagraph(p1,first_time,
true,annotationData,graphId,graph);
322 map_event[date.first]=ev;
333 std::pair<string,LinguisticGraphVertex> date=p->
getDate();
334 if (map_event.find(date.first)!=map_event.end())
336 Event *ev=map_event[date.first];
337 ev->
addParagraph(p,
false,
false,annotationData,graphId,graph);
338 map_event[date.first]=ev;
343 ev->
setDate(make_pair(m_dateEntity,date));
344 LDEBUG <<
"Creation d'un nouvel évènement ";
345 ev->
addParagraph(p,
false,
false,annotationData,graphId,graph);
346 map_event[date.first]=ev;
369 std::set<LinguisticGraphVertex> visited;
370 std::queue<LinguisticGraphVertex> toVisit;
371 toVisit.push(firstVx);
376 uint64_t id_paragraph=1;
377 p->
setId(id_paragraph);
380 Token* previous_token=0;
385 std::string current_date=
"00-00-00";
387 while (!toVisit.empty())
394 for (boost::tie(outItr,outItrEnd)=out_edges(v,*graph);
399 if (visited.find(next)==visited.end())
401 visited.insert(next);
406 if (v != firstVx && v != lastVx)
408 LDEBUG <<
"Traitement du vertex " << v;
409 LDEBUG <<
"current_date du vertex " << current_date;
415 LDEBUG <<
"Je suis dans le Début d'un nouveau paragraphe ";
416 current_date=
"00-00-00";
418 uint64_t par_position=v_par[v_par.size()-1]->getPosition();
419 uint64_t last_position=previous_token->
position()+previous_token->
length()-1;
420 v_par[v_par.size()-1]->setLength(last_position-par_position+1);
425 v_par[v_par.size()-1]->setId(id_paragraph);
426 v_par[v_par.size()-1]->setPosition(position);
431 LDEBUG <<
"Je suis dans un vertex de type Entité nommée ";
435 string date=
getDate(v,annotationData,m_dateEntity);
436 LDEBUG <<
"Je suis dans Date ";
437 LDEBUG <<
"Valeur de la Date =" << date;
438 if (date.compare(
"00-00-00")==0)
441 LDEBUG <<
"Date mal normalisée à ignorer";
445 v_par[v_par.size()-1]->addDate(date,v);
453 LDEBUG <<
"Je suis dans Evenement ";
454 v_par[v_par.size()-1]->addEventEntity(m_eventEntity,v);
460 LDEBUG <<
"Je suis dans les autres types d'EN ";
462 v_par[v_par.size()-1]->addEntity(e,v);
470 LDEBUG <<
"Je suis dans fin d'une phrase ";
472 v_par[v_par.size()-1]->addSentence(v);
479 uint64_t par_position=v_par[v_par.size()-1]->getPosition();
480 uint64_t last_position=previous_token->
position()+previous_token->
length()-1;
481 v_par[v_par.size()-1]->setLength(last_position-par_position+1);
482 LDEBUG <<
"par_position " << par_position <<
", last_position" << last_position;
486 previous_token=token;
495 for (std::vector<Segment>::const_iterator it=(tb->
getSegments()).begin(),it_end=(tb->
getSegments()).end();
498 if ((*it).getLastVertex() == v)
return true;
506 std::set< AnnotationGraphVertex > matches = annotationData->
matches(m_graphId,v,
"annot");
507 for (std::set< AnnotationGraphVertex >::const_iterator it = matches.begin();
508 it != matches.end(); it++)
524 std::set< AnnotationGraphVertex > matches = annotationData->
matches(m_graphId,v,
"annot");
525 for (std::set< AnnotationGraphVertex >::const_iterator it = matches.begin();
526 it != matches.end(); it++)
529 LDEBUG <<
"Looking at annotation graph vertex " << vx;
535 if (e==t)
return true;
544 std::set< AnnotationGraphVertex > matches = annotationData->
matches(graphId,v,
"annot");
545 for (std::set< AnnotationGraphVertex >::const_iterator it = matches.begin();
546 it != matches.end(); it++)
563 std::string normalizedForm=
"00-00-00";
564 std::string year=
"00";
565 std::string month=
"00";
566 std::string day=
"00";
568 std::set< AnnotationGraphVertex > matches = annotationData->
matches(m_graphId,v,
"annot");
569 for (std::set< AnnotationGraphVertex >::const_iterator it = matches.begin();
570 it != matches.end(); it++)
573 LDEBUG <<
"Looking at annotation graph vertex " << vx;
585 for (Automaton::EntityFeatures::const_iterator
586 featureItr=features.begin(),features_end=features.end();
587 featureItr!=features_end; featureItr++)
589 LDEBUG <<
"Looking for feature=" << featureItr->getName() <<
", value=" << featureItr->getValueString();
590 if (featureItr->getName().compare(
"date") == 0)
591 return (featureItr->getValueString());
592 if (featureItr->getName().compare(
"year") == 0)
593 year=featureItr->getValueString();
594 if (featureItr->getName().compare(
"month") == 0)
595 month=featureItr->getValueString();
596 if (featureItr->getName().compare(
"day") == 0)
597 day=featureItr->getValueString();
602 normalizedForm= year;
603 normalizedForm.insert(normalizedForm.end(),
'-');
604 normalizedForm.append(month);
605 normalizedForm.insert(normalizedForm.end(),
'-');
606 normalizedForm.append(day);
607 LDEBUG <<
"Returned normalizedForm = " << normalizedForm;
608 return (normalizedForm);
614 std::set< AnnotationGraphVertex > matches = annotationData->
matches(m_graphId,v,
"annot");
615 for (std::set< AnnotationGraphVertex >::const_iterator it = matches.begin();
616 it != matches.end(); it++)
619 LDEBUG <<
"Looking at annotation graph vertex " << vx;
625 if (eset.find(e)!=eset.end())
return true;
#define EVENTSEGMENTATION_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)
uint64_t getLength() const
uint64_t getPosition() const
bool is_specific_entity_in(LinguisticGraphVertex, Common::AnnotationGraphs::AnnotationData *, std::set< Common::MediaticData::EntityType >) const
bool is_a_bound(LinguisticGraphVertex, SegmentationData *) const
void compute_paragraphs(std::vector< Paragraph * > &, LinguisticGraph *, LinguisticAnalysisStructure::AnalysisGraph *, SegmentationData *, SegmentationData *, Common::AnnotationGraphs::AnnotationData *) const
std::string getDate(LinguisticGraphVertex, Common::AnnotationGraphs::AnnotationData *, Common::MediaticData::EntityType) const
bool is_specific_entity(LinguisticGraphVertex, Common::AnnotationGraphs::AnnotationData *) const
void init(Common::XMLConfigurationFiles::GroupConfigurationStructure &unitConfiguration, Manager *manager) override
initialize with parameters from configuration file.
LimaStatusCode process(AnalysisContent &analysis) const override
void compute_events(std::map< std::string, Event * > &, std::vector< Paragraph * >, LinguisticGraph *, Common::AnnotationGraphs::AnnotationData *, std::string) const
Common::MediaticData::EntityType getEntityType(LinguisticGraphVertex, Common::AnnotationGraphs::AnnotationData *, std::string graphId) 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 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
void setVerticesFromPositions(uint64_t posBegin, uint64_t length, LinguisticAnalysisStructure::AnalysisGraph *anagraph)
void add(const Segment &s)
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
LimaString utf8stdstring2limastring(const std::string &src)
SimpleFactory< MediaProcessUnit, EventSegmentation > EventSegmentationFactory(EVENTSEGMENTATION_CLASSID)
static const struct TextHtmlEntity entities[]