LIMA
Libre Multilingual Analyzer — C++ API
Loading...
Searching...
No Matches
WordSenseAnnotation.h
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#ifndef LIMA_WORDSENSEDISAMBIGUATION_WORDSENSEANNOTATION_H
7#define LIMA_WORDSENSEDISAMBIGUATION_WORDSENSEANNOTATION_H
8
15
16#include <map>
17#include <set>
18#include <string>
19#include "WordUnit.h"
20#include "KnnSearcher.h"
21
22
23
24
25namespace Lima
26{
27namespace Common {
28namespace AnnotationGraphs {
29 class AnnotationData;
30}
31}
32namespace LinguisticProcessing
33{
34namespace SyntacticAnalysis {
35class SyntacticData;
36}
37namespace WordSenseDisambiguation
38{
39
41{
53public:
54
55 /*
56typedef std::set<WordSenseAnnotation*> Vertices;
57typedef std::map<WordSenseAnnotation*,std::set<WordSenseAnnotation*> > VerticesRelation;
58typedef std::map< WordSenseAnnotation*,std::map <WordSenseAnnotation*,float> > WeightedVerticesRelation;
59*/
61
63 const Mapping mapping,
64 const float confidence,
66 m_wsu(),
67 m_mode(mode),
68 m_mapping(mapping),
69 m_confidence(confidence),
70 m_morphVertex(v),
71 m_senseTag()
72 {}
73
75 const Mapping mapping,
77 m_wsu(),
78 m_mode(mode),
79 m_mapping(mapping),
80 m_confidence(-1),
81 m_morphVertex(v),
82 m_senseTag()
83 {}
84
86 m_wsu(wsa.m_wsu),
87 m_mode(wsa.m_mode),
88 m_mapping(wsa.m_mapping),
89 m_confidence(wsa.m_confidence),
90 m_morphVertex(wsa.m_morphVertex),
91 m_senseTag(wsa.m_senseTag)
92 {}
93
95 {
96 m_mode = wsa.m_mode;
97 m_mapping = wsa.m_mapping;
98 m_confidence = wsa.m_confidence;
99 m_morphVertex = wsa.m_morphVertex;
100 m_wsu = wsa.m_wsu;
101 m_senseTag = wsa.m_senseTag;
102 return *this;
103 };
104 friend LIMA_WORDSENSEANALYSIS_EXPORT std::ostream& operator << (std::ostream& os, const WordSenseAnnotation& wsa);
105
107
108 inline uint64_t senseId();
109 inline uint64_t senseId() const;
110 inline std::string senseTag();
111 inline std::string senseTag() const;
112 inline std::string mode();
113 inline std::string mapping();
114 inline const std::string mode() const;
115 inline const std::string mapping() const;
116 inline float confidence() const;
117 inline LinguisticGraphVertex morphVertex();
118 inline LinguisticGraphVertex morphVertex() const;
120 inline AnnotationGraphVertex av() const;
121 inline void senseId(uint64_t newSenseId);
122 inline void confidence(const float newConfidence);
123 inline void morphVertex(LinguisticGraphVertex v);
124 inline void av(AnnotationGraphVertex av);
125 inline void dump(std::ostream& os);
126
128 bool isDisambiguated() const;
129
130
132/*
133 int classify(
134 LinguisticGraph* graph,
135 SyntacticAnalysis::SyntacticData* sd,
136 const Common::PropertyCode::PropertyAccessor* macroAccessor,
137 const Common::PropertyCode::PropertyAccessor* microAccessor,
138 const std::map<std::string,LinguisticCode>& tagLocalDef,
139 const std::map<std::string, std::deque<std::string> >& relLocalDef,
140 const LinguisticAnalysisStructure::AnalysisGraph* anagraph,
141 MediaId language) ;
142*/
143
144 bool disambiguate(const WordUnit& wu);
145 bool disambiguate(KnnSearcher* searcher,
146 const WordUnit& wu,
147 const SemanticContext& context,
148 double thres,
149 char method);
150
151 AnnotationGraphVertex writeAnnotation(
153
154 virtual void outputXml(std::ostream& xmlStream,
155 const LinguisticGraph& g) const;
156
157
158
159private:
160
161protected:
162 /* internal computation functions called by classifKnnMRD*/
163
164 std::set<WordSenseUnit>::iterator classify(const WordUnit& wu,
165 const SemanticContext& context,
166 const std::map<int, std::map<std::string, double> >& cvListRep,
167 const double thres,
168 const char method) ;
169
170 int computeConfidenceVector(const WordUnit& wu,
171 const NNList& knns,
172 const SemanticContext::const_iterator itContext,
173 std::map<int, std::map<std::string, double> >& cvListRep);
174
175
185 double cvCluster(const std::map<int, std::map<std::string, double> >& cvListRep,
186 const std::string& relation,
187 int id_cluster);
188
197 double sumCvCluster(std::map<int, std::map<std::string, double> >& cvListRep,
198 std::string relation);
199 //(F)
200 double sumLogCv(const std::map<int, std::map<std::string, double> >& cvListRep,
201 const std::string& relation);
202 //(G)
203 double sumLogCvList(const std::map<int, std::map<std::string, double> >& cvListRep);
204 /* end internal computation functions */
205
206
207 void retrieveSense(std::set<WordSenseUnit>::iterator itSenses);
208 float classifKnnMRD(KnnSearcher* searcher,
209 const WordUnit& wu,
210 const SemanticContext& context,
211 double thres,
212 char method);
213
219 std::string m_senseTag;
220
221// AnnotationGraphVertex m_av;
222
223};
224
225
227{
228 return m_wsu.senseId();
229}
230inline uint64_t WordSenseAnnotation::senseId() const
231{
232 return m_wsu.senseId();
233}
235{
236 /*if (m_wsu.senseTag() !="")
237 return m_wsu.senseTag();*/
238 return m_senseTag;
239}
240inline std::string WordSenseAnnotation::senseTag() const
241{
242 return m_wsu.senseTag();
243}
244inline std::string WordSenseAnnotation::mode()
245{
246 switch (m_mode) {
247 case B_MOST_FREQUENT :
248 return "b_Most_Frequent";
250 return "b_Romanseval_Most_Frequent";
252 return "b_Jaws_Most_Frequent";
253 case S_WSI_MRD :
254 return "s_Wsi_mrd";
255 case S_WSI_DS :
256 return "s_Wsi_Dempster_Schaffer";
257 case S_UNKNOWN :
258 return "Unknown";
259 default :
260 break;
261 }
262 return "";
263}
264inline const std::string WordSenseAnnotation::mode() const
265{
266 switch (m_mode) {
267 case B_MOST_FREQUENT :
268 return "b_Most_Frequent";
270 return "b_Romanseval_Most_Frequent";
272 return "b_Jaws_Most_Frequent";
273 case S_WSI_MRD :
274 return "s_Wsi_mrd";
275 case S_WSI_DS :
276 return "s_Wsi_Dempster_Schaffer";
277 case S_UNKNOWN :
278 return "Unknown";
279 default :
280 break;
281 }
282 return "";
283}
285{
286 switch (m_mapping) {
288 return "m_Romanseval_Senses";
289 case M_JAWS_SENSES :
290 return "m_Jaws_Senses";
291 case M_UNKNOWN :
292 return "Unknown";
293 default :
294 break;
295 }
296 return "";
297}
298inline const std::string WordSenseAnnotation::mapping() const
299{
300 switch (m_mapping) {
302 return "m_Romanseval_Senses";
303 case M_JAWS_SENSES :
304 return "m_Jaws_Senses";
305 case M_UNKNOWN :
306 return "Unknown";
307 default :
308 break;
309 }
310 return "";
311}
313{
314 return m_confidence;
315}
316
325/*
326inline void WordSenseAnnotation::senseId(uint64_t newSenseId)
327{
328 m_senseId = newSenseId;
329}*/
330inline void WordSenseAnnotation::confidence(const float newConfidence)
331{
332 m_confidence = newConfidence;
333}
338inline void WordSenseAnnotation::dump(std::ostream& os)
339{
340 os << "#" << m_wsu.senseId() << ";" << m_mode<< ";" << /*"V:" << m_morphVertex <<*/ "\n";
341}
342
343
344
345
356{
357 public:
358 virtual int dump(std::ostream& os, Common::AnnotationGraphs::GenericAnnotation& ga) const override;
359};
360
361
362
363
364} // closing namespace WordSenseDisambiguation
365} // closing namespace LinguisticProcessing
366} // closing namespace Lima
367
368#endif // LIMA_WORDSENSEDISAMBIGUATION_WORDSENSEANNOTATION_H
This file is the main header file for the data related to annotation graphs.
A graph that stores the relations of syntactic dependency between the elements of a DependencyGraph.
QDebug & operator<<(QDebug &qd, const std::string &str)
Definition QsLog.cpp:39
A graph structure for linguistic analysis.
LinguisticGraph::vertex_descriptor LinguisticGraphVertex
boost::adjacency_list< boost::vecS, boost::vecS, boost::bidirectionalS, LinguisticVertexProperties > LinguisticGraph
Property to identify the chains in the graph.
#define LIMA_WORDSENSEANALYSIS_EXPORT
Holds an annotation graph and gives an API to manipulate it.
This class allows to convert any object into an annotation by inheritance.
Definition of a function suitable to be used as a dumper for WordSense Annotations of an Annotation g...
virtual int dump(std::ostream &os, Common::AnnotationGraphs::GenericAnnotation &ga) const override
WordSenseAnnotation(const Mode mode, const Mapping mapping, const float confidence, LinguisticGraphVertex v)
WordSenseAnnotation & operator=(const WordSenseAnnotation &wsa)
WordSenseAnnotation(const Mode mode, const Mapping mapping, LinguisticGraphVertex v)
AnnotationGraph::vertex_descriptor AnnotationGraphVertex
std::map< std::string, std::set< uint64_t > > SemanticContext
NAUTITIA.