30 using namespace KKMLL;
37 nominalValuesUpper (NULL),
51 nominalValuesUpper (NULL),
68 fieldNum (a.fieldNum),
70 nameUpper
(a.nameUpper
),
71 nominalValuesUpper (NULL),
88 delete nominalValuesUpper;
98 if (nominalValuesUpper)
101 return memoryConsumedEstimated;
113 msg <<
"Attribute::ValidateNominalType Attribute[" << funcName <<
"] must be a Nominal or Symbolic Type to perform this operation.";
114 cerr << std::endl << msg << std::endl << std::endl;
127 ValidateNominalType (
"AddANominalValue");
131 alreadyExists =
true;
135 alreadyExists =
false;
145 ValidateNominalType (
"GetNominalValue");
147 static KKStr missingDataValue =
"?";
152 return missingDataValue;
155 if (!nominalValuesUpper)
158 KKStrConstPtr result = nominalValuesUpper
->LookUp (code
);
162 <<
"Attribute::GetNominalValue ***ERROR*** Code[" << code <<
"] Does not exist." << endl
163 <<
" Attribute::Name[" << name <<
"]" << endl
187 ValidateNominalType (
"GetNominalCode");
196 if ((nameUpper
!= rightSide.nameUpper) || (
Type () != rightSide
.Type ()))
204 if ((*nominalValuesUpper)
!= (*rightSide.nominalValuesUpper))
215 return !(*
this == rightSide);
224 fieldNum = right.fieldNum;
226 nameUpper
= right.nameUpper;
228 delete nominalValuesUpper;
229 if (nominalValuesUpper)
232 nominalValuesUpper = NULL;
259 XmlTag startTag
("Attribute", startTagType
);
271 for (kkint32 nominalIdx = 0; nominalIdx < Cardinality (); ++nominalIdx)
272 nominalValues.push_back (GetNominalValue (nominalIdx));
289 delete nominalValuesUpper;
290 nominalValuesUpper = NULL;
297 while (t && (!cancelFlag))
299 if ((t->SectionName ().EqualIgnoreCase (
"NominalValues")) && (
typeid(*t) ==
typeid(XmlElementVectorKKStr)))
301 delete nominalValuesUpper;
302 nominalValuesUpper =
new KKStrListIndexed (
true,
305 XmlElementVectorKKStrPtr v =
dynamic_cast<XmlElementVectorKKStrPtr>(t);
306 if ((v != NULL) && (v->Value () != NULL))
308 VectorKKStr::const_iterator idx;
309 bool alreadyEixists =
false;
310 for (idx = v->Value ()->begin (); idx != v->Value ()->end (); ++idx)
311 AddANominalValue (*idx, alreadyEixists);
348 kkint32 memoryConsumedEstimated =
sizeof (AttributeList) + nameIndex.size ();
351 std::map<KKStr, AttributePtr>::const_iterator idx;
352 for (idx = nameIndex.begin (); idx != nameIndex.end (); ++idx)
353 memoryConsumedEstimated += (
sizeof (AttributePtr) + idx->first.MemoryConsumedEstimated ());
357 AttributeList::const_iterator idx;
358 for (idx = begin (); idx != end (); ++idx)
360 memoryConsumedEstimated += (*idx)->MemoryConsumedEstimated ();
364 return memoryConsumedEstimated;
375 map<KKStr, AttributePtr>::const_iterator p;
376 p = nameIndex.find (nameUpper);
377 if (p == nameIndex.end ())
386 AddToNameIndex (attribute);
387 KKQueue<Attribute>::PushOnBack (attribute);
393 AddToNameIndex (attribute);
394 KKQueue<Attribute>::PushOnFront (attribute);
401 nameIndex.insert (pair<KKStr, AttributePtr> (attribute->Name ().ToUpper (), attribute));
411 for (idx = begin (); idx != end (); idx++)
413 v->push_back ((*idx)->Type ());
424 static vector<KKStr> AttributeTypeStrings =
433 if ((type < (AttributeType)0) || ((kkuint32)type >= AttributeTypeStrings.size ()))
434 return KKStr::EmptyStr ();
436 return AttributeTypeStrings[(
int)type];
468 if (size () != right.size ())
471 AttributeList::const_iterator idxL;
472 AttributeList::const_iterator idxR;
475 idxR = right.begin ();
477 while (idxL != end ())
479 AttributePtr leftAttribute = *idxL;
480 AttributePtr rightAttribute = *idxR;
482 if ((*leftAttribute) != (*rightAttribute))
496 return !(*
this == right);
511 AttributeList::const_iterator idx;
512 for (idx = begin (); idx != end (); ++idx)
536 while (t && (!cancelFlag))
538 if (
typeid (*t) ==
typeid(XmlElementAttribute))
540 XmlElementAttributePtr attrToken =
dynamic_cast<XmlElementAttributePtr> (t);
541 if (attrToken->Value ())
542 PushOnBack (attrToken->TakeOwnership ());
579 tagStart.AddAtribute (
"Size", (kkint32)size ());
584 for (AttributeType zed = AttributeType::NULLAttribute; zed <= AttributeType::Symbolic; ++zed)
585 o <<
"\t" << AttributeTypeToStr (zed);
588 o <<
"CodedAttributeValues";
589 for (
auto idx: *
this)
590 o <<
"\t" << (
int)idx;
611 while (t && (!cancelFlag))
623 if (!fieldName.Empty ())
624 decodeTable.push_back (AttributeTypeFromStr (fieldName));
632 if ((x < 0) || (x >= (kkint32)decodeTable.size ()))
634 log.Level (-1) << endl <<
"AttributeTypeVector::ReadXML ***ERROR*** Invalid Code Value[" << x <<
"]" << endl << endl;
635 push_back (AttributeType::NULLAttribute);
639 push_back ((AttributeType)x);
KKStr(kkint32 size)
Creates a KKStr object that pre-allocates space for 'size' characters.
XmlTag(const KKStr &_name, TagTypes _tagType)
void PushOnFront(AttributePtr attribute)
Attribute(const Attribute &a)
void AddANominalValue(const KKStr &nominalValue, bool &alreadyExists)
Adds a allowable Nominal value to the Nominal or Symbolic field that this attribute represents...
const AttributePtr LookUpByName(const KKStr &attributeName) const
void PushOnBack(AttributePtr attribute)
bool EqualIgnoreCase(const char *s2) const
kkint32 MemoryConsumedEstimated() const
const KKStr & GetNominalValue(kkint32 code) const
Returns the nominal value for the given ordinal value.
void TrimWhiteSpace(const char *_whiteSpace=" ")
After this call all leading and trailing whitespace will be trimmed from tokens.
bool operator!=(const AttributeList &right) const
Determines if two different attribute lists are different; compares each respective attribute...
KKStr GetNextToken(const char *delStr="\n\t\r ")
Extract next Token from string, tokens will be separated by delimiter characters. ...
KKStrConstPtr LookUp(kkuint32 x) const
const KKStr & AttributeValueKKStr(const KKStr &name) const
kkint32 GetNominalCode(const KKStr &nominalValue) const
XmlContent * XmlContentPtr
bool operator!=(const Attribute &rightSide) const
void ReadXML(XmlStream &s, XmlTagConstPtr tag, VolConstBool &cancelFlag, RunLog &log)
unsigned __int32 kkuint32
AttributeType operator++(AttributeType zed)
kkint32 MemoryConsumedEstimated() const
describes a single Feature, Type and possible values.
Attribute(const KKStr &_name, AttributeType _type, kkint32 _fieldNum)
KKStr & operator=(KKStr &&src)
void AddAtribute(const KKStr &attributeName, kkint32 attributeValue)
KKStrListIndexed(bool _owner, bool _caseSensitive)
KKStrParser(const KKStr &_str)
kkint32 AttributeValueInt32(const KKStr &attributeName) const
void WriteXML(const KKStr &varName, std::ostream &o) const
KKStr(const KKStr &str)
Copy Constructor.
void AddAtribute(const KKStr &attributeName, const KKStr &attributeValue)
AttributeTypeVector * AttributeTypeVectorPtr
XmlTag const * XmlTagConstPtr
Manages the reading and writing of objects in a simple XML format. For a class to be supported by Xml...
void ReadXML(XmlStream &s, XmlTagConstPtr tag, VolConstBool &cancelFlag, RunLog &log)
AttributeType AttributeTypeFromStr(const KKStr &s)
static KKStr Concat(const std::vector< std::string > &values)
Concatenates the list of 'std::string' strings.
AttributeTypeVector(kkuint32 initialSize, AttributeType initialValue)
bool operator==(const AttributeList &right) const
Determines if two different attribute lists are the same; compares each respective attribute...
void Upper()
Converts all characters in string to their Upper case equivalents via 'toupper'.
kkint32 MemoryConsumedEstimated() const
static const KKStr & EmptyStr()
Static method that returns an Empty String.
kkint32 MemoryConsumedEstimated() const
bool operator!=(const KKStr &right) const
bool operator==(const Attribute &rightSide) const
void WriteXML(const KKStr &varName, std::ostream &o) const
AttributeTypeVectorPtr CreateAttributeTypeVector() const
kkint32 GetNextTokenInt(const char *delStr="\n\t\r ")
AttributeType Type() const
AttributeList(bool owner)
void WriteXML(std::ostream &o)
KKStr & operator=(const KKStr &src)
KKStrPtr const Content() const
void ReadXML(XmlStream &s, XmlTagConstPtr tag, VolConstBool &cancelFlag, RunLog &log)
Used for logging messages.
void EncodeProblem(const struct svm_paramater ¶m, struct svm_problem &prob_in, struct svm_problem &prob_out)
kkint32 LookUp(const KKStr &s) const
KKStrListIndexed(const KKStrListIndexed &list)
Class that manages the extraction of tokens from a String without being destructive to the original s...
void WriteXML(const KKStr &varName, std::ostream &o) const
virtual XmlTokenPtr GetNextToken(VolConstBool &cancelFlag, RunLog &log)
bool operator!=(const KKStrListIndexed &right)
KKException(const KKStr &_exceptionStr)
void WriteXML(const KKStr &varName, std::ostream &o) const
kkint32 Cardinality() const
Returns back the cardinality of the attribute; the number of possible values it can take...
const KKStr & AttributeTypeToStr(AttributeType type)
#define XmlFactoryMacro(NameOfClass)
Attribute & operator=(const Attribute &right)
volatile const bool VolConstBool