LIMA
Libre Multilingual Analyzer — C++ API
Loading...
Searching...
No Matches
ChainsDisambiguator.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
15#ifndef LIMA_LINGUISTICPROCESSING_SYNTACTICANALYSIS_CHAINSDISAMBIGUATOR_H
16#define LIMA_LINGUISTICPROCESSING_SYNTACTICANALYSIS_CHAINSDISAMBIGUATOR_H
17
24
25#include <vector>
26#include <list>
27#include <deque>
28#include <set>
29#include <stdexcept>
30
31#ifdef WIN32
32#undef min
33#undef max
34#endif
35
36namespace Lima {
37namespace LinguisticProcessing {
38namespace SyntacticAnalysis {
39
40#define SADLOGINIT LOGINIT("LP::SyntacticAnalysis::Disamb")
41
47{
48public:
49 Elem(uint64_t id, unsigned char type=0) : m_id(id), m_type(type) {}
50 Elem(const Elem& elem) : m_id(elem.m_id), m_type(elem.m_type), m_elems(elem.m_elems) {}
51 virtual ~Elem() {}
52 Elem& operator=(const Elem& elem);
53
57 inline uint64_t id() const {return m_id;}
58
62 inline unsigned char type() const {return m_type;}
63
67 inline const std::vector< uint64_t >& elems() const {return m_elems;}
68
72 inline std::vector< uint64_t >& elems() {return m_elems;}
73
74private:
76 uint64_t m_id;
78 unsigned char m_type;
80 std::vector< uint64_t > m_elems;
81};
82
88{
89public:
90 Key(uint64_t id, const std::set< uint64_t>& chainsToIgnore = std::set< uint64_t>()) :
91 m_id(id), m_chainsToIgnore(chainsToIgnore) {}
92
93 Key(const Key& key) : m_id(key.m_id), m_chainsToIgnore(key.m_chainsToIgnore) {}
94
95 virtual ~Key() {}
96
97 Key& operator=(const Key& key);
98
104 inline uint64_t id() const {return m_id;}
105 inline const std::set< uint64_t >& chainsToIgnore() const {return m_chainsToIgnore;}
106 inline std::set< uint64_t >& chainsToIgnore() {return m_chainsToIgnore;}
108
109
110private:
112 uint64_t m_id;
114 std::set< uint64_t > m_chainsToIgnore;
115};
116
119{
120public:
121 Path(
122 uint64_t id,
123 const std::set< uint64_t>& chainsToIgnore,
124 unsigned char type=0,
125 uint64_t chainId=std::numeric_limits<uint64_t>::max());
126
127 Path(const Path& path);
128
129 virtual ~Path() {}
130
131 Path& operator=(const Path& path);
132
133 bool operator<(const Path& path) const;
134
140 inline const Key& key() const {return m_key;}
141 inline const std::list< Elem >& elems() const {return m_elems;}
142 inline uint64_t idealConjVerbNb() const {return m_idealConjVerbNb;}
143 inline uint64_t conjVerbNb() const {return m_conjVerbNb;}
144 inline uint64_t outChainsWordsNb() const {return m_outChainsWordsNb;}
145 inline uint64_t chainsNb() const {return m_chainsNb;}
146 inline Key& key() {return m_key;}
147 inline std::list< Elem >& elems() {return m_elems;}
148 inline uint64_t& idealConjVerbNb() {return m_idealConjVerbNb;}
149 inline uint64_t& conjVerbNb() {return m_conjVerbNb;}
150 inline uint64_t& outChainsWordsNb() {return m_outChainsWordsNb;}
151 inline uint64_t& chainsNb() {return m_chainsNb;}
152 inline void key(const Key& key) {m_key = key;}
153 inline void elems(const std::list< Elem >& elems) {m_elems = elems;}
154 inline void idealConjVerbNb(uint64_t idealConjVerbNb) {m_idealConjVerbNb = idealConjVerbNb;}
155 inline void conjVerbNb(uint64_t conjVerbNb) {m_conjVerbNb = conjVerbNb;}
156 inline void outChainsWordsNb(uint64_t outChainsWordsNb) {m_outChainsWordsNb = outChainsWordsNb;}
157 inline void chainsNb(uint64_t chainsNb) {m_chainsNb = chainsNb;}
158 inline void depsNb(uint64_t depsNb) { m_depsNb = depsNb; }
159 inline uint64_t depsNb() const { return m_depsNb; }
161
167 void updateParams(
168 const LinguisticCode& microCateg,
169 bool incrChainsNb,
170 bool incrOutChainsWordsNb,
171 MediaId language);
172
173private:
175 Key m_key;
177 std::list< Elem > m_elems;
178
181
182 uint64_t m_idealConjVerbNb;
184 uint64_t m_conjVerbNb;
186 uint64_t m_outChainsWordsNb;
188 uint64_t m_chainsNb;
190 uint64_t m_depsNb;
192};
193
202{
203public:
221 const LinguisticGraphVertex& s,
222 const LinguisticGraphVertex& t,
223 MediaId language,
224 uint64_t depGraphMaxBranchingFactor);
225
228
231
233 ChainsDisambiguator& operator=(const ChainsDisambiguator& cd);
234
236 void initPaths();
237
239 void computePaths();
240
245 void applyDisambiguisation();
246
247private:
248
249
257 void cancelCurrentChain(Elem elem, Path& hyp);
258
259
268 void startWithSeveralChainsOnNewVertex(
269 LinguisticGraphVertex nextVertex,
270 const std::set< LinguisticAnalysisStructure::ChainIdStruct >& nextVertexChains,
271 const Path& currentHyp);
272
278 uint64_t computeDepsNb(const Path& path);
279
281 std::deque< Path > m_hypsStack;
282
289 std::multiset< Path > m_completePaths;
290
292 SyntacticData* m_data;
293
295 LinguisticGraphVertex m_srcVertex;
296
298 LinguisticGraphVertex m_tgtVertex;
299
301 MediaId m_language;
302
307 uint64_t m_depGraphMaxBranchingFactor;
308
309 const Common::PropertyCode::PropertyAccessor* m_microAccessor;
310};
311
314LIMA_SYNTACTICANALYSIS_EXPORT std::ostream& operator<<(std::ostream &os, const Key& k);
315LIMA_SYNTACTICANALYSIS_EXPORT std::ostream& operator<<(std::ostream &os, const Elem& e);
316LIMA_SYNTACTICANALYSIS_EXPORT std::ostream& operator<<(std::ostream &os, const Path& p);
318
319} // closing namespace SyntacticAnalysis
320} // closing namespace LinguisticProcessing
321} // closing namespace Lima
322
323#endif // LIMA_LINGUISTICPROCESSING_SYNTACTICANALYSIS_CHAINSDISAMBIGUATOR_H
A graph structure for linguistic analysis.
LinguisticGraph::vertex_descriptor LinguisticGraphVertex
#define LIMA_SYNTACTICANALYSIS_EXPORT
Data used for the syntactic analyzis of texts.
Provide function to read write and check a property.
Builds possible chains paths between two vertices.
An element of a Path (out of chain vertex or candidate chain)
unsigned char type() const
Accessor to the type of this elem: vertex or chain.
std::vector< uint64_t > & elems()
Non const accessor to the subelements collection.
const std::vector< uint64_t > & elems() const
Const accessor to the subelements collection.
uint64_t id() const
Accessor to the vertex or chain id.
Stores a path end vertex id and the chains ids that have been found to ignore.
Key(uint64_t id, const std::set< uint64_t > &chainsToIgnore=std::set< uint64_t >())
const std::set< uint64_t > & chainsToIgnore() const
This class points to a graph, its dependency graph and the structure that holds the maping between th...
std::ostream & operator<<(std::ostream &os, const Key &k)
Operators to dump to stream the classes defined here.
NAUTITIA.
static bool operator<(const QStringView &entityStr, const TextHtmlEntity &entity)