LIMA
Libre Multilingual Analyzer — C++ API
Loading...
Searching...
No Matches
coreferentAnnotation.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
17#ifndef LIMA_COREFSOLVING_COREFERENTANNOTATION_H
18#define LIMA_COREFSOLVING_COREFERENTANNOTATION_H
19
20#include "CorefSolvingExport.h"
26
27#include <string>
28
29
30
31namespace Lima
32{
33namespace Common {
34namespace AnnotationGraphs {
35 class AnnotationData;
36}
37}
38namespace LinguisticProcessing
39{
40namespace SyntacticAnalysis {
41class SyntacticData;
42}
43namespace Coreferences
44{
45
47{
48
49
50public:
51
52typedef std::set<CoreferentAnnotation*> Vertices;
53typedef std::map<CoreferentAnnotation*,std::set<CoreferentAnnotation*> > VerticesRelation;
54typedef std::map< CoreferentAnnotation*,std::map <CoreferentAnnotation*,float> > WeightedVerticesRelation;
55
57
58 CoreferentAnnotation(uint64_t id, const std::string& categ, const float salience, LinguisticGraphVertex v) :
59 m_id(id), m_categ(categ), m_salience(salience), /*m_av(v),*/ m_bindingSalience(0), m_morphVertex(v), m_newerRef(this) {}
60
62 m_id(ca.m_id), m_categ(ca.m_categ), m_salience(ca.m_salience), /*m_av(ca.m_av), */ m_bindingSalience(ca.m_bindingSalience), m_morphVertex(ca.m_morphVertex), m_newerRef(ca.m_newerRef) {}
63
66 m_id(id), m_categ("not initialized"), m_salience(-1), m_bindingSalience(0), m_morphVertex(v), m_newerRef(this) {}
67
68
70 {
71 m_id = ca.m_id;
72 m_categ = ca.m_categ;
73 m_salience = ca.m_salience;
74// m_av = ca.m_av;
75 m_bindingSalience = ca.m_bindingSalience;
76 m_morphVertex = ca.m_morphVertex;
77 m_newerRef = ca.m_newerRef;
78 return *this;
79 };
80
81
83
84 inline uint64_t id();
85 inline uint64_t id() const;
86 inline std::string& categ();
87 inline const std::string& categ() const;
88 inline float salience() const;
89 inline float bindingSalience() const;
90 inline LinguisticGraphVertex morphVertex();
91 inline LinguisticGraphVertex morphVertex() const;
93 inline AnnotationGraphVertex av() const;
94 inline CoreferentAnnotation* newerRef();
95 inline CoreferentAnnotation* newerRef() const;
96 inline void id(uint64_t newId);
97 inline void categ(const std::string newType);
98 inline void salience(const float newSalience);
99 inline void bindingSalience(const float newBindingSalience);
100 inline void morphVertex(LinguisticGraphVertex v);
101 inline void av(AnnotationGraphVertex av);
102 inline void newerRef(CoreferentAnnotation* newerRef);
103 void dump( std::ostream& os, const Lima::Common::AnnotationGraphs::AnnotationData* ad ) const;
104 inline bool hasNewerRef(/*std::deque<Vertices>* npCandidates*/);
105
108 bool isIncludedInNounPhrase(
109 const LinguisticGraph* g,
110 MediaId language,
112 AnalysisContent& ac,
113 const std::set< LinguisticCode >& inNpCategs,
114 const Common::PropertyCode::PropertyAccessor* microAccessor) const;
115
116 LinguisticGraphVertex npHeadVertex(
118 MediaId language,
119 std::set<DependencyGraphVertex>* alreadyProcessed ) const;
120
121 bool isTaggedAsOneOfThese(
122 const LinguisticGraph* g,
123 const std::set< LinguisticCode >& categs,
124 const Common::PropertyCode::PropertyAccessor* microAccessor) const;
125
126
129 bool isDefinite(const SyntacticAnalysis::SyntacticData* sd,
130 const std::string& definiteRel,
131 const std::set< LinguisticCode >& definiteCategs,
132 const Common::PropertyCode::PropertyAccessor* microAccessor,
133 MediaId language) const ;
134 bool isPleonastic(const SyntacticAnalysis::SyntacticData* sd,
135 const std::string& m_pleonRel,
136 MediaId language) const;
137
138 bool isPronoun(const LinguisticGraph* g,
139 const Common::PropertyCode::PropertyAccessor* macroAccessor,
140 const LinguisticCode& L_PRON) const ;
141/*
142 bool isVerb(const LinguisticGraph* g,
143 const Common::PropertyCode::PropertyAccessor* macroAccessor,
144 const LinguisticCode& L_V) const ;*/
145
146 bool isConjCoord(
147 const Common::PropertyCode::PropertyAccessor* microAccessor,
149 const LinguisticCode& conjCoord) const;
150
151 std::string referentType(
153 const LinguisticGraph* g,
154 const Common::PropertyCode::PropertyAccessor* macroAccessor,
155 const Common::PropertyCode::PropertyAccessor* microAccessor,
156 const std::map<std::string,LinguisticCode>& tagLocalDef,
157 const std::map<std::string, std::deque<std::string> >& relLocalDef,
158 const std::set< LinguisticCode >& definiteCategs,
159 const std::set< LinguisticCode >& reflexiveReciprocalCategs,
160 const std::set< LinguisticCode >& undefPronounsCategs,
161 const std::set< LinguisticCode >& possPronounsCategs,
162 const Common::PropertyCode::PropertyAccessor* personAccessor,
164 MediaId language) const;
165
166bool isN3PPronoun(
167 const Common::PropertyCode::PropertyAccessor* personAccessor,
168 const LinguisticAnalysisStructure::AnalysisGraph* anagraph) const;
169
172 bool sentenceIsRecent() const;
173 bool beginWithColon(
175 LinguisticGraphVertex& beginSentence) const;
176 bool endWithColon(
178 LinguisticGraphVertex& endSentence) const;
179 bool isInAppos(
182 AnalysisContent& ac,
183 MediaId language,
184 std::set<DependencyGraphVertex>* alreadyProcessed) const;
185 bool isInQuantA(
187 const LinguisticAnalysisStructure::AnalysisGraph* anagraph) const;
188 bool isInSubordinate(
190 const Common::PropertyCode::PropertyAccessor* macroAccessor,
191 const std::map<std::string,LinguisticCode>& tagLocalDef,
192 MediaId language,
194 AnalysisContent& ac,
195 std::set<LinguisticGraphVertex>* alreadyProcessed) const;
196 bool isFunctionMasterOf(
198 const std::deque<std::string>& macroDependencyRelation,
199 MediaId language) const;
200
201
205 bool isVerb(
206 const Common::PropertyCode::PropertyAccessor* macroAccessor,
207 const std::map<std::string,LinguisticCode>& tagLocalDef,
208 const LinguisticAnalysisStructure::AnalysisGraph* anagraph) const;
209
210 bool isGovernedByMasculineCoordinate(
212 const Common::PropertyCode::PropertyAccessor* genderAccessor,
213 MediaId language,
215 AnalysisContent& ac) const ;
216
217 // P and N have incompatible agreement features. (gender, number)
218 bool isAgreementCompatibleWith(
219 const CoreferentAnnotation& ca,
221 const Common::PropertyCode::PropertyAccessor* genderAccessor,
222 const Common::PropertyCode::PropertyAccessor* personAccessor,
223 const Common::PropertyCode::PropertyAccessor* numberAccessor,
224 MediaId language,
226 AnalysisContent& ac) const ;
227
228 // P is in the Argument Domain of N <=> P and N are both argument of the same head
229 bool isInTheArgumentDomainOf(
230 const CoreferentAnnotation& ca,
232 MediaId language,
234 AnalysisContent& ac,
235 const Common::PropertyCode::PropertyAccessor* macroAccessor,
236 const Common::PropertyCode::PropertyAccessor* microAccessor,
237 const std::map<std::string,LinguisticCode>& tagLocalDef,
238 const LinguisticCode& conjCoord,
239 std::set<LinguisticGraphVertex>* alreadyProcessed) const ;
240
241 // P is in the Argument Domain of N <=> P and N are both argument of the same head
242 bool isInTheArgumentDomainOf2(
243 const CoreferentAnnotation& ca,
245 MediaId language,
247 AnalysisContent& ac,
248 const Common::PropertyCode::PropertyAccessor* macroAccessor,
249 const Common::PropertyCode::PropertyAccessor* microAccessor,
250 const std::map<std::string,LinguisticCode>& tagLocalDef,
251 const LinguisticCode& conjCoord,
252 std::set<LinguisticGraphVertex>* alreadyProcessed) const ;
253
254 // P is in the Adjunct Domain of N <=> N is an argument of a head H, P is the object of a preposition PREP, PREP is an adjunct of H
255 bool isInTheAdjunctDomainOf(
256 const CoreferentAnnotation& ca,
258 const LinguisticGraph* graph,
259 //const Common::PropertyCode::PropertyManager& microManager,
260 const Common::PropertyCode::PropertyAccessor* microAccessor,
261 const std::map<std::string,LinguisticCode>& tagLocalDef,
262 const std::map<std::string, std::deque<std::string> >& relLocalDef,
263 MediaId language) const;
264
265// P is the object of a preposition PREP,
266// and PREP is an adjunct of Q
267bool isInThePrepAdjunctNP(
268 const DependencyGraphVertex& qv,
270 const LinguisticGraph* graph,
271 const Common::PropertyCode::PropertyAccessor* microAccessor,
272 const std::map<std::string,LinguisticCode>& tagLocalDef,
273 const std::map<std::string, std::deque<std::string> >& relLocalDef,
274 MediaId language) const;
275
276 // P is an argument of a head H, N is not a pronoun,
277 // and N is contained in H.
278 bool sf4(
279 const CoreferentAnnotation& ca,
281 //const LinguisticGraph* g,
282 const Common::PropertyCode::PropertyAccessor* macroAccessor,
283 const LinguisticCode& L_PRON,
284 MediaId language,
286 AnalysisContent& ac) const;
287
288 // P is in the NP domain of N <=> N is a determiner of a noun Q, and:
289 // (i) P is an argument of Q.
290 // or (ii) P is an object of a preposition PREP and PREP is an adjunct of Q.
291 bool isInTheNpDomainOf(
292 const CoreferentAnnotation& ca,
294 const Common::PropertyCode::PropertyAccessor* microAccessor,
295 const std::map<std::string,LinguisticCode>& tagLocalDef,
296 const std::map<std::string,std::deque<std::string> >& relLocalDef,
297 MediaId language,
299 AnalysisContent& ac) const;
300
301 // P is contained in a phrase Q <=>
302 // (i) P is either an argument or an adjunct of Q (ie. P is immediately contained in Q.
303 // or (ii) P is immediately contained in some phrase R, and R is contained in Q.
304 bool isContainedIn(
305 const DependencyGraphVertex& dv,
306 MediaId language,
308 AnalysisContent& ac) const;
309
310 bool isDeterminer(
313 const std::map<std::string,std::deque<std::string> >& relLocalDef,
314 MediaId language,
316 AnalysisContent& ac) const;
317
318 // P is a determiner of a noun Q,
319 // and N is contained in Q.
320 bool sf6(
321 const CoreferentAnnotation& ca,
323 const std::map<std::string,std::deque<std::string> >& relLocalDef,
324 MediaId language,
326 AnalysisContent& ac) const;
327
328 // N is an argument of a verb V,
329 // there is an NP Q in the argument domain of N such that Q has no noun determiner,
330 // and
331 // (i) A is an argument of Q.
332 // or (ii) A is an argument of a preposition PREP and PREP is an adjunct of Q.
333 bool aba4(
334 const CoreferentAnnotation& ca,
335 //Common::AnnotationGraphs::AnnotationData* ad,
337 const std::map<std::string,LinguisticCode >& tagLocalDef,
338 const std::map<std::string,std::deque<std::string> >& relLocalDef,
339 const Common::PropertyCode::PropertyAccessor* macroAccessor,
340 const Common::PropertyCode::PropertyAccessor* microAccessor,
341 MediaId language,
342 const std::set< LinguisticCode >& inNpCategs,
344 AnalysisContent& ac,
345 const LinguisticCode& conjCoord,
346 std::deque<Vertices>* npCandidates) const;
347
348// [higher slot] subj > agent > obj > (iobj|pobj) [lower slot]
349int getSlotValue(
351 const std::map<std::string,std::deque<std::string> >& relLocalDef,
352 const std::map<std::string, int>& slotValues,
353 MediaId language) const;
354
355 // A is a determiner of a noun Q,
356 // and
357 // (i) Q is in the argument domain of N,
358 // and N fills a higher argument slot than Q.
359 // or (ii) Q is in the adjunct domain of N.
360 bool aba5(
361 const CoreferentAnnotation& ca,
363 const std::map<std::string,LinguisticCode>& tagLocalDef,
364 const std::map<std::string,std::deque<std::string> >& relLocalDef,
365 const Common::PropertyCode::PropertyAccessor* macroAccessor,
366 const Common::PropertyCode::PropertyAccessor* microAccessor,
367 MediaId language,
369 AnalysisContent& ac,
370 const std::map<std::string, int>& slotValues,
371 const LinguisticCode& conjCoord) const;
372
373
376 int classify(
377 LinguisticGraph* graph,
379 const Common::PropertyCode::PropertyAccessor* macroAccessor,
380 const Common::PropertyCode::PropertyAccessor* microAccessor,
381 const std::map<std::string,LinguisticCode>& tagLocalDef,
382 const std::map<std::string, std::deque<std::string> >& relLocalDef,
383 const std::set< LinguisticCode >& definiteCategs,
384 const std::set< LinguisticCode >& reflexiveReciprocalCategs,
385 const std::set< LinguisticCode >& undefPronouns,
386 const std::set< LinguisticCode >& possPronouns,
387 const bool& resolveDefinites,
388 const bool& resolveN3PPronouns,
389 const Common::PropertyCode::PropertyAccessor* personAccessor,
391 MediaId language) ;
392
393
394 float salienceWeighting(
395 const std::map<std::string,float>& weights,
397 const Common::PropertyCode::PropertyAccessor* macroAccessor,
399 MediaId language,
400 const std::map< std::string,LinguisticCode>& tagLocalDef,
401 const std::map< std::string,std::deque<std::string> >& relLocalDef,
402 AnalysisContent& ac,
403 LinguisticGraphVertex& beginSentence,
404 LinguisticGraphVertex& endSentence) const;
405
406 AnnotationGraphVertex writeAnnotation(
408 CoreferentAnnotation& antecedent) const;
409
410 virtual void outputXml(std::ostream& xmlStream,
411 const LinguisticGraph& g,
413
414
415private:
416
417protected:
418 uint64_t m_id;
419 std::string m_categ;
423// AnnotationGraphVertex m_av;
424
426};
427
429{
430 return m_id;
431}
432inline uint64_t CoreferentAnnotation::id() const
433{
434 return m_id;
435}
436inline std::string& CoreferentAnnotation::categ()
437{
438 return m_categ;
439}
440inline const std::string& CoreferentAnnotation::categ() const
441{
442 return m_categ;
443}
445{
446 return m_salience;
447}
449{
450 return m_bindingSalience;
451}
460// inline AnnotationGraphVertex CoreferentAnnotation::av()
461// {
462// return m_av;
463// }
464// inline AnnotationGraphVertex CoreferentAnnotation::av() const
465// {
466// return m_av;
467// }
476inline void CoreferentAnnotation::id(uint64_t newId)
477{
478 m_id = newId;
479}
480inline void CoreferentAnnotation::categ(const std::string newType)
481{
482 m_categ = newType;
483}
484inline void CoreferentAnnotation::salience(const float newSalience)
485{
486 m_salience = newSalience;
487}
488inline void CoreferentAnnotation::bindingSalience(const float newBindingSalience)
489{
490 m_bindingSalience = newBindingSalience;
491}
496// inline void CoreferentAnnotation::av(AnnotationGraphVertex av)
497// {
498// m_av = av;
499// }
505{
506return (newerRef()!=this);
507}
508
509
510
511
522{
523public:
525 virtual int dump(std::ostream& os, Common::AnnotationGraphs::GenericAnnotation& ga) const override;
526
527private:
529
530};
531
532
533} // closing namespace Coreferences
534} // closing namespace LinguisticProcessing
535} // closing namespace Lima
536
537#endif // LIMA_COREFSOLVING_COREFSOLVER_H
This file is the main header file for the data related to annotation graphs.
#define LIMA_COREFSOLVING_EXPORT
A graph that stores the relations of syntactic dependency between the elements of a DependencyGraph.
DependencyGraph::vertex_descriptor DependencyGraphVertex
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.
Holds all data that pass through the ProcessUnits Analysis data are shared pointers,...
Holds an annotation graph and gives an API to manipulate it.
This class allows to convert any object into an annotation by inheritance.
Provide function to read write and check a property.
std::map< CoreferentAnnotation *, std::set< CoreferentAnnotation * > > VerticesRelation
CoreferentAnnotation(uint64_t id, const std::string &categ, const float salience, LinguisticGraphVertex v)
bool sentenceIsRecent() const
test functions for the salience weighting
CoreferentAnnotation & operator=(const CoreferentAnnotation &ca)
std::map< CoreferentAnnotation *, std::map< CoreferentAnnotation *, float > > WeightedVerticesRelation
Definition of a function suitable to be used as a dumper for Coreferent Annotations of an Annotation ...
virtual int dump(std::ostream &os, Common::AnnotationGraphs::GenericAnnotation &ga) const override
An AnalysisData containing a LinguisticGraph with a language and an id.
This class points to a graph, its dependency graph and the structure that holds the maping between th...
AnnotationGraph::vertex_descriptor AnnotationGraphVertex
NAUTITIA.