LIMA
Libre Multilingual Analyzer — C++ API
Loading...
Searching...
No Matches
SyntacticData.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
16// clazy:exclude=rule-of-two-soft
17
18
19#ifndef LIMA_SYNTACTICANALYSIS_SYNTACTICDATA_H
20#define LIMA_SYNTACTICANALYSIS_SYNTACTICDATA_H
21
23#include "DependencyGraph.h"
26#include "linguisticProcessing/common/linguisticData/languageData.h" // for SyntacticRelationId
28
29#include <tuple>
30
31namespace Lima {
32namespace LinguisticProcessing {
33
34namespace LinguisticAnalysisStructure
35{
36 class Token;
37 class MorphoSyntacticData;
38}
39
40namespace SyntacticAnalysis {
41
42class SyntagmDefStruct;
43
51{
52public:
53typedef std::tuple< LinguisticGraphVertex, LinguisticGraphVertex, Common::MediaticData::SyntacticRelationId > Relation;
54
61 SyntacticData(LinguisticAnalysisStructure::AnalysisGraph* pit, std::shared_ptr<SyntagmDefStruct> matrices);
62
63 virtual ~SyntacticData();
64
65 inline LinguisticGraph* graph() {return m_graph;}
66 inline const LinguisticGraph* graph() const {return m_graph;}
67
68 inline DependencyGraph* dependencyGraph() {return m_depGraph;}
69 inline const DependencyGraph* dependencyGraph() const {return m_depGraph;}
70
72 inline const LinguisticAnalysisStructure::AnalysisGraph* iterator() const {return m_anagraph;}
73
74 inline std::shared_ptr<SyntagmDefStruct> matrices() const {return m_matrices;}
75 inline void matrices(std::shared_ptr<SyntagmDefStruct> matrices) {m_matrices=matrices;}
76
77 inline std::vector<LinguisticAnalysisStructure::Token*>& ownedTokens() {return m_ownedTokens;}
78 inline std::vector<LinguisticAnalysisStructure::MorphoSyntacticData*>& ownedMorphosyntacticData() {return m_ownedMorphData;}
79
80 DependencyGraphVertex depVertexForTokenVertex(const LinguisticGraphVertex& v) const;
81 LinguisticGraphVertex tokenVertexForDepVertex(const DependencyGraphVertex& v) const;
82
87 uint64_t depsBetween(
88 const LinguisticGraphVertex& srcVertex,
89 const LinguisticGraphVertex& tgtVertex);
98 void setupDependencyGraph();
99
109 std::vector<LinguisticGraphVertex>
110 findRelated(const LinguisticGraphVertex,
112
122 std::vector<LinguisticGraphVertex>
123 findRelated(const LinguisticGraphVertex,
124 const std::set<Common::MediaticData::SyntacticRelationId>& relations);
125
126
127 inline void clearStoredRelations() {m_relations.clear();}
128
130 {
131 if (m_relations.empty()) {
132 return std::make_tuple(m_anagraph->firstVertex(), m_anagraph->lastVertex(), 0);
133 }
134 else
135 {
136 Relation r = m_relations.front(); // clazy:exclude=rule-of-two-soft
137 m_relations.pop_front();
138 return r;
139 }
140 }
141
142 inline bool relation(const LinguisticGraphVertex& v1,
143 const LinguisticGraphVertex& v2,
145 {
146// SALOGINIT;
147 Relation r = std::make_tuple(v1,v2,relationType);
148 if (m_relations.empty() || !(m_relations.front() == r))
149 {
150 m_relations.push_back(r);
151 return true;
152 }
153 else
154 {
155 return false;
156 }
157 };
158
159 std::pair<LinguisticGraphVertex, DependencyGraphVertex> addVertex();
160
161 void addRelationNoChain(const Common::MediaticData::SyntacticRelationId& relType,
162 const LinguisticGraphVertex& src,
163 const LinguisticGraphVertex& dest);
164
165 void modifyRelationNoChain(const Common::MediaticData::SyntacticRelationId& relType,
166 const LinguisticGraphVertex& src,
167 const LinguisticGraphVertex& dest,
169
171 const LinguisticGraphVertex& v2,
173 {
174 m_relationStoredForSelectionalConstraint = std::make_tuple(v1,v2,relationType);
175 return true;
176 };
177
179 {
180 return m_relationStoredForSelectionalConstraint; // clazy:exclude=rule-of-two-soft
181 };
182
183 bool removeDependency(const LinguisticGraphVertex& v1,
184 const LinguisticGraphVertex& v2,
185 const Common::MediaticData::SyntacticRelationId relationType=0);
186
187 private:
190
192 LinguisticGraph* m_graph;
193
195 DependencyGraph* m_depGraph;
196
197 std::shared_ptr<SyntagmDefStruct> m_matrices;
198
200 std::pair<
201 std::map< LinguisticGraphVertex, DependencyGraphVertex >,
202 std::map< DependencyGraphVertex, LinguisticGraphVertex > > m_mapping;
203
204 std::list< Relation > m_relations;
205
206 std::vector<LinguisticAnalysisStructure::Token*> m_ownedTokens;
207 std::vector<LinguisticAnalysisStructure::MorphoSyntacticData*> m_ownedMorphData;
208
209 Relation m_relationStoredForSelectionalConstraint;
210};
211
212} // closing namespace SyntacticAnalysis
213} // closing namespace LinguisticProcessing
214} // closing namespace Lima
215
216#endif
A graph that stores the relations of syntactic dependency between the elements of a DependencyGraph.
DependencyGraph::vertex_descriptor DependencyGraphVertex
boost::adjacency_list< boost::vecS, boost::vecS, boost::bidirectionalS, DepVertexProperties, DepEdgeProperties > DependencyGraph
The dependency graph class.
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_SYNTACTICANALYSIS_EXPORT
just for semantics: base class for analysisData
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...
std::shared_ptr< SyntagmDefStruct > matrices() const
bool relation(const LinguisticGraphVertex &v1, const LinguisticGraphVertex &v2, const Common::MediaticData::SyntacticRelationId relationType=0)
void matrices(std::shared_ptr< SyntagmDefStruct > matrices)
std::vector< LinguisticAnalysisStructure::Token * > & ownedTokens()
const LinguisticAnalysisStructure::AnalysisGraph * iterator() const
std::tuple< LinguisticGraphVertex, LinguisticGraphVertex, Common::MediaticData::SyntacticRelationId > Relation
bool storeRelationForSelectionalConstraint(const LinguisticGraphVertex &v1, const LinguisticGraphVertex &v2, const Common::MediaticData::SyntacticRelationId relationType=0)
LinguisticAnalysisStructure::AnalysisGraph * iterator()
std::vector< LinguisticAnalysisStructure::MorphoSyntacticData * > & ownedMorphosyntacticData()
NAUTITIA.