LIMA
Libre Multilingual Analyzer — C++ API
Loading...
Searching...
No Matches
EventTemplateFillingActions.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 EventTemplateFillingActions.cpp
9 * @author besancon (besanconr@zoe.cea.fr)
10 * @date Thu Sep 01 2011
11 * copyright Copyright (C) 2011 by CEA - LIST
12 *
13 ***********************************************************************/
14
16#include "EventTemplateData.h"
17
27
28using namespace Lima::Common::AnnotationGraphs;
31using namespace Lima::Common::AnnotationGraphs;
33using namespace std;
34
35namespace Lima {
36namespace LinguisticProcessing {
37namespace EventAnalysis {
38
39//----------------------------------------------------------------------
40// factories for action function
43
46
49
50//----------------------------------------------------------------------
52 const LimaString& complement):
53Automaton::ConstraintFunction(language,complement),
54m_role(),
55m_type()
56{
57 int i=complement.indexOf(Common::Misc::utf8stdstring2limastring(","));
58 if (i==-1) {
60 }
61 else {
62 m_role=Common::Misc::limastring2utf8stdstring(complement.left(i));
64 }
65}
66
68 const LinguisticGraphVertex& v,
69 AnalysisContent& analysis) const
70{
72 auto eventData = std::dynamic_pointer_cast<EventTemplateData>(analysis.getData("EventTemplateData"));
73 if (eventData==0) {
74 eventData = std::make_shared<EventTemplateData>();
75 analysis.setData("EventTemplateData", eventData);
76 }
77 // get the cardinality for the role in the template definition
78 unsigned int cardinality(1);
79 auto defData = std::dynamic_pointer_cast<EventTemplateDefinitionData>(analysis.getData("EventTemplateFillingTemplateDefinition"));
80 if (defData==0) {
81 LDEBUG << "AddTemplateElement: no template definition provided";
82 }
83 else {
84 cardinality=defData->resource->getCardinality(m_role);
85 }
86
87 if (! m_type.isNull()) {
88 EventTemplateElement elt(v,&graph,m_type);
89 LDEBUG << "AddTemplateElement("<< m_type <<"): add " << elt << " as " << m_role << ", cardinality =" << cardinality;
90 eventData->addElementInCurrentTemplate(m_role,elt,cardinality);
91 }
92 else {
93 //get type from specific entity associated to the vertex
94 const auto annotationData = std::dynamic_pointer_cast< AnnotationData >(analysis.getData("AnnotationData"));
95 if (annotationData==0)
96 {
98 LERROR << "AddTemplateElement: no annotation graph available !";
99 return false;
100 }
101 // check if vertex corresponds to a specific entity found
102 std::set< AnnotationGraphVertex > matches = annotationData->matches(graph.getGraphId(),v,"annot");
103 for (std::set< AnnotationGraphVertex >::const_iterator it = matches.begin();
104 it != matches.end(); it++)
105 {
107 if (annotationData->hasAnnotation(vx, Common::Misc::utf8stdstring2limastring("SpecificEntity")))
108 {
109 const SpecificEntityAnnotation* se =
110 annotationData->annotation(vx, Common::Misc::utf8stdstring2limastring("SpecificEntity")).
111 pointerValue<SpecificEntityAnnotation>();
112
113 EventTemplateElement elt(v,&graph,se->getType());
114 LDEBUG << "AddTemplateElement: add " << elt << " as " << m_role << ", cardinality =" << cardinality;
115 eventData->addElementInCurrentTemplate(m_role,elt,cardinality);
116 }
117 }
118 }
119 return true;
120}
121
123 const LinguisticGraphVertex& /*v1*/,
124 const LinguisticGraphVertex& /*v2*/,
125 AnalysisContent& /*analysis*/) const
126{
128 LERROR << "Calling constraint AddTemplateElement with two vertices: not implemented yet";
129 return true;
130}
131
132//----------------------------------------------------------------------
134 const LimaString& complement):
135Automaton::ConstraintFunction(language,complement),
136m_eventType()
137{
139 LDEBUG << "Complement" << complement;
140 m_eventType=Common::Misc::limastring2utf8stdstring(complement);
141 LDEBUG << "m_event_type" << m_eventType;
142}
143
145{
146 auto eventData = std::dynamic_pointer_cast<EventTemplateData>(analysis.getData("EventTemplateData"));
147 if (eventData==0) {
149 LERROR << "CreateEventTemplate: Missing data EventTemplateData";
150 return false;
151 }
153 LDEBUG << "CreateEventTemplate";
154
155 // validate current template by creating a new empty template which will be new current template
156 LDEBUG << "setTypeInCurrentTemplate" << m_eventType;
157 eventData->setTypeInCurrentTemplate(m_eventType);
158
159 eventData->addTemplate();
160 return true;
161}
162
163//----------------------------------------------------------------------
165 const LimaString& complement):
166Automaton::ConstraintFunction(language,complement)
167{
168}
169
171{
172 auto eventData = std::dynamic_pointer_cast<EventTemplateData>(analysis.getData("EventTemplateData"));
173 if (eventData==0) {
175 LERROR << "CreateEventTemplate: Missing data EventTemplateData";
176 return false;
177 }
179 LDEBUG << "ClearEventTemplate";
180 eventData->clearCurrentTemplate();
181 return true;
182}
183
184
185
186
187} // end namespace
188} // end namespace
189} // end namespace
#define CreateEventTemplateId
#define ClearEventTemplateId
#define AddTemplateElementId
#define LDEBUG
Definition LimaCommon.h:157
#define LERROR
Definition LimaCommon.h:161
LinguisticGraph::vertex_descriptor LinguisticGraphVertex
#define EVENTANALYSISLOGINIT
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.
EntityType getEntityType(const LimaString &entityName) const
entity types manager
␈rief A class for the description of automata
Definition automaton.h:87
bool operator()(const LinguisticAnalysisStructure::AnalysisGraph &graph, const LinguisticGraphVertex &v, AnalysisContent &analysis) const override
unary constraint function : the constraint only applies on one vertices in the graph (the graph is al...
AddTemplateElement(MediaId language, const LimaString &complement)
bool operator()(AnalysisContent &analysis) const override
zero-ary constraint function : applies the function without a vertex indication (used for actions,...
bool operator()(AnalysisContent &analysis) const override
zero-ary constraint function : applies the function without a vertex indication (used for actions,...
An AnalysisData containing a LinguisticGraph with a language and an id.
A representation of a specific entity to store in the annotation graph.
static const MediaticData & single()
const singleton accessor
Definition Singleton.h:51
AnnotationGraph::vertex_descriptor AnnotationGraphVertex
std::string limastring2utf8stdstring(const Lima::LimaString &phrase, uint32_t size0)
Convert a wide string to a string , in dest up to size bytes.
LimaString utf8stdstring2limastring(const std::string &src)
ConstraintFunctionFactory< AddTemplateElement > AddTemplateElementFactory(AddTemplateElementId)
ConstraintFunctionFactory< CreateEventTemplate > CreateEventTemplateFactory(CreateEventTemplateId)
ConstraintFunctionFactory< ClearEventTemplate > ClearEventTemplateFactory(ClearEventTemplateId)
NAUTITIA.
QString LimaString
Definition LimaString.h:33
STL namespace.
launch exception related to the configuration file parsing