LIMA
Libre Multilingual Analyzer — C++ API
Loading...
Searching...
No Matches
bowDocument.cpp
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
6
/************************************************************************
7
*
8
* @file bowDocument.cpp
9
* @author Besancon Romaric (besanconr@zoe.cea.fr)
10
* @date Wed Oct 8 2003
11
* copyright Copyright (C) 2003 by CEA LIST
12
*
13
***********************************************************************/
14
15
#include "
bowDocument.h
"
16
#include "
common/Data/strwstrtools.h
"
17
#include <fstream>
18
#include <deque>
19
20
using namespace
std
;
21
22
namespace
Lima
23
{
24
namespace
Common
25
{
26
namespace
BagOfWords
27
{
28
29
//***********************************************************************
30
// stream operators
31
//***********************************************************************
32
33
std::ostream&
operator<<
(std::ostream& out,
const
BoWBlocType
& blocType)
34
{
35
unsigned
char
blocTypeCode=
static_cast<
unsigned
char
>
(blocType);
36
out.write((
char
*) &(blocTypeCode),
sizeof
(
unsigned
char
));
37
return
out;
38
}
39
40
QDebug&
operator<<
(QDebug& out,
const
BoWBlocType
& blocType)
41
{
42
unsigned
char
blocTypeCode=
static_cast<
unsigned
char
>
(blocType);
43
out << blocTypeCode;
44
return
out;
45
}
46
47
std::istream&
operator>>
(std::istream& in,
BoWBlocType
& blocType)
48
{
49
unsigned
char
typeCode;
50
in.read((
char
*) &(typeCode),
sizeof
(
unsigned
char
));
51
blocType=
static_cast<
BoWBlocType
>
(typeCode);
52
return
in;
53
}
54
55
std::string
getBlocTypeString
(
BoWBlocType
blocType)
56
{
57
switch
(blocType) {
58
case
BoWBlocType::DOCUMENT_PROPERTIES_BLOC
:
59
return
"DOCUMENT_PROPERTIES_BLOC"
;
60
case
BoWBlocType::BOW_TEXT_BLOC
:
61
return
"BOW_TEXT_BLOC"
;
62
case
BoWBlocType::BIN_NUM_BLOC
:
63
return
"BIN_NUM_BLOC"
;
64
case
BoWBlocType::ST_BLOC
:
65
return
"ST_BLOC"
;
66
case
BoWBlocType::END_BLOC
:
67
return
"END_BLOC"
;
68
case
BoWBlocType::NODE_PROPERTIES_BLOC
:
69
return
"NODE_PROPERTIES_BLOC"
;
70
case
BoWBlocType::HIERARCHY_BLOC
:
71
return
"HIERARCHY_BLOC"
;
72
case
BoWBlocType::INDEXING_BLOC
:
73
return
"INDEXING_BLOC"
;
74
}
75
return
""
;
76
}
77
78
//***********************************************************************
79
// constructors
80
//***********************************************************************
81
BoWDocument::BoWDocument
():
82
GenericDocumentProperties(),
83
BoWText
()
84
{
85
#ifdef DEBUG_LP
86
BOWLOGINIT
;
87
LDEBUG
<<
"BoWDocument::BoWDocument()"
<<
this
;
88
#endif
89
}
90
91
BoWDocument::BoWDocument
(
const
BoWDocument
& d):
92
GenericDocumentProperties(d),
93
BoWText
(d)
94
{
95
#ifdef DEBUG_LP
96
BOWLOGINIT
;
97
LDEBUG
<<
"BoWDocument::BoWDocument(BoWDocument)"
<<
this
;
98
#endif
99
}
100
101
//***********************************************************************
102
// destructor
103
//***********************************************************************
104
BoWDocument::~BoWDocument
()
105
{
106
clear
();
107
}
108
109
//***********************************************************************
110
// assignment operator
111
//***********************************************************************
112
BoWDocument
&
BoWDocument::operator =
(
const
BoWDocument
& d)
113
{
114
if
(&d !=
this
)
115
{
116
BoWText::operator=
(d);
117
GenericDocumentProperties::operator=(d);
118
}
119
return
*
this
;
120
}
121
122
void
BoWDocument::clear
()
123
{
124
BoWText::clear
();
125
Lima::Common::Misc::GenericDocumentProperties::reinit
();
126
}
127
128
//***********************************************************************
129
// binary read/write
130
//***********************************************************************
131
void
BoWDocument::setProperties
(
const
GenericDocumentProperties& properties)
132
{
133
GenericDocumentProperties::operator=(properties);
134
}
135
136
//***********************************************************************
137
// binary read/write
138
//***********************************************************************
139
void
BoWDocument::reinit
()
140
{
141
GenericDocumentProperties::reinit();
142
BoWText::clear
();
143
}
144
145
//***********************************************************************
146
// binary read/write
147
//***********************************************************************
148
/*
149
void BoWDocument::read(std::istream& file)
150
{
151
// enum type with small number of values coded on one byte;
152
BoWBlocType blocType = readOneByteInt(file);
153
// old format
154
if (blocType==DOCUMENT_PROPERTIES_BLOC)
155
{
156
Misc::GenericDocumentProperties::read(file);
157
file >> blocType;
158
}
159
while (blocType==BOW_TEXT_BLOC)
160
{
161
BoWText::read(file);
162
if (file.eof()) break;
163
file >> blocType;
164
}
165
}
166
*/
167
168
/*
169
void BoWDocument::readPart(std::istream& file, AbstractBoWXMLWriter& writer, bool useIterator, std::ostream& os)
170
{
171
BoWBlocType blocType = readOneByteInt(file);
172
173
BOWLOGINIT;
174
LDEBUG << "BoWDocument::readPart: read "
175
<< (int)blocType;
176
177
// new format
178
switch( blocType )
179
{
180
case HIERARCHY_BLOC:
181
{
182
std::string elementName;
183
Misc::readStringField(file,elementName);
184
writer.openSBoWNode(os, this, elementName);
185
break;
186
}
187
case INDEXING_BLOC:
188
{
189
std::string elementName;
190
Misc::readStringField(file,elementName);
191
writer.openSBoWIndexingNode(os, this, elementName);
192
break;
193
}
194
case BOW_TEXT_BLOC:
195
{
196
BoWText::clear();
197
BoWText::read(file);
198
writer.processSBoWText(os, this, useIterator);
199
break;
200
}
201
case NODE_PROPERTIES_BLOC:
202
{
203
Misc::GenericDocumentProperties::read(file);
204
writer.processProperties(os, this, useIterator);
205
break;
206
}
207
case END_BLOC:
208
{
209
writer.closeSBoWNode(os);
210
break;
211
}
212
}
213
}
214
*/
215
216
/*
217
void BoWDocument::write(std::ostream& file) const
218
{
219
// enum type with small number of values coded on one byte;
220
file << DOCUMENT_PROPERTIES_BLOC;
221
Misc::GenericDocumentProperties::write(file);
222
writeOneByteInt(file, BOW_TEXT_BLOC)
223
BoWText::write(file);
224
writeOneByteInt(file, END_BLOC)
225
}
226
*/
227
228
//***********************************************************************
229
// output
230
//***********************************************************************
231
std::ostream&
operator <<
(std::ostream& os,
const
BoWDocument
& d)
232
{
233
os << static_cast<Misc::GenericDocumentProperties>(d) << std::endl;
234
os << static_cast<BoWText>(d);
235
return
os;
236
}
237
238
QDebug&
operator <<
(QDebug& os,
const
BoWDocument
& d)
239
{
240
os << static_cast<Misc::GenericDocumentProperties>(d);
241
os << static_cast<BoWText>(d);
242
return
os;
243
}
244
245
}
// end namespace
246
}
// end namespace Common
247
}
// end namespace
LDEBUG
#define LDEBUG
Definition
LimaCommon.h:157
BOWLOGINIT
#define BOWLOGINIT
Definition
LimaCommon.h:201
bowDocument.h
Lima::Common::BagOfWords::BoWDocument
represent a document as a Bag Of Word, with associated document properties.
Definition
bowDocument.h:57
Lima::Common::BagOfWords::BoWDocument::reinit
virtual void reinit() override
Definition
bowDocument.cpp:139
Lima::Common::BagOfWords::BoWDocument::setProperties
virtual void setProperties(const Misc::GenericDocumentProperties &properties)
Definition
bowDocument.cpp:131
Lima::Common::BagOfWords::BoWDocument::clear
virtual void clear() override
Definition
bowDocument.cpp:122
Lima::Common::BagOfWords::BoWDocument::~BoWDocument
virtual ~BoWDocument()
Definition
bowDocument.cpp:104
Lima::Common::BagOfWords::BoWDocument::operator=
BoWDocument & operator=(const BoWDocument &)
Definition
bowDocument.cpp:112
Lima::Common::BagOfWords::BoWDocument::BoWDocument
BoWDocument()
Definition
bowDocument.cpp:81
Lima::Common::BagOfWords::BoWText
This class represents a list of elements, that are pointers on polymmorphic tokens that can be simple...
Definition
bowText.h:48
Lima::Common::BagOfWords::BoWText::operator=
BoWText & operator=(const BoWText &)
Definition
bowText.cpp:52
Lima::Common::BagOfWords::BoWText::clear
virtual void clear()
Definition
bowText.cpp:85
Lima::Common::Misc::GenericDocumentProperties::reinit
virtual void reinit()
Definition
genericDocumentProperties.cpp:340
Lima::Common::BagOfWords::getBlocTypeString
std::string getBlocTypeString(BoWBlocType blocType)
Definition
bowDocument.cpp:55
Lima::Common::BagOfWords::BoWBlocType
BoWBlocType
Definition
bowDocument.h:34
Lima::Common::BagOfWords::DOCUMENT_PROPERTIES_BLOC
@ DOCUMENT_PROPERTIES_BLOC
Definition
bowDocument.h:35
Lima::Common::BagOfWords::INDEXING_BLOC
@ INDEXING_BLOC
Definition
bowDocument.h:42
Lima::Common::BagOfWords::BOW_TEXT_BLOC
@ BOW_TEXT_BLOC
Definition
bowDocument.h:36
Lima::Common::BagOfWords::NODE_PROPERTIES_BLOC
@ NODE_PROPERTIES_BLOC
Definition
bowDocument.h:40
Lima::Common::BagOfWords::END_BLOC
@ END_BLOC
Definition
bowDocument.h:39
Lima::Common::BagOfWords::ST_BLOC
@ ST_BLOC
Definition
bowDocument.h:38
Lima::Common::BagOfWords::HIERARCHY_BLOC
@ HIERARCHY_BLOC
Definition
bowDocument.h:41
Lima::Common::BagOfWords::BIN_NUM_BLOC
@ BIN_NUM_BLOC
Definition
bowDocument.h:37
Lima::Common::BagOfWords::operator>>
std::istream & operator>>(std::istream &in, BoWBlocType &blocType)
Definition
bowDocument.cpp:47
Lima::Common::BagOfWords::operator<<
T & operator<<(T &qd, const BoWType &bt)
Definition
AbstractBoWElement.h:54
Lima
NAUTITIA.
Definition
AmosePluginsManager.h:15
std
STL namespace.
strwstrtools.h
lima_linguisticprocessing
src
linguisticProcessing
common
BagOfWords
bowDocument.cpp
Generated by
1.9.8