LIMA
Libre Multilingual Analyzer — C++ API
Loading...
Searching...
No Matches
SpecificEntityAnnotation.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 * Copyright (C) 2005 by CEA LIST *
8 * *
9 ***************************************************************************/
10
13
14using namespace Lima::Common::AnnotationGraphs;
16
17namespace Lima
18{
19
20namespace LinguisticProcessing
21{
22
23namespace SpecificEntities
24{
25
27{
29
31 FsaStringsPool& sp);
32 SpecificEntityAnnotationPrivate( const std::deque<LinguisticGraphVertex>& vertices,
34 const LimaString& form,
35 const LimaString& normalizedForm,
36 int nbError,
37 uint64_t startPos,
38 uint64_t length,
39 FsaStringsPool& sp);
40 virtual ~SpecificEntityAnnotationPrivate() = default;
43
44 std::vector< LinguisticGraphVertex> m_vertices;
45
49 StringsPoolIndex m_string;
50 StringsPoolIndex m_normalizedString;
51 StringsPoolIndex m_normalizedForm;
52 uint64_t m_position;
53 uint64_t m_length;
54};
55
56
57SpecificEntityAnnotationPrivate::SpecificEntityAnnotationPrivate(
58 const std::deque<LinguisticGraphVertex>& vertices,
60 const LimaString& form,
61 const LimaString& normalizedForm,
62 int nbError,
63 uint64_t startPos,
64 uint64_t length,
65 FsaStringsPool& sp) :
66 // front, head or any hint for another vertex?
67 m_vertices(vertices.begin(),vertices.end()),
68 m_head(vertices.front()),
69 m_type(entityType),
70 m_string(sp[form]),
71 m_normalizedString(sp[normalizedForm]),
72 m_normalizedForm(sp[normalizedForm]),
73 m_position(startPos),
74 m_length(length)
75{
76 // no features??
77 m_features.addFeature("value", normalizedForm);
78 // no features??
79 m_features.addFeature("nbError", nbError);
80}
81
82SpecificEntityAnnotationPrivate::SpecificEntityAnnotationPrivate(
83 const RecognizerMatch& entity,
84 FsaStringsPool& sp) :
85 m_head(0),
86 m_type(entity.getType()),
87 m_features(entity.features()),
88 m_string(sp[entity.getString()]),
89 m_normalizedString(sp[entity.getNormalizedString(sp)]),
90 m_normalizedForm(0),
91 m_position(entity.positionBegin()),
92 m_length(entity.length())
93{
94 Automaton::EntityFeatures::const_iterator
96 if (f!=entity.features().end()) {
97 m_normalizedForm=sp[boost::any_cast<const LimaString&>((*f).getValue())];
98 }
99
100 if (entity.getHead() == 0)
101 {
102 m_head = entity[0].m_elem.first;
103 }
104 else
105 {
106 m_head = entity.getHead();
107 }
108
109 m_vertices.reserve(entity.size());
110
111 Automaton::RecognizerMatch::const_iterator it, it_end;
112 it = entity.begin(); it_end = entity.end();
113 for (; it != it_end; it++)
114 {
115 if ( (*it).m_elem.second )
116 {
117 m_vertices.push_back((*it).m_elem.first);
118 }
119 }
120}
121
123 const std::deque<LinguisticGraphVertex>& vertices,
125 const LimaString& form,
126 const LimaString& normalizedForm,
127 int nbError,
128 uint64_t startPos,
129 uint64_t length,
130 FsaStringsPool& sp) :
131 m_d(new SpecificEntityAnnotationPrivate(vertices,
132 entityType,
133 form,
134 normalizedForm,
135 nbError,
136 startPos,
137 length,
138 sp))
139{
140}
141
148
153
158
160{
161 if (m_d != nullptr)
162 delete m_d;
163 m_d = new SpecificEntityAnnotationPrivate(*annotation.m_d);
164 return *this;
165}
166
168{
169 return m_d->m_head;
170}
171
173{
174 m_d->m_head = head;
175}
176
181
183{
184 m_d->m_type = type;
185}
186
188{
189 return m_d->m_features;
190}
191
193{
194 m_d->m_features = features;
195}
196
198{
199 return m_d->m_string;
200}
201
203{
204 return m_d->m_normalizedString;
205}
206
208{
209 return m_d->m_normalizedForm;
210}
211
213{
214 return m_d->m_position;
215}
216
218{
219 return m_d->m_length;
220}
221
222const std::vector< LinguisticGraphVertex>& SpecificEntityAnnotation::vertices() const
223{
224 return m_d->m_vertices;
225}
226
227void SpecificEntityAnnotation::dump(std::ostream& os) const
228{
229 os << "head:" << m_d->m_head << " type:" << m_d->m_type << " vertices=";
230 if (m_d->m_vertices.size() != 0)
231 {
232 os << m_d->m_vertices[0];
233 for (const auto& v : m_d->m_vertices)
234 {
235 os << "," << v;
236 }
237 }
238}
239
240
242 GenericAnnotation& ga) const
243{
245 try
246 {
248 return SUCCESS_ID;
249 }
250 catch (const boost::bad_any_cast& )
251 {
252 LERROR << "This annotation is not a SpecificEntityAnnotation ; nothing dumped";
253 return UNKNOWN_ERROR;
254 }
255}
256
257
258} // SpecificEntities
259} // LinguisticProcessing
260} // Lima
#define DEFAULT_ATTRIBUTE
#define LERROR
Definition LimaCommon.h:161
#define PROCESSORSLOGINIT
Definition LimaCommon.h:211
LinguisticGraph::vertex_descriptor LinguisticGraphVertex
This class allows to convert any object into an annotation by inheritance.
a list of generic features: each feature is unique (only one feature for a name)
void addFeature(const std::string &name, const ValueType &value)
EntityFeatures::const_iterator find(const std::string &featureName) const
virtual int dump(std::ostream &os, Common::AnnotationGraphs::GenericAnnotation &ga) const override
A representation of a specific entity to store in the annotation graph.
SpecificEntityAnnotation & operator=(const SpecificEntityAnnotation &annotation)
void dump(std::ostream &os) const
The functions that dumps a SpecificEntityAnnotation on an output stream.
SpecificEntityAnnotation(const Automaton::RecognizerMatch &entity, FsaStringsPool &sp)
NAUTITIA.
@ UNKNOWN_ERROR
Definition LimaCommon.h:238
@ SUCCESS_ID
Definition LimaCommon.h:237
QString LimaString
Definition LimaString.h:33