LIMA
Libre Multilingual Analyzer — C++ API
Loading...
Searching...
No Matches
EventTemplate.cpp
Go to the documentation of this file.
1// Copyright (C) 2011 by CEA LIST
2// SPDX-FileCopyrightText: 2022 CEA LIST <gael.de-chalendar@cea.fr>
3//
4// SPDX-License-Identifier: MIT
5
6#include "EventTemplate.h"
7
8namespace Lima {
9namespace LinguisticProcessing {
10namespace EventAnalysis {
11
13m_template(),
14m_weight(0.0),
15m_mainEvent(false),
16m_type(),
17m_posBegin(std::numeric_limits<uint64_t>::max()),
18m_posEnd(0)
19{
20}
21
22EventTemplate::EventTemplate(const std::string& type):
23m_template(),
24m_weight(0.0),
25m_mainEvent(false),
26m_type(type),
27m_posBegin(0),
28m_posEnd(0)
29{
30}
31
34
35void EventTemplate::addElement(const std::string& role,
36 const EventTemplateElement& elt,
37 unsigned int cardinality)
38{
39 if (m_template.count(role)>=cardinality) {
40 // Too many values for the same role: which ones to keep ?
41 // at this stage, we do not have any info on the order in which the values
42 // were inserted (they are sorted by the multimap) :
43 // we choose to just ignore the new values to be added
45 LDEBUG << "EventTemplate::addElement: too many values for role" << role <<": ignore new value '"<< elt << "'";
46 return;
47 }
48 m_template.emplace(role,elt);
49 uint64_t posBegin=elt.getPositionBegin();
50 uint64_t posEnd=elt.getPositionEnd();
51 if (posEnd > m_posEnd) {
52 m_posEnd=posEnd;
53 }
54 if (posBegin < m_posBegin) {
55 m_posBegin=posBegin;
56 }
57}
58
60{
61 // overwrite existing elements
62 clear();
63 m_template=elts;
65 LDEBUG << "EventTemplate::setTemplateElements: set"<<m_template.size()<<"new elements";
66 // set global position
67 for (const auto& elt: m_template) {
68 uint64_t posBegin=elt.second.getPositionBegin();
69 uint64_t posEnd=elt.second.getPositionEnd();
70 if (posEnd > m_posEnd) {
71 m_posEnd=posEnd;
72 }
73 if (posBegin < m_posBegin) {
74 m_posBegin=posBegin;
75 }
76 }
77 LDEBUG << "EventTemplate::setTemplateElements: new position is ["<<m_posBegin<<","<<m_posEnd<<"]";
78}
79
81{
82 m_template.clear();
83 m_weight=0.0;
84 m_mainEvent=false;
85 m_posBegin=std::numeric_limits<uint64_t>::max();
86 m_posEnd=0;
87}
88
89const EventTemplateElement& EventTemplate::getElement(const std::string& role) const
90{
91 static EventTemplateElement emptyElement;
92 std::map<std::string,EventTemplateElement>::const_iterator
93 it=m_template.find(role);
94 if (it==m_template.end()) {
96 LERROR << "No element '" << role << "' in EventTemplate";
97 return emptyElement;
98 }
99 return (*it).second;
100}
101
102std::ostream& operator<<(std::ostream& os, const EventTemplate& e)
103{
104 os << e.m_type << "/[" << e.m_posBegin << "-" << e.m_posEnd << "]";
105 for (const auto& elt: e.m_template) {
106 os << "/" << elt.first << ":" << elt.second;
107 }
108 return os;
109}
110QDebug& operator<<(QDebug& os, const EventTemplate& e)
111{
112 std::ostringstream oss;
113 oss << e;
114 os << oss.str();
115 return os;
116}
117
118
119} // end namespace
120} // end namespace
121} // end namespace
#define LDEBUG
Definition LimaCommon.h:157
#define LERROR
Definition LimaCommon.h:161
#define EVENTANALYSISLOGINIT
const EventTemplateElement & getElement(const std::string &role) const
void setTemplateElements(const TemplateElements &elts)
void addElement(const std::string &role, const EventTemplateElement &elt, unsigned int cardinality)
std::multimap< std::string, EventTemplateElement > TemplateElements
std::ostream & operator<<(std::ostream &os, const Entity &annot)
Definition Entity.cpp:160
NAUTITIA.
STL namespace.