29 using namespace KKMLL;
59 if (finalCleanUpRanAlready)
64 if (!finalCleanUpRanAlready)
66 if (exisitingDescriptions)
68 delete exisitingDescriptions;
69 exisitingDescriptions = NULL;
71 finalCleanUpRanAlready =
true;
87 sparseMinFeatureNum (0),
104 kkint32 memoryConsumedEstimated =
sizeof (FileDesc) +
105 attributes.MemoryConsumedEstimated () +
106 sizeof (AttributeType) * attributeVector.size () +
107 sizeof (kkint32) * cardinalityVector.size () +
108 classes.MemoryConsumedEstimated () +
109 classNameAttribute.MemoryConsumedEstimated ();
111 return memoryConsumedEstimated;
118 bool alreadyExists =
false;
120 for (
kkint32 fieldNum = 0; fieldNum < (kkint32)_fieldNames.size (); fieldNum++)
125 KKStr fieldName = _fieldNames[fieldNum];
132 while (alreadyExists);
142 attributes.PushOnBack (
new Attribute (attribute));
143 attributeVector.push_back (attribute.Type ());
149 cardinalityVector.push_back (card);
158 AttributeList::const_iterator idx;
159 for (idx = attributes.begin (); idx != attributes.end (); ++idx)
161 AddAAttribute (**idx);
174 alreadyExists =
false;
175 AttributePtr existingAttribute = attributes.LookUpByName (_name);
176 if (existingAttribute)
179 alreadyExists =
true;
183 curAttribute =
new Attribute (_name, _type, attributes.QueueSize ());
184 attributes.PushOnBack (curAttribute);
185 attributeVector.push_back (curAttribute->Type ());
190 cardinalityVector.push_back (card);
198 MLClassList::const_iterator idx;
199 for (idx = classesToAdd.begin (); idx != classesToAdd.end (); idx++)
202 if (classes.PtrToIdx (ic) < 0)
203 classes.AddMLClass (ic);
212 ValidateFieldNum (fieldNum,
"GetAAttribute");
213 const Attribute& a = attributes [fieldNum];
221 const KKStr& nominalValue,
227 ValidateFieldNum (fieldNum,
"AddANominalValue");
233 attributes[fieldNum].AddANominalValue (nominalValue, alreadyExist);
235 cardinalityVector[fieldNum]++;
250 KKStr errMsg =
"FileDesc::AddANominalValue ***ERROR*** No Current Attribute Set.";
251 log.Level (-1) << endl << errMsg << endl << endl;
255 alreadyExist =
false;
258 cardinalityVector[curAttribute->FieldNum ()]++;
265 const KKStr& nominalValue,
270 curAttribute = attributes.LookUpByName (attributeName);
274 errMsg <<
"FileDesc::AddANominalValue ***ERROR***, Invalid Attribute[" << attributeName <<
"].";
275 log.Level (-1) << endl << errMsg << endl << endl;
286 return classes.LookUpByName (className);
293 return classes.GetUnKnownClass ();
300 return classes.GetMLClassPtr (className);
309 if ((fieldNum < 0) || (fieldNum >= attributes.QueueSize ()))
312 errMsg <<
"FileDesc::" << funcName <<
" ***ERROR*** Invalid FieldNum[" << fieldNum <<
"] Only [" << attributes.QueueSize () <<
"] fields defined.";
313 cerr << endl << errMsg << endl << endl;
314 throw KKException (errMsg);
322 const KKStr& nominalValue
325 ValidateFieldNum (fieldNum,
"LookUpNominalCode");
326 const Attribute& a = attributes[fieldNum];
343 ValidateFieldNum (fieldNum,
"Type");
350 errMsg <<
"FileDesc::Cardinality ***ERROR*** Could not locate attribute[" << fieldNum <<
"]";
372 ValidateFieldNum (fieldNum,
"Type");
373 return attributes[fieldNum].Type ();
380 ValidateFieldNum (fieldNum,
"TypeStr");
381 return AttributeTypeToStr (attributes[fieldNum].Type ());
389 ValidateFieldNum (fieldNum,
"FieldName");
390 return attributes[fieldNum].Name ();
399 ValidateFieldNum (fieldNum,
"GetNominalValue");
400 return attributes[fieldNum].GetNominalValue (code);
412 for (kkint32 x = 0; x < attributes.QueueSize (); x++)
413 table[x] = attributes.IdxToPtr (x);
423 for (x = 0; x < attributes.QueueSize (); x++)
424 attributeTypes[x] = attributes[x].Type ();
425 return attributeTypes;
433 VectorInt32 cardinalityTable (attributes.QueueSize (), 0);
434 for (x = 0; x < attributes.QueueSize (); x++)
435 cardinalityTable[x] = attributes[x].Cardinality ();
436 return cardinalityTable;
445 if ((NumOfFields () != rightSide.NumOfFields ()) ||
446 (Version () != rightSide.Version ()) ||
447 (attributes != rightSide.attributes)
458 if ((NumOfFields () != rightSide.NumOfFields ()) ||
459 (Version () != rightSide.Version ()) ||
460 (attributes != rightSide.attributes)
480 log.Level (-1) << endl
481 <<
"FileDesc::SameExceptForSymbolicData Field count mis-match" << endl
482 <<
" File[" << fileName <<
"] count[" << otherFd.NumOfFields () <<
"] File[" << otherFd.fileName <<
"] Count[" << otherFd.NumOfFields () <<
"]" << endl
493 for (fieldNum = 0; fieldNum < numOfFields; fieldNum++)
500 log.Level (-1) << endl
501 <<
"FileDesc::SameExceptForSymbolicData Field Name mis-match" << endl
502 <<
" File[" << fileName <<
"] Name[" << lName <<
"] File[" << rightFileName <<
"] Name[" << rName <<
"]" << endl
515 log.Level (-1) << endl
516 <<
"FileDesc::SameExceptForSymbolicData Field Type mis-match" << endl
517 <<
" File[" << fileName <<
"] Name[" << lName <<
"] File[" << rightFileName <<
"] Name[" << rName <<
"]" << endl
541 bool FileDesc::finalCleanUpRanAlready =
false;
557 if (fileDesc == NULL)
559 KKStr errMsg =
"FileDesc::GetExistingFileDesc ***ERROR*** (fileDesc == NULL).";
560 cerr << endl << errMsg << endl << endl;
569 if (!exisitingDescriptions)
572 exisitingDescriptions->PushOnBack (fileDesc);
574 finalCleanUpRanAlready =
false;
575 atexit (FileDesc::FinalCleanUp);
580 for (
auto existingFileDesc: *exisitingDescriptions)
582 if (existingFileDesc == fileDesc)
584 result = existingFileDesc;
587 else if (existingFileDesc == NULL)
591 else if ((*existingFileDesc) == (*fileDesc))
596 result = existingFileDesc;
603 exisitingDescriptions->PushOnBack (fileDesc);
625 a = attributes.IdxToPtr (i);
634 cout <<
" Code does not match ";
636 cout << j <<
":" << a->GetNominalValue(j) <<
" ";
642 cout <<
"Symbolic (";
647 cout <<
" Code does not match ";
649 cout << j <<
":" << a->GetNominalValue(j) <<
" ";
684 return attributes.LookUpByName (attributeName);
692 AttributePtr a = attributes.LookUpByName (attributeName);
730 log.Level (-1) << endl
731 <<
"FileDesc::MergeSymbolicFields There are more differences between file descriptions besides symbolic data." << endl
732 <<
" File[" << left.fileName <<
"] File[" << right.fileName <<
"]" << endl
744 for (fieldNum = 0; fieldNum < numOfFields; fieldNum++)
751 log.Level (-1) << endl
752 <<
"FileDesc::MergeSymbolicFields Field Name mis-match" << endl
753 <<
" File[" << left.fileName <<
"] Name[" << lName <<
"] File[" << right.fileName <<
"] Name[" << rName <<
"]" << endl
764 log.Level (-1) << endl
765 <<
"FileDesc::MergeSymbolicFields Field Type mis-match" << endl
766 <<
" File[" << left.fileName <<
"] Name[" << lName <<
"] File[" << right.fileName <<
"] Name[" << rName <<
"]" << endl
787 bool alreadyExists =
false;
807 while (t && (!cancelFlag))
818 FileName (*(eKKStr->Value ()));
824 if (eAttributes && (eAttributes->Value ()))
825 AddAttributes (*(eAttributes->Value ()));
839 ClassNameAttribute (*(eKKStr->Value ()));
844 XmlElementInt32Ptr eKKInt32 =
dynamic_cast<XmlElementInt32Ptr>(e);
851 XmlElementInt32Ptr eKKInt32 =
dynamic_cast<XmlElementInt32Ptr>(e);
857 log.Level (-1) << endl
858 <<
"XmlElementFileDesc ***ERROR*** Unexpected Element <" << className <<
", VarName=" << varName.QuotedStr () <<
">" << endl
887 if (!fileName.Empty ())
888 XmlElementKKStr::WriteXML (fileName,
"FileName", o);
890 XmlElementAttributeList::WriteXML (attributes,
"Attributes", o);
892 XmlElementMLClassNameList::WriteXML (classes,
"Classes", o);
894 if (!ClassNameAttribute ().Empty ())
895 XmlElementKKStr::WriteXML (ClassNameAttribute (),
"ClassNameAttribute", o);
897 XmlElementInt32::WriteXML (version,
"Version", o);
899 if (sparseMinFeatureNum != 0)
900 XmlElementInt32::WriteXML (sparseMinFeatureNum,
"SparseMinFeatureNum", o);
955 FileDescPtr v = value;
963 const KKStr& varName,
__int16 kkint16
16 bit signed integer.
KKStr(kkint32 size)
Creates a KKStr object that pre-allocates space for 'size' characters.
XmlTag(const KKStr &_name, TagTypes _tagType)
KKStr TypeStr(kkint32 fieldNum) const
const KKMLL::AttributePtr LookUpByName(const KKStr &attributeName) const
void AddANominalValue(const KKStr &nominalValue, bool &alreadyExists)
Adds a allowable Nominal value to the Nominal or Symbolic field that this attribute represents...
Provides a detailed description of the attributes of a dataset.
static FileDescPtr GetExistingFileDesc(FileDescPtr fileDesc)
Returns a pointer to an existing instance of 'fileDesc' if it exists, otherwise will use one being pa...
bool EqualIgnoreCase(const char *s2) const
const KKStr & GetNominalValue(kkint32 code) const
Returns the nominal value for the given ordinal value.
kkuint32 NumOfFields() const
FileDescList * FileDescListPtr
GoalKeeper * GoalKeeperPtr
void AddAAttribute(const KKB::KKStr &_name, KKMLL::AttributeType _type, bool &alreadyExists)
XmlElement(XmlTagPtr _nameTag, XmlStream &s, RunLog &log)
MLClassPtr GetMLClassPtr(const KKStr &className)
KKMLL::AttributeType Type(kkint32 fieldNum) const
void AddANominalValue(const KKStr &attributeName, const KKStr &nominalValue, bool &alreadyExist, RunLog &log)
kkint32 GetNominalCode(const KKStr &nominalValue) const
static void Destroy(volatile GoalKeeperPtr &_goalKeeperInstance)
Destroys an existing instance of GoalKeeper.
MLClassPtr LookUpUnKnownMLClass()
XmlElementFileDesc(XmlTagPtr tag, XmlStream &s, VolConstBool &cancelFlag, RunLog &log)
void ReadXML(XmlStream &s, XmlTagConstPtr tag, VolConstBool &cancelFlag, RunLog &log)
XmlElementAttributeList * XmlElementAttributeListPtr
void SparseMinFeatureNum(kkint32 _sparseMinFeatureNum)
bool SameExceptForSymbolicData(const FileDesc &otherFd, RunLog &log) const
void AddAAttribute(const KKMLL::Attribute &attribute)
static void Create(const KKStr &_name, volatile GoalKeeperPtr &_newGoalKeeper)
Create a GoalKeeper object and avoid a race condition doing it.
void Version(kkint16 _version)
kkint32 MemoryConsumedEstimated() const
void AddClasses(const MLClassList &classesToAdd)
bool operator!=(const FileDesc &rightSize) const
Returns true if file description on the right size is NOT identical.
const KKStr & FieldName(kkint32 fieldNum) const
unsigned __int32 kkuint32
bool operator==(const FileDesc &rightSize) const
Returns true if file description on the right size is identical.
MLClassPtr LookUpMLClassByName(const KKStr &className)
VectorInt32 CreateCardinalityTable() const
describes a single Feature, Type and possible values.
kkint32 LookUpNominalCode(kkint32 fieldNum, const KKStr &nominalValue) const
static void FinalCleanUp()
Clean up function, call just before exiting the application.
void AddAttributes(const KKMLL::AttributeList &attributes)
void AddANominalValue(kkint32 fieldNum, const KKStr &nominalValue, bool &alreadyExist, RunLog &log)
const KKStr & GetNominalValue(kkint32 fieldNum, kkint32 code) const
bool AllFieldsAreNumeric() const
Allows the user to quickly determine if there are no nominal fields.
void StartBlock()
Initiates a Block as long as another thread has not already locked this object.
XmlElement * XmlElementPtr
void AddAtribute(const KKStr &attributeName, const KKStr &attributeValue)
const KKStr & FileName() const
XmlTag const * XmlTagConstPtr
Manages the reading and writing of objects in a simple XML format. For a class to be supported by Xml...
MLClassListPtr Value() const
void EndBlock()
Ends the block and allows other threads to pass through StatBlock.
static KKStr Concat(const std::vector< std::string > &values)
Concatenates the list of 'std::string' strings.
std::vector< kkint32 > VectorInt32
Vector of signed 32 bit integers.
void AddANominalValue(const KKStr &nominalValue, bool &alreadyExist, RunLog &log)
virtual ~XmlElementFileDesc()
bool operator!=(const KKStr &right) const
virtual const KKStr & VarName() const
KKStr StrFormatInt(kkint32 val, const char *mask)
AttributeType Type() const
std::ostream &__cdecl operator<<(std::ostream &os, const KKStr &str)
const KKMLL::AttributePtr * CreateAAttributeTable() const
virtual const KKStr & SectionName() const
static FileDescPtr NewContinuousDataOnly(VectorKKStr &_fieldNames)
Creates a simple FileDesc that consists of continuous data only.
kkint32 GetFieldNumFromAttributeName(const KKStr &attributeName) const
AttributeTypeVector CreateAttributeTypeTable() const
XmlElementKKStr * XmlElementKKStrPtr
void WriteXML(std::ostream &o)
static void WriteXML(const FileDesc &fileDesc, const KKStr &varName, std::ostream &o)
Used for logging messages.
void EncodeProblem(const struct svm_paramater ¶m, struct svm_problem &prob_in, struct svm_problem &prob_out)
FileDescPtr TakeOwnership()
virtual TokenTypes TokenType()=0
FileDescPtr Value() const
virtual XmlTokenPtr GetNextToken(VolConstBool &cancelFlag, RunLog &log)
kkint32 Cardinality(kkint32 fieldNum) const
KKException(const KKStr &_exceptionStr)
Maintains a list of MLClass instances.
void DisplayAttributeMappings()
kkint32 Cardinality() const
Returns back the cardinality of the attribute; the number of possible values it can take...
FileDescList(bool _owner)
static FileDescPtr MergeSymbolicFields(const FileDesc &left, const FileDesc &right, RunLog &log)
Merges the Symbolic fields of two different 'FileDesc' instances producing a new instance of 'FileDes...
Container class file 'FileDesc' instances.
#define INT_MAX
Adapted by Kurt Kramer be a 'class' definition so as to make it more usable in th ePices software wor...
void WriteXML(const KKStr &varName, std::ostream &o) const
#define XmlFactoryMacro(NameOfClass)
const KKMLL::Attribute & GetAAttribute(kkint32 fieldNum) const
XmlElementMLClassNameList * XmlElementMLClassNameListPtr
volatile const bool VolConstBool