LIMA
Libre Multilingual Analyzer — C++ API
Loading...
Searching...
No Matches
DocumentElements.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2022 CEA LIST <gael.de-chalendar@cea.fr>
2//
3// SPDX-License-Identifier: MIT
4
5/************************************************************************
6 * @file DocumentElements.h
7 * @author Besancon Romaric
8 * @date Wed Oct 29 13:22:02 2003
9 * @author Gael de Chalendar
10 * @date Wed Apr 08 2015
11 ***********************************************************************/
12
17#include "documentProperty.h"
19
20#include <deque>
21#include <string>
22
23#include <QtCore/QTextStream>
24
25
26#ifndef DOCUMENTELEMENTS_H
27#define DOCUMENTELEMENTS_H
28
29namespace Lima {
30namespace DocumentsReader {
31
44
45
47public:
49
50 virtual bool isDiscarding() {return false;}
51 virtual bool isPresentation() {return false;}
52
53 virtual FieldType nodeType() {return NODE_NOTYPE;}
54};
55
62class DOCUMENTSREADER_EXPORT ContentElementPart : public AbstractDocumentElement, public std::pair<Lima::LimaString,unsigned int> {
63public:
64 ContentElementPart():std::pair<Lima::LimaString,unsigned int>(Lima::LimaString(),0) {}
65 ContentElementPart(const Lima::LimaString& text, const unsigned int offset)
66 : std::pair<Lima::LimaString,unsigned int>(text,offset) {}
68 void addText(const Lima::LimaString& text) { first.append(text); }
69 const Lima::LimaString& getText(void) const { return first; }
70 unsigned int getOffset(void) const { return second; }
71 Lima::LimaString& getText(void) { return first; }
72};
73
79class DOCUMENTSREADER_EXPORT AbstractStructuredDocumentElement : public AbstractDocumentElement, public std::deque<ContentElementPart*> {
80public:
82
83 // Ajoute une partie de contenu non contigue
84 void addPart(const Lima::LimaString& text, const unsigned int offset);
85
86 virtual bool hasPropType( ) { return false; }
87 virtual const DocumentPropertyType& getPropType() { return m_propType; }
88 virtual const Lima::LimaString& getPropertyValue() const { return m_propertyValue; }
89
90 virtual const QString& getElementName() const {return m_elementName; };
91
92 // Called when some character content is added
93 virtual void addToCurrentOffset(const Lima::LimaString& value);
94
95 // Accessor
96 unsigned long int getOffset();
97
98 // Accessor
99 void setOffset( unsigned long int offset);
100
101 void addSpaces(int nbSpaces);
102
103protected:
104 AbstractStructuredDocumentElement( const QString& elementName, unsigned int firstBytePos );
105
107
108 unsigned long int m_offset;
109
112
113};
114
115
122{
123public:
124 DiscardableDocumentElement( const QString& elementName, unsigned int firstBytePos );
126 bool isDiscarding() override {return true;}
127 virtual FieldType nodeType() override {return NODE_DISCARDABLE;}
128};
129
130class DOCUMENTSREADER_EXPORT PropagatedProperties : public std::map<DocumentPropertyType, std::vector<std::string> >
131{
132public:
134
135 friend DOCUMENTSREADER_EXPORT std::ostream& operator << (std::ostream&, const PropagatedProperties&);
136 friend DOCUMENTSREADER_EXPORT QTextStream& operator << (QTextStream&, const PropagatedProperties&);
137 friend DOCUMENTSREADER_EXPORT QDebug& operator << (QDebug&, const PropagatedProperties&);
138
139 virtual void print(std::ostream&) const;
140 virtual void print(QTextStream&) const;
141 virtual void print(QDebug&) const;
142};
143
144
145
149{
150public:
152 const QString& elementName,
153 unsigned int firstBytePos ,
154 const PropagatedProperties& toBePropagated );
156
157 void addProperty( const DocumentPropertyType& propType, const std::string& value );
158
159
160 const PropagatedProperties& getPropertyList() const;
161
162 void setPropagatedValue(
163 const PropagatedProperties& toBePropagated );
164
165protected:
167
168};
169
187{
188public:
190 const QString& elementName,
191 unsigned int firstBytePos ,
192 const DocumentPropertyType& propType,
193 const PropagatedProperties& toBePropagated );
195
196 bool hasPropType( ) override { return( m_propType.getValueCardinality() != CARDINALITY_NONE ); }
197 virtual FieldType nodeType() override {return NODE_INDEXING;}
198
199};
200
207{
208public:
209 HierarchyDocumentElement( const QString& elementName, unsigned int firstBytePos ,
210 const PropagatedProperties& toBePropagated );
212 virtual FieldType nodeType() override {return NODE_HIERARCHY;}
213};
214
222{
223public:
225 const QString& elementName,
226 unsigned int firstBytePos ,
227 const PropagatedProperties& toBePropagated );
229 bool isPresentation() override {return true;}
230 virtual FieldType nodeType() override {return NODE_PRESENTATION;}
231};
232
238{
239public:
241 const QString& elementName,
242 unsigned int firstBytePos,
243 const DocumentPropertyType& propType,
244 const PropagatedProperties& toBePropagated );
246 virtual FieldType nodeType() override {return NODE_IGNORED;}
247
248 bool hasPropType( ) override { return( m_propType.getValueCardinality() != CARDINALITY_NONE ); }
249};
250
257{
258public:
260 const QString& elementName,
261 unsigned int firstBytePos ,
262 const DocumentPropertyType& propType );
263 bool hasPropType( ) override { return true; }
265 // Called when some character content is added
266 void addToCurrentOffset(const Lima::LimaString& value) override;
267 virtual FieldType nodeType() override {return NODE_PROPERTY;}
268
269};
270
271
272} // namespace DocumentsReader
273} // namespace Lima
274
275#endif
QDebug & operator<<(QDebug &qd, const std::string &str)
Definition QsLog.cpp:39
unsigned long int m_offset
current position during parsing
virtual const Lima::LimaString & getPropertyValue() const
virtual const DocumentPropertyType & getPropType()
Partie de texte (contenu dans un element) partageant le meme offset caractere.
ContentElementPart(const Lima::LimaString &text, const unsigned int offset)
const Lima::LimaString & getText(void) const
void addText(const Lima::LimaString &text)
Element d'un document Xml discardable Exemple <USELESS>private comment</USELESS> => " ...
Element d'un document XML definissant une propriete du noeud pere Exemple <filename>d1....
Element d'un document XML dont content est indexee Exemple <section lang="fre">yeah</section> Il peut...
Element d'un document XML de presentation Exemple <BOLD>important</BOLD> => " important " ...
#define DOCUMENTSREADER_EXPORT
FieldType
a type containing the type of an element
@ NODE_DISCARDABLE
root of XML file
@ NODE_PRESENTATION
node that can contain indexing nodes in its hierarchy.
@ NODE_ROOT
no type: field is ignored
@ NODE_INDEXING
node inside an indexing node whose content (including its children) is replaced by spaces
@ NODE_HIERARCHY
node whose content is analyzed and indexed
@ NODE_PROPERTY
nodes which are not children of hierarchy nodes are ignored
@ NODE_IGNORED
node inside an indexing node with content replaced by spaces, but which content is kept
NAUTITIA.
QString LimaString
Definition LimaString.h:33
STL namespace.