19#include <QtCore/QDate>
20#include <QtCore/QTime>
28namespace LinguisticProcessing {
46 return (m_name==name);
51 if (m_name!=f.m_name) {
55 const type_info& type=m_value.type();
56 const type_info& typeOther=f.m_value.type();
57 if (type!=typeOther) {
61 if (type==
typeid(
string)) {
62 return (boost::any_cast<string>(m_value)==boost::any_cast<string>(f.m_value));
65 return (boost::any_cast<LimaString>(m_value)==boost::any_cast<LimaString>(f.m_value));
67 if (type==
typeid(
double)) {
68 return (boost::any_cast<double>(m_value)==boost::any_cast<double>(f.m_value));
70 if (type==
typeid(
int)) {
71 return (boost::any_cast<int>(m_value)==boost::any_cast<int>(f.m_value));
73 if (type==
typeid(QDate)) {
74 return (boost::any_cast<QDate>(m_value)==boost::any_cast<QDate>(f.m_value));
76 if (type==
typeid(QTime)) {
77 return (boost::any_cast<QTime>(m_value)==boost::any_cast<QTime>(f.m_value));
84 std::ostringstream oss;
85 const type_info& type=m_value.type();
86 if (type==
typeid(std::string)) {
87 return boost::any_cast<std::string>(m_value);
92 if (type==
typeid(
double)) {
93 std::ostringstream oss;
94 oss << boost::any_cast<double>(m_value);
97 if (type==
typeid(
int)) {
98 std::ostringstream oss;
99 oss << boost::any_cast<int>(m_value);
102 if (type==
typeid(QDate)) {
104 return (boost::any_cast<QDate>(m_value)).toString(Qt::ISODate).toUtf8().data();
106 if (type==
typeid(QTime)) {
108 return (boost::any_cast<QTime>(m_value)).toString(Qt::ISODate).toUtf8().data();
110 return "unknown_type";
114 std::ostringstream oss;
115 const type_info& type=m_value.type();
117 return boost::any_cast<LimaString>(m_value);
134 if (size()!=f.size()) {
137 for (EntityFeatures::const_iterator it1=begin(),it1_end=end(),it2=f.begin();
138 it1!=it1_end; it1++,it2++) {
139 if (! (*it1 == *it2) ) {
148 const QString& value)
152 LDEBUG <<
"EntityFeatures<QString>::appendFeature(" << name <<
"," << value <<
")";
153 EntityFeatures::iterator it=
findLast(name);
155 QString previous = boost::any_cast<QString>(it->getValue());
156 LDEBUG <<
"EntityFeatures::appendFeature: previous =" << previous;
157 previous.append(
" ").append(value);
158 (*it).setValue(boost::any(previous));
159 LDEBUG <<
"EntityFeatures::appendFeature: now =" << previous;
165 back().setName(name);
166 back().setValue(boost::any(value));
175 LDEBUG <<
"EntityFeatures<int>::appendFeature(" << name <<
"," << value <<
")";
177 EntityFeatures::iterator it=
findLast(name);
179 int previous = boost::any_cast<int>(*it);
181 (*it).setValue(boost::any(previous));
187 back().setName(name);
188 back().setValue(boost::any(value));
197 LDEBUG <<
"EntityFeatures<double>::appendFeature(" << name <<
"," << value <<
")";
199 EntityFeatures::iterator it=
findLast(name);
201 double previous = boost::any_cast<double>(*it);
203 (*it).setValue(boost::any(previous));
209 back().setName(name);
210 back().setValue(boost::any(value));
215find(
const std::string& featureName)
const
217 return std::find(begin(),end(),featureName);
221find(
const std::string& featureName)
223 return std::find(begin(),end(),featureName);
227findLast(
const std::string& featureName)
const
229 std::vector<std::string> pattern(1,featureName);
230 return std::find_end(begin(),end(),pattern.begin(),pattern.end());
234findLast(
const std::string& featureName)
236 std::vector<std::string> pattern(1,featureName);
237 return std::find_end(begin(),end(),pattern.begin(),pattern.end());
245 EntityFeatures::const_iterator it=f.begin(),it_end=f.end();
246 os << (*it).getName() <<
"=" << (*it).getValueString();
247 for (it++; it!=it_end; it++) {
248 os <<
"/" << (*it).getName() <<
"=" << (*it).getValueString();
257 EntityFeatures::const_iterator it=f.begin(),it_end=f.end();
258 os << (*it).getName() <<
"=" << (*it).getValueString();
259 for (it++; it!=it_end; it++) {
260 os <<
"/" << (*it).getName() <<
"=" << (*it).getValueString();
a generic feature that is defined by a name and a value, which can be of any type (use boost::any typ...
LimaString getValueLimaString() const
std::string getValueString() const
bool operator==(const EntityFeature &f) const
a list of generic features: each feature is unique (only one feature for a name)
EntityFeatures::const_iterator findLast(const std::string &featureName) const
bool operator==(const EntityFeatures &f) const
void appendFeature(const std::string &name, const ValueType &value)
EntityFeatures::const_iterator find(const std::string &featureName) const
std::string limastring2utf8stdstring(const Lima::LimaString &phrase, uint32_t size0)
Convert a wide string to a string , in dest up to size bytes.
LimaString utf8stdstring2limastring(const std::string &src)
std::ostream & operator<<(std::ostream &os, const DFFSPos &x)