LIMA
Libre Multilingual Analyzer — C++ API
Loading...
Searching...
No Matches
Entity.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 Entity.cpp
8 * @author Faiza GARA
9 * @date October 2007
10 * @version $Id:
11 * copyright Copyright (C) 2007 by CEA LIST
12 *
13 ***********************************************************************/
14
15
16#include "Entity.h"
21
22
23
24#include <string>
25
26#include <wchar.h>
27
28using namespace std;
30using namespace Lima::Common::MediaticData;
31
32namespace Lima
33{
34namespace LinguisticProcessing
35{
36namespace EventAnalysis
37{
38
39
40
41
42
43//***********************************************************************
44// constructors
45//***********************************************************************
47 m_position(),
48 m_length(),
49 m_main(false),
50 m_features()
51{
52
53}
54
56 const uint64_t position,
57 const uint64_t length,
58 EntityFeatures features):
59 m_position(position),
60 m_length(length),
61 m_main(false),
62 m_features(features)
63
64
65{
66}
67
68
69//***********************************************************************
70// destructor
71//***********************************************************************
74
75
76
77
78
79
80
81
82//***********************************************************************
83// == operator
84// added by Benoit Mathieu
85//***********************************************************************
86
87bool Entity::operator==(const Entity& e) const
88{
89
90 return ( (getPosition()==e.getPosition()) && (getLength()==e.getLength()));
91}
92
93bool Entity::operator!=(const Entity& t) const
94{
95 return !(*this==t);
96}
97
98
99
100
101//***********************************************************************
102// binary input/output
103//***********************************************************************
104
105
106void Entity::read(std::istream& file)
107{
111 uint64_t size= Common::Misc::readCodedInt(file);
112 std::string name;
113 std::string value;
114 for (uint64_t i=0; i < size; i++)
115 {
119 f.setName(name);
120 f.setValue(value);
121 m_features.push_back(f);
122 }
123 // lire le nombre de features et les sauvegarder
124}
125
126void Entity::write(std::ostream& file) const
127{
129 LDEBUG << "Entity::write()..";
134 LDEBUG << "Entity::write: write features...";
135 for (Automaton::EntityFeatures::const_iterator
136 featureItr=m_features.begin();
137 featureItr!=m_features.end(); featureItr++)
138 {
139 Common::Misc::writeStringField(file,featureItr->getName());
140 Common::Misc::writeStringField(file,featureItr->getValueString());
141 }
142 // ecrire le nombre de features et pour chaque feature ecrire le type et la valeur
143}
144
145std::map<std::string,std::string> Entity::getMapFeatures(void) const
146{
147 std::map<std::string,std::string> resmap;
148 for (Automaton::EntityFeatures::const_iterator
149 featureItr=m_features.begin();
150 featureItr!=m_features.end(); featureItr++)
151 {
152 resmap[featureItr->getName()]=featureItr->getValueString();
153 }
154 return resmap;
155}
156
157
158//**********************************************************************
159// output on ostream (mostly for debug)
160std::ostream& operator << (std::ostream& os, const Entity& annot)
161{
162 LIMA_UNUSED(annot);
163 return os;
164}
165
166
167//***********************************************************************
168// output
169//***********************************************************************
170
172{
173 std::ostringstream oss;
174 return oss.str();
175}
176
177
178std::string Entity::getIdUTF8String() const
179{
180 std::ostringstream oss;
181 return oss.str();
182}
183
184
185std::string Entity::toString(std::string parentURI) const
186{
187 LIMA_UNUSED(parentURI);
188 std::ostringstream oss;
189 oss << "<rdf:rdf xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\""
190 << " xmlns:dc=\"http://purl.org/dc/elements/1.1/\"" << std::endl;
191 return oss.str();
192
193}
194
195} // namespace EventAnalysis
196} // namespace LinguisticProcessing
197} // namespace Lima
#define LIMA_UNUSED(x)
Definition LimaCommon.h:224
#define LDEBUG
Definition LimaCommon.h:157
#define EVENTANALYSISLOGINIT
a generic feature that is defined by a name and a value, which can be of any type (use boost::any typ...
a list of generic features: each feature is unique (only one feature for a name)
virtual std::string getIdUTF8String() const
function used to identify an annotation in a text (used in Dumper)
Definition Entity.cpp:178
virtual std::string getOutputUTF8String(void) const
get a string of the OntoAnnotation for output function
Definition Entity.cpp:171
std::map< std::string, std::string > getMapFeatures(void) const
Definition Entity.cpp:145
virtual void read(std::istream &file)
Definition Entity.cpp:106
virtual std::string toString(std::string parentURI) const
function used to print the annotation in a string
Definition Entity.cpp:185
bool operator!=(const Entity &) const
redefine inequality as negation of equality.
Definition Entity.cpp:93
bool operator==(const Entity &) const
redefine equality
Definition Entity.cpp:87
Lima::LinguisticProcessing::Automaton::EntityFeatures m_features
Definition Entity.h:97
virtual void write(std::ostream &file) const
Definition Entity.cpp:126
uint64_t readCodedInt(std::istream &file)
read a integer coded in variable-byte format in a file
void readStringField(istream &file, string &s)
void writeStringField(ostream &file, const string &s)
void writeCodedInt(std::ostream &file, const uint64_t number)
write a integer coded in variable-byte format in a file
std::ostream & operator<<(std::ostream &os, const Entity &annot)
Definition Entity.cpp:160
NAUTITIA.
STL namespace.