LIMA
Libre Multilingual Analyzer — C++ API
Loading...
Searching...
No Matches
EventParagraph.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 EventParagraph.cpp
8 * @author Faiza GARA
9 * @date April 2008
10 * @version $Id:
11 * copyright Copyright (C) 2008 by CEA LIST
12 *
13 ***********************************************************************/
14
15
16#include "EventParagraph.h"
21
22
23
24using namespace std;
27using namespace Lima::Common::MediaticData;
29
30namespace Lima {
31namespace LinguisticProcessing
32{
33
34namespace EventAnalysis
35{
36
37//**********************************************************************
38// constructors,destructor,copy assignment
39//**********************************************************************
40EventParagraph::EventParagraph() : m_splitted(false), m_otherentities(), m_evententities(), m_length(0), m_position(0), m_id(0)
41{
42
43}
44
46{
47 m_length=p->getLength();
48 m_id=p->getId();
49 m_position=p->getPosition();
50 this->addEventEntities(p,annotationData,graphId,graph);
51 this->addEntities(p,annotationData,graphId,graph);
52 m_splitted=false;
53}
54
55EventParagraph::EventParagraph(Paragraph *p, bool splitted,Common::AnnotationGraphs::AnnotationData* annotationData, std::string graphId,LinguisticGraph* graph)
56{
57 m_length=p->getLength();
58 m_id=p->getId();
59 m_position=p->getPosition();
60 this->addEventEntities(p,annotationData,graphId,graph);
61 this->addEntities(p,annotationData,graphId,graph);
62 m_splitted=splitted;
63}
64
65Lima::LinguisticProcessing::Automaton::EntityFeatures EventParagraph::getEntityFeatures(LinguisticGraphVertex v, Common::AnnotationGraphs::AnnotationData* annotationData, std::string graphId)
66{
67 EntityFeatures features;
68
69 std::set< AnnotationGraphVertex > matches = annotationData->matches(graphId,v,"annot");
70 for (std::set< AnnotationGraphVertex >::const_iterator it = matches.begin();
71 it != matches.end(); it++)
72 {
74
75
76 if (annotationData->hasAnnotation(vx, Common::Misc::utf8stdstring2limastring("SpecificEntity")))
77 {
78
79
80 EntityType e;
81 e=annotationData->annotation(vx,Common::Misc::utf8stdstring2limastring("SpecificEntity")).pointerValue< SpecificEntityAnnotation>()->getType();
82
83
84 features=annotationData->annotation(vx,Common::Misc::utf8stdstring2limastring("SpecificEntity")).pointerValue< SpecificEntityAnnotation>()->getFeatures();
85 return features;
86
87 }
88 }
89 return features;
90}
91
93{
94 bool res=false;
95
96 if (m_otherentities.find(t)!=m_otherentities.end())
97 {
98 return true;
99 }
100
101 if (m_evententities.first==t && m_evententities.second.size()> 0) return true;
102
103 return res;
104}
105
107{
108 std::pair<Common::MediaticData::EntityType,std::deque<LinguisticGraphVertex> > event_pair= p->getEventEntities();
110
111 LDEBUG << "EventParagraph::addEventEntities EventEntitie type " << event_pair.first;
112 std::vector<Entity *> v_entity;
113 for(std::deque<LinguisticGraphVertex>::const_iterator iT= event_pair.second.begin(); iT != event_pair.second.end();iT++)
114 {
115 Entity *e = new Entity();
116 Token* token = get(vertex_token, *graph, *iT);
117 e->setLength(token->length());
118 e->setPosition(token->position());
119 e->setMain(false);
120 Lima::LinguisticProcessing::Automaton::EntityFeatures features=getEntityFeatures(*iT, annotationData, graphId);
121 e->setFeatures(features);
122 v_entity.push_back(e);
123 }
124 m_evententities=make_pair(event_pair.first,v_entity);
125}
126
128{
129 std::map<Common::MediaticData::EntityType,std::deque<LinguisticGraphVertex> > map_entities= p->getOtherEntities();
130 for(std::map<Common::MediaticData::EntityType,std::deque<LinguisticGraphVertex> >::const_iterator iT1 = map_entities.begin(); iT1!=map_entities.end(); iT1++)
131 {
132 std::vector<Entity *> v_entity;
133 for(std::deque<LinguisticGraphVertex>::const_iterator iT= iT1->second.begin(); iT != iT1->second.end();iT++)
134 {
135 Entity *e = new Entity();
136 Token* token = get(vertex_token, *graph, *iT);
137 e->setLength(token->length());
138 e->setPosition(token->position());
139 e->setMain(false);
140 Lima::LinguisticProcessing::Automaton::EntityFeatures features=getEntityFeatures(*iT, annotationData, graphId);
141 e->setFeatures(features);
142 v_entity.push_back(e);
143 }
144 m_otherentities[iT1->first]=v_entity;
145 }
146}
147
148// Direct insertion of a known entity
150{
151 m_evententities.first=type;
152 m_evententities.second.push_back(entity);
153}
154
156{
157 m_otherentities[type].push_back(entity);
158}
159
160void EventParagraph::read(std::istream& file)
161{
162 m_position= Common::Misc::readCodedInt(file);
163 m_length= Common::Misc::readCodedInt(file);
164 EntityType t;
165 t.setTypeId(static_cast<EntityTypeId>(Common::Misc::readCodedInt(file)));
166 t.setGroupId(static_cast<EntityGroupId>(Common::Misc::readCodedInt(file)));
167 m_evententities.first=t;
168 int size=Common::Misc::readCodedInt(file);
169 for (int i=0; i< size; i++)
170 {
171 Entity *e=new Entity();
172 e->read(file);
173 m_evententities.second.push_back(e);
174 }
175 int other_size=Common::Misc::readCodedInt(file);
176 for (int i=0; i< other_size; i++)
177 {
178 EntityType to;
179 to.setTypeId(static_cast<EntityTypeId>(Common::Misc::readCodedInt(file)));
180 to.setGroupId(static_cast<EntityGroupId>(Common::Misc::readCodedInt(file)));
181 int to_size=Common::Misc::readCodedInt(file);
182 std::vector<Entity*> v;
183 for (int j=0; j< to_size; j++)
184 {
185 Entity *e=new Entity();
186 e->read(file);
187 v.push_back(e);
188 }
189 m_otherentities[to]=v;
190 }
191}
192
193void EventParagraph::write(std::ostream& file) const
194{
196 LDEBUG << "EventParagraph::write()..";
197 Common::Misc::writeCodedInt(file,m_position);
198 Common::Misc::writeCodedInt(file,m_length);
199 LDEBUG << "EventParagraph::write: write typeId of m_evententities..."
200 << m_evententities.first.getTypeId();
201 Common::Misc::writeCodedInt(file,m_evententities.first.getTypeId());
202 LDEBUG << "EventParagraph::write: write groupId of m_evententities..."
203 << m_evententities.first.getGroupId();
204 Common::Misc::writeCodedInt(file,m_evententities.first.getGroupId());
205 Common::Misc::writeCodedInt(file,m_evententities.second.size());
206 for(std::vector<Entity*>::const_iterator iT=m_evententities.second.begin();iT!=m_evententities.second.end();iT++)
207 {
208 LDEBUG << "EventParagraph::write m_evententities";
209 (*iT)->write(file);
210 }
211 LDEBUG << "EventParagraph::write size of m_otherentities (" << m_otherentities.size() << ")....";
212 Common::Misc::writeCodedInt(file,m_otherentities.size());
213 for(std::map<EntityType,std::vector<Entity *> >::const_iterator iT=m_otherentities.begin();
214 iT!=m_otherentities.end();iT++)
215 {
216 LDEBUG << "EventParagraph::write m_otherentity....";
217 Common::Misc::writeCodedInt(file,(*iT).first.getTypeId());
218 Common::Misc::writeCodedInt(file,(*iT).first.getGroupId());
219 Common::Misc::writeCodedInt(file,(*iT).second.size());
220 for(std::vector<Entity *>::const_iterator iT2 =(*iT).second.begin();iT2!=(*iT).second.end();iT2++)
221 {
222 (*iT2)->write(file);
223 }
224 }
225}
226
231
233{
234 for(std::vector<Entity *>::const_iterator iT=m_evententities.second.begin();iT!=m_evententities.second.end();iT++)
235 {
236 if ((*iT)!=0) delete (*iT);
237 }
238 m_evententities.second.clear();
239 for(std::map<Common::MediaticData::EntityType,std::vector<Entity *> >::const_iterator iTm=m_otherentities.begin();iTm!=m_otherentities.end();iTm++)
240 {
241
242 for(std::vector<Entity *>::const_iterator iT=(*iTm).second.begin();iT!=(*iTm).second.end();iT++)
243 {
244 if ((*iT)!=0) delete (*iT);
245 }
246 }
247 m_otherentities.clear();
248}
249
250std::string EventParagraph::toString(std::string parentURI, uint64_t index, bool main) const
251{
252 LIMA_UNUSED(parentURI);
253 LIMA_UNUSED(index);
255 std::ostringstream oss;
256 oss << "<rdf:rdf xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\""
257 << " xmlns:dc=\"http://purl.org/dc/elements/1.1/\"" << std::endl;
258 oss << "<dc:creator>CEA LIST Specific entities extraction service</dc:creator>";
259 oss << "</rdf:rdf>";
260// return oss.str();
261
262 std::string out;
263 for(std::vector<Entity *>::const_iterator iT=m_evententities.second.begin();iT!=m_evententities.second.end();iT++)
264 {
265
266 }
267
268 for(std::map<Common::MediaticData::EntityType,std::vector<Entity *> >::const_iterator iTm=m_otherentities.begin();iTm!=m_otherentities.end();iTm++)
269 {
270
271 for(std::vector<Entity *>::const_iterator iT=(*iTm).second.begin();iT!=(*iTm).second.end();iT++)
272 {
273
274 }
275 }
276 return out;
277}
278
279
280} // namespace
281} // namespace
282} // namespace Lima
#define LIMA_UNUSED(x)
Definition LimaCommon.h:224
#define LDEBUG
Definition LimaCommon.h:157
@ vertex_token
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 setGroupId(EntityGroupId groupId)
a list of generic features: each feature is unique (only one feature for a name)
void setFeatures(Lima::LinguisticProcessing::Automaton::EntityFeatures features)
Definition Entity.h:50
virtual void read(std::istream &file)
Definition Entity.cpp:106
bool has_entity(Common::MediaticData::EntityType t) const
std::string toString(std::string parentURI, uint64_t index, bool main) const
void addEventEntity(const Common::MediaticData::EntityType &type, Entity *entity)
void addEntities(Paragraph *p, Common::AnnotationGraphs::AnnotationData *, std::string graphId, LinguisticGraph *graph)
void addEntity(const Common::MediaticData::EntityType &type, Entity *entity)
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 Paragraph.h:45
std::map< Common::MediaticData::EntityType, std::deque< LinguisticGraphVertex > > getOtherEntities() const
Definition Paragraph.h:155
std::pair< Common::MediaticData::EntityType, std::deque< LinguisticGraphVertex > > getEventEntities() const
Definition Paragraph.h:150
AnnotationGraph::vertex_descriptor AnnotationGraphVertex
bool hasAnnotation(AnnotationGraphVertex v, const LimaString &annot) const
int main(int argc, char *argv[])
Definition main.cpp:14
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)
NAUTITIA.
STL namespace.