LIMA
Libre Multilingual Analyzer — C++ API
Loading...
Searching...
No Matches
Event.cpp
Go to the documentation of this file.
1// Copyright 2002-2013 CEA LIST
2// SPDX-FileCopyrightText: 2022 CEA LIST <gael.de-chalendar@cea.fr>
3//
4// SPDX-License-Identifier: MIT
5
6/************************************************************************
7 * @file Event.cpp
8 * @author Faiza GARA
9 * @date October 2008
10 * @version $Id:
11 * copyright Copyright (C) 2008 by CEA LIST
12 *
13 ***********************************************************************/
14
15
16#include "Event.h"
17
23
24
25
26using namespace std;
28
29namespace Lima {
30namespace LinguisticProcessing
31{
32
33namespace EventAnalysis
34{
35
36//**********************************************************************
37// constructors,destructor,copy assignment
38//**********************************************************************
40 std::vector< EventParagraph* >(), m_entities_weight(0), m_main(false)
41{
43 LDEBUG << "Nouvel évènement";
44}
45
47{
48 for(std::vector< EventParagraph* >::const_iterator iT=begin(); iT !=end(); iT++)
49 {
50 if ((*iT) !=0){
51 (*iT)->clear();
52 }
53 }
54 clear();
55
56}
57
59{
60// EVENTANALYZERLOGINIT;
61 for(std::vector<EventParagraph*>::const_iterator iT=begin();iT!=end();iT++)
62 {
63 std::pair<Common::MediaticData::EntityType,std::vector<Entity *> > event=(*iT)->getEventEntities();
64 std::map<Common::MediaticData::EntityType,std::vector<Entity *> > otherentities=(*iT)->getOtherEntities();
65 std::vector<Entity *> v_entity = event.second;
66 if(v_entity.size() > 0)
67 {
68 Entity *entity = v_entity[0];
69 entity->setMain(true);
70 }
71 for ( std::map<Common::MediaticData::EntityType,std::vector<Entity *> >::const_iterator iT=otherentities.begin();iT!=otherentities.end();iT++)
72 {
73 v_entity = (*iT).second;
74 if(v_entity.size() > 0)
75 {
76 Entity *entity = v_entity[0];
77 entity->setMain(true);
78 }
79 }
80 }
81}
82
83void Event::compute_entities_weight(std::map<Common::MediaticData::EntityType,unsigned short> map_weights,Common::AnnotationGraphs::AnnotationData* annotation, std::string graphId)
84{
85 LIMA_UNUSED(annotation);
86 LIMA_UNUSED(graphId);
88
89
90// unsigned short number_computed_entities=0;
91 for(std::map<Common::MediaticData::EntityType,unsigned short>::iterator iT=map_weights.begin();iT!=map_weights.end();iT++)
92 {
93 if (has_entity((*iT).first)) m_entities_weight=m_entities_weight+(*iT).second;
94 }
95
96 LDEBUG << "computed entities_weight of event = " << m_entities_weight;
97}
98
100{
101 bool res=false;
102
103 if (t==m_date.first) return true;
104
105 for(std::vector<EventParagraph*>::const_iterator iT=begin();iT!=end() && !res;iT++)
106 {
107 res=(*iT)->has_entity(t);
108 }
109 return res;
110}
111
113{
115 std::set< AnnotationGraphVertex > matches = annotationData->matches(graphId,v,"annot");
116 for (std::set< AnnotationGraphVertex >::const_iterator it = matches.begin();
117 it != matches.end(); it++)
118 {
120
121 if (annotationData->hasAnnotation(vx, Common::Misc::utf8stdstring2limastring("SpecificEntity")))
122 {
123
124 e=annotationData->annotation(vx,Common::Misc::utf8stdstring2limastring("SpecificEntity")).pointerValue< SpecificEntityAnnotation>()->getType();
125 return e;
126 }
127 }
128 return e;
129}
130void Event::addParagraph(Paragraph *p,bool firstpos,bool split,Common::AnnotationGraphs::AnnotationData* annotationData, std::string graphId,LinguisticGraph* graph)
131{
133 LDEBUG << "Ajout de Paragraph";
134
135 EventParagraph *ep =new EventParagraph(p,split,annotationData,graphId,graph);
136 if (this->size()==0) push_back(ep);
137 else
138 {
139 EventParagraph *lastp =this->back();
140 if ((lastp->getId()+1) == p->getId() && firstpos && (lastp->is_splitted() == false))
141 {
142 LDEBUG << "Les deux paragraphes sont contigus";
143 // ce sont deux paragraphes contigüs
144 // ajouter tous les élément de p dans lastp et changer l'indice de lastp
145 lastp->setId(p->getId());
146 lastp->setLength(lastp->getLength()+p->getLength());
147 //lastp->addSentences(p);
148 lastp->addEventEntities(p,annotationData,graphId,graph);
149 lastp->addEntities(p,annotationData,graphId,graph);
150 this->pop_back();
151 this->push_back(lastp);
152 delete(ep);
153 }
154 else
155 {
156 // ce sont deux paragraphes non contigüs
157 this->push_back(ep);
158 LDEBUG << "Les deux paragraphes appartiennent à des sections différentes";
159 }
160 delete(p);
161 }
162
163}
164
165
166
167
168/**********************************************************************
169 * Returns the next annotation. It will be no more available
170 */
171
172
173//**********************************************************************
174// read/write in binary format
175//**********************************************************************
176void Event::read(std::istream& file) {
178 m_main=Common::Misc::readCodedInt(file);
179 uint64_t size=Common::Misc::readCodedInt(file);
180 LDEBUG << " Read Main = " << m_main;
181 LDEBUG << " Read size of fragments " << size;
182 for (uint64_t i(0); i<size; i++) {
184 p->read(file);
185 push_back(p);
186 }
187}
188
189void Event::write(std::ostream& file) const {
191 LDEBUG << "Event::write()..";
192 //EVENTANALYZERLOGINIT;
193 Common::Misc::writeCodedInt(file,m_main);
194 Common::Misc::writeCodedInt(file,size());
195 LDEBUG << " Write size of fragments " << size();
196 for (std::vector< EventParagraph* >::const_iterator iT=begin(); iT!=end(); iT++) {
197 (*iT)->write(file);
198 }
199}
200
201std::string Event::toString(std::string parentURI, uint64_t index) const
202{
203 std::string out;
204
205 for (std::vector< EventParagraph* >::const_iterator iT=begin(); iT!=end(); iT++) {
206 out.append((*iT)->toString(parentURI, index, m_main));
207 }
208
209 return out;
210}
211
212std::ostream& operator << (std::ostream& os, const Event& text) {
213 for (Event::const_iterator i(text.begin());
214 i != text.end(); i++) {
215 //os << (*i)->getOutputUTF8String() << std::endl;
216 }
217 return os;
218}
219
220
221
222} // namespace
223} // namespace
224} // namespace Lima
#define LIMA_UNUSED(x)
Definition LimaCommon.h:224
#define LDEBUG
Definition LimaCommon.h:157
LinguisticGraph::vertex_descriptor LinguisticGraphVertex
boost::adjacency_list< boost::vecS, boost::vecS, boost::bidirectionalS, LinguisticVertexProperties > LinguisticGraph
Property to identify the chains in the graph.
#define EVENTANALYZERLOGINIT
#define EVENTANALYSISLOGINIT
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
void addEntities(Paragraph *p, Common::AnnotationGraphs::AnnotationData *, std::string graphId, LinguisticGraph *graph)
void addEventEntities(Paragraph *p, Common::AnnotationGraphs::AnnotationData *, std::string graphId, LinguisticGraph *graph)
This class represents a list of elements, that are pointers on polymmorphic annotations that can be d...
Definition Event.h:44
bool has_entity(Common::MediaticData::EntityType) const
Definition Event.cpp:99
void addParagraph(Paragraph *, bool, bool, Common::AnnotationGraphs::AnnotationData *, std::string graphId, LinguisticGraph *graph)
Definition Event.cpp:130
virtual void write(std::ostream &file) const
Definition Event.cpp:189
void compute_entities_weight(std::map< Common::MediaticData::EntityType, unsigned short >, Common::AnnotationGraphs::AnnotationData *, std::string graphId)
Definition Event.cpp:83
Common::MediaticData::EntityType getEntityType(LinguisticGraphVertex, Common::AnnotationGraphs::AnnotationData *, std::string graphId) const
Definition Event.cpp:112
virtual void read(std::istream &file)
Definition Event.cpp:176
std::string toString(std::string parentURI, uint64_t index) const
Definition Event.cpp:201
This class represents a list of elements, that are pointers on polymmorphic annotations that can be d...
Definition Paragraph.h:45
AnnotationGraph::vertex_descriptor AnnotationGraphVertex
bool hasAnnotation(AnnotationGraphVertex v, const LimaString &annot) const
uint64_t readCodedInt(std::istream &file)
read a integer coded in variable-byte format in a file
void writeCodedInt(std::ostream &file, const uint64_t number)
write a integer coded in variable-byte format in a file
LimaString utf8stdstring2limastring(const std::string &src)
std::ostream & operator<<(std::ostream &os, const Entity &annot)
Definition Entity.cpp:160
NAUTITIA.
STL namespace.