LIMA
Libre Multilingual Analyzer — C++ API
Loading...
Searching...
No Matches
DataTypes.cpp
Go to the documentation of this file.
1// Copyright 2002-2019 CEA LIST
2// SPDX-FileCopyrightText: 2022 CEA LIST <gael.de-chalendar@cea.fr>
3//
4// SPDX-License-Identifier: MIT
5
6#include "DataTypes.h"
7#include "common/LimaCommon.h"
8#include <iostream>
9#include <limits>
10
11using namespace std;
12using namespace Lima;
13
14namespace Lima {
15
17{
18 friend class Node;
19public:
21 virtual ~NodePrivate();
22 NodePrivate(const NodePrivate& n);
23 NodePrivate& operator=(const NodePrivate& n);
24
25 NodePrivate(const std::string& docName,
26 STRUCT_ID structId,
27 NODE_ID nodeId,
28 CONTENT_ID contentId,
29 int32_t indexid ,
30 std::string uri,
31 std::string nodeMedia,
32 std::string nodeType,
33 std::string descrId ,
34 TOPO_POS nodeStart,
35 TOPO_POS nodeEnd,
36 TOPO_POS nodeLength,
37 NODE_ID nodeParent);
38
41 // OME Pour test
42 std::string m_docName;
47 std::string m_uri;
48 std::string m_nodeMedia;
49 std::string m_nodeType;
51 std::string m_descrId;
56 int32_t m_indexId;
57};
58
78
97
98NodePrivate::NodePrivate(const string& docName,
99 STRUCT_ID structId,
100 NODE_ID nodeId,
101 CONTENT_ID contentId,
102 int32_t indexid,
103 string uri,
104 string nodeMedia,
105 string nodeType,
106 string descrId,
107 TOPO_POS nodeStart,
108 TOPO_POS nodeEnd,
109 TOPO_POS nodeLength,
110 NODE_ID nodeParent )
111{
112 m_docName = docName;
113 m_structId = structId;
114 m_contentId = contentId;
115 m_nodeId = nodeId;
116 m_uri = uri;
117 m_nodeMedia = nodeMedia;
118 m_nodeType = nodeType;
119 m_nodeStart = nodeStart;
120 m_nodeEnd = nodeEnd;
121 m_nodeLength = nodeLength;
122 m_nodeParent = nodeParent;
123 m_descrId = descrId;
124 m_indexId = indexid;
125};
126
128Node::Node() : m_d(new NodePrivate()) {}
129Node::~Node() {delete m_d;}
130Node::Node(const Node& n) : m_d(new NodePrivate(*n.m_d)) {}
131
133{
134 if (this == &n)
135 return *this;
136
137 if (m_d != 0) {
138 delete m_d;
139 }
140 m_d = new NodePrivate(*n.m_d);
141 return *this;
142}
143
144
145Node::Node (const std::string& docName,
146 STRUCT_ID structId,
147 NODE_ID nodeId,
148 CONTENT_ID contentId,
149 int indexid ,
150 std::string uri,
151 std::string nodeMedia,
152 std::string nodeType,
153 std::string descrId ,
154 TOPO_POS nodeStart,
155 TOPO_POS nodeEnd,
156 TOPO_POS nodeLength,
157 NODE_ID nodeParent ) :
158 m_d(new NodePrivate(docName,
159 structId,
160 nodeId,
161 contentId,
162 indexid ,
163 uri,
164 nodeMedia,
165 nodeType,
166 descrId ,
167 nodeStart,
168 nodeEnd,
169 nodeLength,
170 nodeParent))
171{
172}
173
174std::string Node::get_DocName() const
175{
176 return m_d->m_docName;
177};
178void Node::set_DocName ( const std::string& docName )
179{
180 m_d->m_docName=docName;
181}
183{
184 return m_d->m_structId;
185};
187{
188 m_d->m_structId=structId;
189}
191{
192 return m_d->m_nodeId;
193};
195{
196 m_d->m_nodeId=NodeId;
197}
199{
200 return m_d->m_contentId;
201};
203{
204 m_d->m_contentId=ContentId;
205}
206
207int32_t Node::indexId() const
208{
209 return m_d->m_indexId;
210}
211
212void Node::indexId(int32_t id)
213{
214 m_d->m_indexId = id;
215}
216
217const std::string& Node::descrId() const
218{
219 return m_d->m_descrId;
220}
221
222const std::string& Node::nodeType() const
223{
224 return m_d->m_nodeType;
225}
226
228{
229 return m_d->m_nodeStart;
230}
231
233
234{
235 return m_d->m_nodeEnd;
236}
237
239{
240 return m_d->m_nodeLength;
241}
242
243
245{
246 return m_d->m_nodeParent;
247}
248
249const std::string& Node::uri() const
250{
251 return m_d->m_uri;
252}
253
254const std::string& Node::nodeMedia() const
255{
256 return m_d->m_nodeMedia;
257}
258
260{
261 m_d->m_nodeStart = ns;
262}
263
265{
266 m_d->m_nodeEnd = ns;
267}
268
270{
271 m_d->m_nodeLength = ns;
272}
273
275{
276 m_d->m_nodeParent = np;
277}
278
279
281
283{
284 friend class Structure;
285public:
288 StructurePrivate ( STRUCT_ID structID );
289 StructurePrivate& operator= ( const StructurePrivate& sp );
290
293
295 std::map<CONTENT_ID,Node> m_nodes;
296
299};
300
302 m_nodes(),
303 m_structId(std::numeric_limits< uint64_t >::max())
304{
305}
306
308 m_nodes(sp.m_nodes),
309 m_structId(sp.m_structId)
310{
311}
312
314{
315 m_nodes = sp.m_nodes;
317 return *this;
318}
319
321 m_nodes(),
322 m_structId(structID)
323{
324}
325
330
333{
334}
335
337 m_d(new StructurePrivate(structID))
338{
339}
340
342 m_d(new StructurePrivate(*s.m_d))
343{
344}
345
347{
348 if (this == &s)
349 return *this;
350
351 if (m_d!=0)
352 {
353 delete m_d;
354 }
355 m_d = new StructurePrivate(*s.m_d);
356 return *this;
357}
358
361{
362 delete m_d;
363}
364
365void Structure::addNode (const Node& node )
366{
367 m_d->m_nodes[node.get_ContentId()] = node;
368}
369
370void Structure::addNode ( CONTENT_ID ContentId, const Node& node )
371{
372 m_d->m_nodes[ContentId] = node;
373}
374
376{
377 if (m_d->m_nodes.find(ContentId) == m_d->m_nodes.end())
378 return nullptr;
379 return &m_d->m_nodes[ContentId];
380}
381
382const Node* Structure::getNode ( CONTENT_ID ContentId ) const
383{
384 if (m_d->m_nodes.find(ContentId) == m_d->m_nodes.end())
385 return nullptr;
386 return &m_d->m_nodes[ContentId];
387}
388
389const map<CONTENT_ID,Node>& Structure::getNodes() const
390{
391 return m_d->m_nodes;
392}
393
394map<CONTENT_ID,Node>& Structure::getNodes()
395{
396 return m_d->m_nodes;
397}
398
400{
401 return m_d->m_structId;
402}
403
405{
406 LIMA_UNUSED(StructureId);
407 for (auto ItrNodes=m_d->m_nodes.begin();
408 ItrNodes!=m_d->m_nodes.end(); ItrNodes++)
409 {
410 if ((ItrNodes->second.nodeType() == "topic"))
411 {
412 return getNode(ItrNodes->first);
413 }
414 }
415 return 0;
416}
417
418const Node* Structure::getFirstNode ( STRUCT_ID StructureId ) const
419{
420 LIMA_UNUSED(StructureId);
421 for (auto nodesIt=m_d->m_nodes.begin(); nodesIt!=m_d->m_nodes.end();nodesIt++)
422 {
423 if ((nodesIt->second.nodeType() == "topic"))
424 {
425 return getNode(nodesIt->first);
426 }
427 }
428 return 0;
429}
430
431std::ostream& operator<<(ostream& os, const Node& node)
432{
433 os << "Node " << node.get_StructId() << " " << node.get_NodeId() << " "
434 << node.get_ContentId() << " " << node.indexId() << " " << node.descrId()
435 << " " << node.get_DocName() << std::endl;
436 return os;
437}
438
439QDebug& operator<<(QDebug& os, const Node& node)
440{
441 os << "Node(structId:" << node.get_StructId()
442 << ", nodeId:" << node.get_NodeId()
443 << ", contentId:" << node.get_ContentId()
444 << ", indexId:" << node.indexId()
445 << ", descrId:" << node.descrId()
446 << ", docName:" << node.get_DocName()
447 << ", nodeStart:" << node.nodeStart()
448 << ", nodeEnd:" << node.nodeEnd()
449 << ", nodeLength:" << node.nodeLength()
450 << ", nodeParent:" << node.nodeParent() << ")";
451 return os;
452}
453
454std::ostream& operator<<(ostream& os, const Structure& structure)
455{
456 const auto& nodes = structure.getNodes();
457 os << "Structure( structId:" << structure.getStructId()
458 << ", nodes ("<<nodes.size()<<"): ";
459 for (auto ItrNodes = nodes.cbegin(); ItrNodes != nodes.cend(); ItrNodes++)
460 {
461 os << "node (" << ItrNodes->first << ":" << ItrNodes->second<<")";
462 }
463 os << " )";
464 return os;
465}
466
467QDebug& operator<<(QDebug& os, const Structure& structure)
468{
469 const auto& nodes = structure.getNodes();
470 os << "Structure( structId:" << structure.getStructId()
471 << ", nodes ("<<nodes.size()<<"): ";
472 for (auto ItrNodes = nodes.cbegin(); ItrNodes != nodes.cend() ; ItrNodes++)
473 {
474 os << "node (" << ItrNodes->first << ":" << ItrNodes->second<<")";
475 }
476 os << " )";
477 return os;
478}
479
481{
482 m_d->m_structId = structId;
483}
484
485} // Lima
Common Types.
#define LIMA_UNUSED(x)
Definition LimaCommon.h:224
#define LIMA_DATA_EXPORT
Definition LimaCommon.h:128
std::string m_docName
Definition DataTypes.cpp:42
CONTENT_ID m_contentId
identifiant de contenu au sein de la structure.
Definition DataTypes.cpp:46
NODE_ID m_nodeId
identifiant de noeud au sein de la structure.
Definition DataTypes.cpp:44
std::string m_nodeType
Definition DataTypes.cpp:49
TOPO_POS m_nodeStart
Definition DataTypes.cpp:52
NodePrivate & operator=(const NodePrivate &n)
Definition DataTypes.cpp:79
std::string m_descrId
identifiant de type de contenu
Definition DataTypes.cpp:51
STRUCT_ID m_structId
identifiant de structure
Definition DataTypes.cpp:40
std::string m_nodeMedia
Definition DataTypes.cpp:48
virtual ~NodePrivate()
Definition DataTypes.cpp:61
std::string m_uri
Definition DataTypes.cpp:47
TOPO_POS m_nodeLength
Definition DataTypes.cpp:54
noeud de contenu au sein d'une structure.
Definition DataTypes.h:62
const std::string & nodeMedia() const
Node & operator=(const Node &n)
void set_ContentId(CONTENT_ID ContentId)
void set_StructId(STRUCT_ID structId)
Node()
default constructor
STRUCT_ID get_StructId() const
TOPO_POS nodeStart() const
const std::string & nodeType() const
const std::string & descrId() const
CONTENT_ID get_ContentId() const
int32_t indexId() const
TOPO_POS nodeEnd() const
TOPO_POS nodeLength() const
NODE_ID nodeParent() const
void set_DocName(const std::string &docName)
virtual ~Node()
default destructor
const std::string & uri() const
void set_NodeId(NODE_ID NodeId)
std::string get_DocName() const
NODE_ID get_NodeId() const
StructurePrivate & operator=(const StructurePrivate &sp)
STRUCT_ID m_structId
the numeric identifier of the current structure
std::map< CONTENT_ID, Node > m_nodes
the set of
~StructurePrivate()
destructeur: delete des 'Nodes' de contenu
~Structure()
destructeur: delete des 'Nodes' de contenu
Node * getNode(CONTENT_ID ContentId)
get a content node, given its identifiers
Structure & operator=(const Structure &s)
void addNode(const Node &node)
const std::map< CONTENT_ID, Node > & getNodes() const
get all nodes of the current structure
Node * getFirstNode(STRUCT_ID)
get a content node, given its identifiers
STRUCT_ID getStructId() const
void setStructId(STRUCT_ID structId)
NAUTITIA.
uint64_t CONTENT_ID
Identifier of an feature content.
Definition DataTypes.h:45
uint64_t STRUCT_ID
Identifier of a structure in the structure index.
Definition DataTypes.h:35
std::ostream & operator<<(ostream &os, const Node &node)
uint64_t NODE_ID
Identifier of a node in a document.
Definition DataTypes.h:40
uint64_t TOPO_POS
Topology information.
Definition DataTypes.h:50
STL namespace.