LIMA
Libre Multilingual Analyzer — C++ API
Loading...
Searching...
No Matches
BoWRelation.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 * @file BoWRelation.cpp
8 * @author Gael de Chalendar
9 * @date Tue Oct 31 2006
10 * copyright Copyright (C) 2006-2012 by CEA LIST
11 *
12 ***********************************************************************/
13
14
15#include "BoWRelation.h"
16#include "bowToken.h"
20
21#include <iterator> // for debug output
22#include <algorithm> // function (on refMap)
23
24#include <string>
25
26using namespace std;
27
28namespace Lima
29{
30namespace Common
31{
32namespace BagOfWords
33{
34
35#define DEFAULT_SEPARATOR QChar{'#'}
36#define DEFAULT_COMPOUND_SEPARATOR QChar{'_'}
37
38//***********************************************************************
39// static members initialization
40//***********************************************************************
44
45//***********************************************************************
46// constructors
47//***********************************************************************
49 m_realization(),
50 m_type(0),
51 s_type(0)
52{
53// BOWLOGINIT;
54// LDEBUG << "Creating BoWRelation : " << (*this) << " - " << this;
55}
56
57BoWRelation::BoWRelation(const LimaString& realization,
58 uint64_t type):
59 m_realization(realization),
60 m_type(type)
61{
63// BOWLOGINIT;
64// LDEBUG << "Creating BoWRelation : " << (*this) << " - " << this;
65}
66
67BoWRelation::BoWRelation(const LimaString& realization,
68 uint64_t type,uint64_t syntype):
69 m_realization(realization),
70 m_type(type),
71 s_type(syntype)
72{
74// BOWLOGINIT;
75// LDEBUG << "Creating BoWRelation : " << (*this) << " - " << this;
76}
77
79 m_realization(rel.m_realization),
80 m_type(rel.m_type),
81 s_type(rel.s_type)
82{
83// BOWLOGINIT;
84// LDEBUG << "Copying BoWRelation : " << rel << " - " << &rel << " ; new one is: " << this;
85}
86
87
88//***********************************************************************
89// destructor
90//***********************************************************************
94
95//***********************************************************************
96// member functions
97//***********************************************************************
99{
100 // BOWLOGINIT;
101 // std::string dummy;
102 // std::wostringstream wossdummy;
103 // wossdummy << m_realization << m_separator;
104 // LDEBUG << "getString: " << Lima::Common::Misc::wstring2string(dummy, wossdummy.str()) << m_type;
105
107 {
108 return getRealization();
109 }
110 else
111 {
112 std::ostringstream oss;
113 oss << m_type;
115 }
116}
117
118
119// convert the spaces in realization string to a non-space character
120// (problems in indexing)
122{
123 int current(0);
124 int i=m_realization.indexOf(" ",current);
125 while (i != -1)
126 {
128 current=i+1;
129 i=m_realization.indexOf(" ",current);
130 }
131}
132
133//***********************************************************************
134// == operator
135// added by Benoit Mathieu
136//***********************************************************************
137
139{
140 return ( (m_type==t.m_type) &&
142 (s_type == t.s_type));
143}
144
146{
147 return !(*this==t);
148}
149
150
151//***********************************************************************
152// input functions
153//***********************************************************************
155 int& current,
156 const LimaChar& separator)
157{
158 int i=str.indexOf(separator,current);
159 if (i==-1)
160 {
161 Lima::LimaString res(str.mid(current));
162 if (res.isEmpty())
163 {
165 throw InputErrorException("no other field in string "+s);
166 }
167 else
168 {
169 return res;
170 }
171 }
172 Lima::LimaString res=str.mid(current,i-current);
173 current=i+1;
174 return res;
175}
176
177void BoWRelation::parse(const Lima::LimaString& str, int current)
178{
180 LDEBUG << "BoWRelation::parse" << str << current << findNextElement(str,current,m_separator);
183}
184
185//***********************************************************************
186// binary input/output
187//***********************************************************************
188void BoWRelation::read(std::istream& file)
189{
193// LDEBUG << "BoWRelation::read " << Misc::limastring2utf8stdstring(m_realization) << " / " << m_type;
194}
195
196void BoWRelation::write(std::ostream& file) const
197{
198// LDEBUG << "BoWRelation::write " << Misc::limastring2utf8stdstring(m_realization) << " / " << m_type;
202}
203
204//**********************************************************************
205// output on ostream (mostly for debug)
206std::ostream& operator << (std::ostream& os, const BoWRelation& rel)
207{
209 << rel.m_type << "/" << "-" << rel.s_type << "/";
210 return os;
211}
212QDebug& operator << (QDebug& os, const BoWRelation& rel)
213{
214 os << "/" << rel.getRealization() << "-"
215 << rel.m_type << "/" << "-" << rel.s_type << "/";
216 return os;
217}
218
219//***********************************************************************
220// output
221//***********************************************************************
223{
224 std::ostringstream oss;
225 oss << "/" << Misc::limastring2utf8stdstring(getRealization()) << "-"
226 << m_type << "/" << "-" << s_type << "/";
227 return oss.str();
228}
229
231{
232 std::ostringstream oss;
234 << m_type << ")";
235 return oss.str();
236}
237
238} // namespace BagOfWords
239} // namespace Common
240} // namespace Lima
#define DEFAULT_SEPARATOR
#define DEFAULT_COMPOUND_SEPARATOR
#define LDEBUG
Definition LimaCommon.h:157
#define BOWLOGINIT
Definition LimaCommon.h:201
This class is used to type the relation between a part and its enclosing complex token.
Definition BoWRelation.h:50
virtual std::string getIdUTF8String() const
function used to identify a bowtoken in a text (used in BowDumper)
static Lima::LimaString findNextElement(const Lima::LimaString &str, int &current, const LimaChar &separator)
virtual void parse(const Lima::LimaString &str, int current)
for parsing of input stream
virtual Lima::LimaString getRealization(void) const
Definition BoWRelation.h:65
virtual void write(std::ostream &file) const
Lima::LimaString getString(void) const
virtual void read(std::istream &file)
virtual std::string getOutputUTF8String(void) const
get a string of the BoWRelation for output function
void convertSpaces(void)
convert the spaces in the realization string into a non-space character (defined by the m_compoundSep...
bool operator==(const BoWRelation &) const
redefine equality
bool operator!=(const BoWRelation &) const
redefine inequality as negation of equality.
LIMA_BOW_EXPORT uint8_t toInt(const BoWType &bt)
Definition bowToken.cpp:42
T & operator<<(T &qd, const BoWType &bt)
void writeUTF8StringField(std::ostream &file, const Lima::LimaString &s)
Binary write a a LimaString in a file as an utf8 string.
uint64_t readCodedInt(std::istream &file)
read a integer coded in variable-byte format in a file
std::string limastring2utf8stdstring(const Lima::LimaString &phrase, uint32_t size0)
Convert a wide string to a string , in dest up to size bytes.
void readUTF8StringField(std::istream &file, Lima::LimaString &s)
Binary read an utf8 string from a file and store it in a LimaString.
void writeCodedInt(std::ostream &file, const uint64_t number)
write a integer coded in variable-byte format in a file
LimaString utf8stdstring2limastring(const std::string &src)
NAUTITIA.
QChar LimaChar
Definition LimaString.h:30
QString LimaString
Definition LimaString.h:33
STL namespace.