LIMA
Libre Multilingual Analyzer — C++ API
Loading...
Searching...
No Matches
EventTemplateData.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 *
8 * @file EventTemplateData.cpp
9 * @author Romaric Besancon (romaric.besancon@cea.fr)
10 * @date Fri Sep 2 2011
11 * copyright Copyright (C) 2011 by CEA LIST
12 *
13 ***********************************************************************/
14
15#include "EventTemplateData.h"
18#include "Events.h"
19#include "Entity.h"
20
21using namespace std;
22using namespace Lima::Common;
23using namespace Lima::Common::AnnotationGraphs;
25//using namespace boost;
26
27namespace Lima {
28namespace LinguisticProcessing {
29namespace EventAnalysis {
30
31// create default template data with one empty event template to store
37
40
42{
43 push_back(EventTemplate());
44}
45
47 const EventTemplateElement& elt,
48 unsigned int cardinality)
49{
50 back().addElement(role,elt,cardinality);
51}
52
54{
55 back().clear();
56}
57
59{
61 LDEBUG << "set Current Template Type " << type;
62 back().setType(type);
63 LDEBUG << "bak.getType " << back().getType();
64}
65
66//-------------------------------------------------------------------------------
67// conversion to Events (for compatibility with EventExtraction web service)
69convertToEvents(const AnnotationData* annotationData) const
70{
71 Events* events=new Events();
72
73 int eventNum=1;
74 for (std::vector<EventTemplate>::const_iterator it= begin(); it!= end();it++)
75 {
76 const TemplateElements& templateElements=(*it).getTemplateElements();
77 if (! templateElements.empty()) {
78 // one event per template
79 Event* event=new Event();
80 // only one paragraph per event
81 EventParagraph* eventPar=new EventParagraph();
82 event->push_back(eventPar);
83 /*if ((*it).isMainEvent()) {
84 event->setMain();
85 }
86 event->setWeight((*it).getWeight());*/
87 eventPar->setId(eventNum);
88 // set position and length of paragraph using position and length of template elements
89 uint64_t posBeginPar(ULONG_MAX);
90 uint64_t posEndPar(0);
91 for(map<string,EventTemplateElement>::const_iterator it1= templateElements.begin(); it1!= templateElements.end();it1++)
92 {
93 const LinguisticAnalysisStructure::AnalysisGraph* graph=(*it1).second.getGraph();
94 LinguisticGraphVertex v=(*it1).second.getVertex();
95 MediaticData::EntityType type=(*it1).second.getType();
96 Entity* e=createEntity(graph, v, annotationData, (*it1).first, eventNum);
97 if (e->getPosition() < posBeginPar) {
98 posBeginPar=e->getPosition();
99 }
100 uint64_t posEnd=e->getPosition()+e->getLength();
101 if (posEnd > posEndPar) {
102 posEndPar=posEnd;
103 }
104 if (e!=0) {
105 eventPar->addEntity(type,e);
106 }
107 }
108 eventPar->setPosition(posBeginPar);
109 eventPar->setLength(posEndPar-posBeginPar);
110 events->push_back(event);
111 eventNum++;
112 }
113 }
114 return events;
115}
116
117Entity* EventTemplateData::
118createEntity(const LinguisticAnalysisStructure::AnalysisGraph* graph,
120 const AnnotationData* annotationData,
121 const std::string& role,
122 uint64_t eventId) const
123{
124 LinguisticAnalysisStructure::Token* token=get(vertex_token, *(graph->getGraph()), v);
125 if (token==0) {
126 EVENTANALYSISLOGINIT; LWARN << "EventTemplateDataXmlLogger: no token for vertex " << v;
127 return 0;
128 }
129
130 // store eventId feature as string (for output in WebLab)
131 ostringstream eid;
132 eid << eventId;
133
134 // check if vertex corresponds to a specific entity found
135 std::set< AnnotationGraphVertex > matches = annotationData->matches(graph->getGraphId(),v,"annot");
136 for (std::set< AnnotationGraphVertex >::const_iterator it = matches.begin();
137 it != matches.end(); it++)
138 {
140 if (annotationData->hasAnnotation(vx, Common::Misc::utf8stdstring2limastring("SpecificEntity")))
141 {
142 const SpecificEntityAnnotation* se =
143 annotationData->annotation(vx, Common::Misc::utf8stdstring2limastring("SpecificEntity")).
144 pointerValue<SpecificEntityAnnotation>();
145
147 features.setFeature("role",role);
148 features.setFeature("eventId",eid.str());
149 Entity* e=new Entity(token->position(),token->length(),features);
150 e->setMain(true);
151 return e;
152 }
153 }
154
155 // otherwise, have to create entity features
157 features.setFeature("value",token->stringForm());
158 features.setFeature("role",role);
159 features.setFeature("eventId",eid.str());
160 Entity* e=new Entity(token->position(),token->length(),features);
161 e->setMain(true);
162 return e;
163}
164
165} // end namespace
166} // end namespace
167} // end namespace
This file is the main header file for the data related to annotation graphs.
#define LWARN
Definition LimaCommon.h:160
#define LDEBUG
Definition LimaCommon.h:157
@ vertex_token
LinguisticGraph::vertex_descriptor LinguisticGraphVertex
#define EVENTANALYSISLOGINIT
just for semantics: base class for analysisData
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
a list of generic features: each feature is unique (only one feature for a name)
void setFeature(const std::string &name, const ValueType &value)
void addEntity(const Common::MediaticData::EntityType &type, Entity *entity)
Events * convertToEvents(const Common::AnnotationGraphs::AnnotationData *annotationData) const
void addElementInCurrentTemplate(const std::string &role, const EventTemplateElement &elt, unsigned int cardinality)
This class represents a list of elements, that are pointers on polymmorphic annotations that can be d...
Definition Event.h:44
An AnalysisData containing a LinguisticGraph with a language and an id.
const LinguisticGraph * getGraph(void) const
Returns the underlying graph structure.
A representation of a specific entity to store in the annotation graph.
AnnotationGraph::vertex_descriptor AnnotationGraphVertex
bool hasAnnotation(AnnotationGraphVertex v, const LimaString &annot) const
LimaString utf8stdstring2limastring(const std::string &src)
std::multimap< std::string, EventTemplateElement > TemplateElements
NAUTITIA.
STL namespace.