KSquare Utilities
FileDesc.cpp
Go to the documentation of this file.
1 #include "FirstIncludes.h"
2 #include <stdio.h>
3 #include <ctype.h>
4 #include <limits.h>
5 #include <time.h>
6 #include <string>
7 #include <iostream>
8 #include <fstream>
9 #include <vector>
10 #include "MemoryDebug.h"
11 using namespace std;
12 
13 
14 #include "GlobalGoalKeeper.h"
15 #include "DateTime.h"
16 #include "KKBaseTypes.h"
17 #include "KKException.h"
18 #include "OSservices.h"
19 #include "KKQueue.h"
20 #include "RunLog.h"
21 #include "KKStr.h"
22 using namespace KKB;
23 
24 
25 #include "FileDesc.h"
26 #include "FeatureNumList.h"
27 #include "MLClass.h"
28 #include "FeatureVector.h"
29 using namespace KKMLL;
30 
31 
32 
33 
34 namespace KKMLL
35 {
36  /**
37  *@class FileDescList
38  *@brief Container class file 'FileDesc' instances.
39  *@details The class definition is not in the header file because there is no reason for any other entity
40  * other than FileDesc to access a list of FileDesc instances.
41  */
42  class FileDescList: public KKQueue<FileDesc>
43  {
44  public:
45  FileDescList (bool _owner);
46 
47  ~FileDescList ();
48 
49  private:
50  };
51 
52 } /* KKMLL */
53 
54 
55 
56 
58 {
59  if (finalCleanUpRanAlready)
60  return;
61 
62  FileDesc::CreateBlocker ();
63  blocker->StartBlock ();
64  if (!finalCleanUpRanAlready)
65  {
66  if (exisitingDescriptions)
67  {
68  delete exisitingDescriptions;
69  exisitingDescriptions = NULL;
70  }
71  finalCleanUpRanAlready = true;
72  }
73  blocker->EndBlock ();
74 
75  GoalKeeper::Destroy (blocker); blocker = NULL;
76 } /* FinalCleanUp */
77 
78 
79 
80 
82 
83  attributes (true),
84  cardinalityVector (),
85  classes (),
86  curAttribute (NULL),
87  sparseMinFeatureNum (0),
88  version (0)
89 {
90 }
91 
92 
93 
94 
95 
97 {
98  kkint32 ZED = 7887;
99 }
100 
101 
103 {
104  kkint32 memoryConsumedEstimated = sizeof (FileDesc) +
105  attributes.MemoryConsumedEstimated () +
106  sizeof (AttributeType) * attributeVector.size () +
107  sizeof (kkint32) * cardinalityVector.size () +
108  classes.MemoryConsumedEstimated () +
109  classNameAttribute.MemoryConsumedEstimated ();
110 
111  return memoryConsumedEstimated;
112 }
113 
114 
115 
116 FileDescPtr FileDesc::NewContinuousDataOnly (VectorKKStr& _fieldNames)
117 {
118  bool alreadyExists = false;
119  FileDescPtr newFileDesc = new FileDesc ();
120  for (kkint32 fieldNum = 0; fieldNum < (kkint32)_fieldNames.size (); fieldNum++)
121  {
122  kkint32 seqNum = 0;
123  do
124  {
125  KKStr fieldName = _fieldNames[fieldNum];
126  if (seqNum > 0)
127  fieldName << "_" << StrFormatInt (seqNum, "000");
128 
129  newFileDesc->AddAAttribute (fieldName, AttributeType::Numeric, alreadyExists);
130  seqNum++;
131  }
132  while (alreadyExists);
133  }
134 
135  return GetExistingFileDesc (newFileDesc);
136 } /* NewContinuousDataOnly */
137 
138 
139 
140 void FileDesc::AddAAttribute (const Attribute& attribute)
141 {
142  attributes.PushOnBack (new Attribute (attribute));
143  attributeVector.push_back (attribute.Type ());
144 
145  kkint32 card = 0;
146  if (attribute.Type () == AttributeType::Numeric)
147  card = 999999999;
148 
149  cardinalityVector.push_back (card);
150 } /* AddAAttribute */
151 
152 
153 
154 
155 
156 void FileDesc::AddAttributes (const KKMLL::AttributeList& attributes)
157 {
158  AttributeList::const_iterator idx;
159  for (idx = attributes.begin (); idx != attributes.end (); ++idx)
160  {
161  AddAAttribute (**idx);
162  }
163 }
164 
165 
166 
167 
168 
169 void FileDesc::AddAAttribute (const KKStr& _name,
170  AttributeType _type,
171  bool& alreadyExists
172  )
173 {
174  alreadyExists = false;
175  AttributePtr existingAttribute = attributes.LookUpByName (_name);
176  if (existingAttribute)
177  {
178  // This is a very bad error, it should not be able to happen
179  alreadyExists = true;
180  return;
181  }
182 
183  curAttribute = new Attribute (_name, _type, attributes.QueueSize ());
184  attributes.PushOnBack (curAttribute);
185  attributeVector.push_back (curAttribute->Type ());
186 
187  kkint32 card = 0;
188  if (curAttribute->Type () == AttributeType::Numeric)
189  card = INT_MAX;
190  cardinalityVector.push_back (card);
191 } /* AddAAttribute */
192 
193 
194 
195 
196 void FileDesc::AddClasses (const MLClassList& classesToAdd)
197 {
198  MLClassList::const_iterator idx;
199  for (idx = classesToAdd.begin (); idx != classesToAdd.end (); idx++)
200  {
201  MLClassPtr ic = *idx;
202  if (classes.PtrToIdx (ic) < 0)
203  classes.AddMLClass (ic);
204  }
205 } /* AddClasses */
206 
207 
208 
209 
210 const Attribute& FileDesc::GetAAttribute (kkint32 fieldNum) const
211 {
212  ValidateFieldNum (fieldNum, "GetAAttribute");
213  const Attribute& a = attributes [fieldNum];
214  return a;
215 } /* GetAAttribute */
216 
217 
218 
219 
221  const KKStr& nominalValue,
222  bool& alreadyExist,
223  RunLog& log
224  )
225 
226 {
227  ValidateFieldNum (fieldNum, "AddANominalValue");
228  AttributeType t = Type (fieldNum);
229  if ((t == AttributeType::Nominal) ||
231  )
232  {
233  attributes[fieldNum].AddANominalValue (nominalValue, alreadyExist);
234  if (!alreadyExist)
235  cardinalityVector[fieldNum]++;
236  }
237 } /* AddANominalValue */
238 
239 
240 
241 
242 void FileDesc::AddANominalValue (const KKStr& nominalValue,
243  bool& alreadyExist,
244  RunLog& log
245  )
246 {
247  if (!curAttribute)
248  {
249  // This should never happen, means that there has not been a nominal feature added yet.
250  KKStr errMsg = "FileDesc::AddANominalValue ***ERROR*** No Current Attribute Set.";
251  log.Level (-1) << endl << errMsg << endl << endl;
252  throw KKException (errMsg);
253  }
254 
255  alreadyExist = false;
256  curAttribute->AddANominalValue (nominalValue, alreadyExist);
257  if (!alreadyExist)
258  cardinalityVector[curAttribute->FieldNum ()]++;
259 } /* AddANominalValue */
260 
261 
262 
263 
264 void FileDesc::AddANominalValue (const KKStr& attributeName,
265  const KKStr& nominalValue,
266  bool& alreadyExist,
267  RunLog& log
268  )
269 {
270  curAttribute = attributes.LookUpByName (attributeName);
271  if (!curAttribute)
272  {
273  KKStr errMsg (128);
274  errMsg << "FileDesc::AddANominalValue ***ERROR***, Invalid Attribute[" << attributeName << "].";
275  log.Level (-1) << endl << errMsg << endl << endl;
276  throw KKException (errMsg);
277  }
278 
279  AddANominalValue (nominalValue, alreadyExist, log);
280 } /* AddANominalValue */
281 
282 
283 
285 {
286  return classes.LookUpByName (className);
287 }
288 
289 
290 
292 {
293  return classes.GetUnKnownClass ();
294 }
295 
296 
297 
299 {
300  return classes.GetMLClassPtr (className);
301 }
302 
303 
304 
305 void FileDesc::ValidateFieldNum (kkint32 fieldNum,
306  const char* funcName
307  ) const
308 {
309  if ((fieldNum < 0) || (fieldNum >= attributes.QueueSize ()))
310  {
311  KKStr errMsg (128);
312  errMsg << "FileDesc::" << funcName << " ***ERROR*** Invalid FieldNum[" << fieldNum << "] Only [" << attributes.QueueSize () << "] fields defined.";
313  cerr << endl << errMsg << endl << endl;
314  throw KKException (errMsg);
315  }
316 } /* ValidateFieldNum */
317 
318 
319 
320 
322  const KKStr& nominalValue
323  ) const
324 {
325  ValidateFieldNum (fieldNum, "LookUpNominalCode");
326  const Attribute& a = attributes[fieldNum];
327  if ((a.Type () != AttributeType::Nominal) &&
329  )
330  {
331  return -1;
332  }
333 
334  return a.GetNominalCode (nominalValue);
335 } /* LookUpNominalCode */
336 
337 
338 
339 
340 
342 {
343  ValidateFieldNum (fieldNum, "Type");
344 
345  AttributePtr a = attributes.IdxToPtr (fieldNum);
346 
347  if (!a)
348  {
349  KKStr errMsg;
350  errMsg << "FileDesc::Cardinality ***ERROR*** Could not locate attribute[" << fieldNum << "]";
351  cerr << errMsg;
352  throw KKException (errMsg);
353  }
354 
355  switch (a->Type ())
356  {
357  case AttributeType::Ignore: return a->Cardinality ();
359  case AttributeType::Numeric: return INT_MAX;
361 
362  default: return INT_MAX;
363  }
364 
365  return INT_MAX;
366 } /* Cardinality */
367 
368 
369 
371 {
372  ValidateFieldNum (fieldNum, "Type");
373  return attributes[fieldNum].Type ();
374 } /* Type */
375 
376 
377 
378 KKStr FileDesc::TypeStr (kkint32 fieldNum) const
379 {
380  ValidateFieldNum (fieldNum, "TypeStr");
381  return AttributeTypeToStr (attributes[fieldNum].Type ());
382 } /* TypeStr */
383 
384 
385 
386 
387 const KKStr& FileDesc::FieldName (kkint32 fieldNum) const
388 {
389  ValidateFieldNum (fieldNum, "FieldName");
390  return attributes[fieldNum].Name ();
391 } /* FieldName */
392 
393 
394 
396  kkint32 code
397  ) const
398 {
399  ValidateFieldNum (fieldNum, "GetNominalValue");
400  return attributes[fieldNum].GetNominalValue (code);
401 } /* GetNominalValue */
402 
403 
404 
405 
406 
407 const
409 {
410  AttributePtr* table = new AttributePtr[attributes.QueueSize ()];
411 
412  for (kkint32 x = 0; x < attributes.QueueSize (); x++)
413  table[x] = attributes.IdxToPtr (x);
414 
415  return table;
416 } /* CreateAAttributeTable */
417 
418 
420 {
421  kkint32 x;
422  AttributeTypeVector attributeTypes (attributes.size (), AttributeType::NULLAttribute);
423  for (x = 0; x < attributes.QueueSize (); x++)
424  attributeTypes[x] = attributes[x].Type ();
425  return attributeTypes;
426 } /* CreateAttributeTypeTable () */
427 
428 
429 
431 {
432  kkint32 x;
433  VectorInt32 cardinalityTable (attributes.QueueSize (), 0);
434  for (x = 0; x < attributes.QueueSize (); x++)
435  cardinalityTable[x] = attributes[x].Cardinality ();
436  return cardinalityTable;
437 } /* CreateCardinalityTable */
438 
439 
440 
441 
442 
443 bool FileDesc::operator== (const FileDesc& rightSide) const
444 {
445  if ((NumOfFields () != rightSide.NumOfFields ()) ||
446  (Version () != rightSide.Version ()) ||
447  (attributes != rightSide.attributes)
448  )
449  return false;
450 
451  return true;
452 } /* operator== */
453 
454 
455 
456 bool FileDesc::operator!= (const FileDesc& rightSide) const
457 {
458  if ((NumOfFields () != rightSide.NumOfFields ()) ||
459  (Version () != rightSide.Version ()) ||
460  (attributes != rightSide.attributes)
461  )
462  return true;
463 
464  return false;
465 } /* operator== */
466 
467 
468 
469 
470 
471 
473  RunLog& log
474  ) const
475 {
476  bool same = true;
477 
478  if (NumOfFields () != otherFd.NumOfFields ())
479  {
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
483  << endl;
484 
485  return false;
486  }
487 
488  kkint32 numOfFields = NumOfFields ();
489  kkint32 fieldNum = 0;
490 
491  const KKStr& rightFileName = otherFd.FileName ();
492 
493  for (fieldNum = 0; fieldNum < numOfFields; fieldNum++)
494  {
495  const KKStr& lName = FieldName (fieldNum);
496  const KKStr& rName = otherFd.FieldName (fieldNum);
497 
498  if (lName != rName)
499  {
500  log.Level (-1) << endl
501  << "FileDesc::SameExceptForSymbolicData Field Name mis-match" << endl
502  << " File[" << fileName << "] Name[" << lName << "] File[" << rightFileName << "] Name[" << rName << "]" << endl
503  << endl;
504 
505  same = false;
506  }
507 
508  else
509  {
510  AttributeType lType = Type (fieldNum);
511  AttributeType rType = otherFd.Type (fieldNum);
512 
513  if (lType != rType)
514  {
515  log.Level (-1) << endl
516  << "FileDesc::SameExceptForSymbolicData Field Type mis-match" << endl
517  << " File[" << fileName << "] Name[" << lName << "] File[" << rightFileName << "] Name[" << rName << "]" << endl
518  << endl;
519 
520  same = false;
521  }
522  }
523  }
524 
525  return same;
526 } /* SameExceptForSymbolicData */
527 
528 
529 
530 
531 
532 
533 // Will keep a list of all FileDesc
534 // instances instantiated.
535 FileDescListPtr FileDesc::exisitingDescriptions = NULL;
536 
537 
538 GoalKeeperPtr FileDesc::blocker = NULL;
539 
540 
541 bool FileDesc::finalCleanUpRanAlready = false;
542 
543 
544 
545 // Will instantiate an instance of "GoalKeeper" if "blocker" does not already
546 // point one.
547 void FileDesc::CreateBlocker ()
548 {
549  if (!blocker)
550  GoalKeeper::Create ("FileDescBlocker", blocker); // Will handle Race condition.
551 }
552 
553 
554 
555 FileDescPtr FileDesc::GetExistingFileDesc (FileDescPtr fileDesc)
556 {
557  if (fileDesc == NULL)
558  {
559  KKStr errMsg = "FileDesc::GetExistingFileDesc ***ERROR*** (fileDesc == NULL).";
560  cerr << endl << errMsg << endl << endl;
561  throw KKException (errMsg);
562  }
563  FileDescPtr result = NULL;
564 
565  CreateBlocker ();
566 
567  blocker->StartBlock ();
568 
569  if (!exisitingDescriptions)
570  {
571  exisitingDescriptions = new FileDescList (true);
572  exisitingDescriptions->PushOnBack (fileDesc);
573  result = fileDesc;
574  finalCleanUpRanAlready = false;
575  atexit (FileDesc::FinalCleanUp);
576  }
577 
578  else
579  {
580  for (auto existingFileDesc: *exisitingDescriptions)
581  {
582  if (existingFileDesc == fileDesc)
583  {
584  result = existingFileDesc;
585  break;
586  }
587  else if (existingFileDesc == NULL)
588  {
589  continue;
590  }
591  else if ((*existingFileDesc) == (*fileDesc))
592  {
593  // Looks like we already have a compatible "FileDesc" instance.
594  // In this case this is the one the user will want.
595  delete fileDesc;
596  result = existingFileDesc;
597  break;
598  }
599  }
600 
601  if (!result)
602  {
603  exisitingDescriptions->PushOnBack (fileDesc);
604  result = fileDesc;
605  }
606  }
607 
608  blocker->EndBlock ();
609 
610  return result;
611 } /* GetExistingFileDesc */
612 
613 
614 
615 
616 
618 {
619  kkuint32 i;
620  kkint32 j;
621  AttributePtr a;
622 
623  for (i = 0; i < NumOfFields(); i++)
624  {
625  a = attributes.IdxToPtr (i);
626  cout << i << ": ";
627 
629  {
630  for (j = 0; j<a->Cardinality (); j++)
631  {
633  {
634  cout << " Code does not match ";
635  }
636  cout << j << ":" << a->GetNominalValue(j) << " ";
637  }
638  }
639 
640  else if (a->Type() == AttributeType::Symbolic)
641  {
642  cout << "Symbolic (";
643  for (j = 0; j<a->Cardinality (); j++)
644  {
646  {
647  cout << " Code does not match ";
648  }
649  cout << j << ":" << a->GetNominalValue(j) << " ";
650  }
651 
652  cout << ")";
653  }
654 
655 
656  else if (a->Type() == AttributeType::Ignore)
657  {
658  cout << "ignore";
659  }
660 
661  else if (a->Type() == AttributeType::Numeric)
662  {
663  cout << "numeric";
664  }
665 
666  else if (a->Type() == AttributeType::Ordinal)
667  {
668  cout << "ordinal";
669  }
670 
672  {
673  cout << "NULL";
674  }
675  cout << endl;
676  }
677 } /* DisplayAttributeMappings */
678 
679 
680 
681 const
682 AttributePtr FileDesc::LookUpByName (const KKStr& attributeName) const
683 {
684  return attributes.LookUpByName (attributeName);
685 } /* LookUpByName */
686 
687 
688 
689 
690 kkint32 FileDesc::GetFieldNumFromAttributeName (const KKStr& attributeName) const
691 {
692  AttributePtr a = attributes.LookUpByName (attributeName);
693  if (!a)
694  return -1;
695  else
696  return a->FieldNum ();
697 } /* GetFieldNumFromAttributeName */
698 
699 
700 
701 /**
702  * @brief Allows the user to quickly determine if there are no nominal fields.
703  * @details Example use is in CrossValidation application, by using this method it can quickly determine
704  * if it is worth while using encoding.
705  */
707 {
708  for (kkint32 fieldNum = 0; fieldNum < (kkint32)NumOfFields (); fieldNum++)
709  {
710  AttributeType t = Type (fieldNum);
711  if ((t != AttributeType::Numeric) && (t != AttributeType::Ignore))
712  return false;
713  }
714 
715 
716  return true;
717 } /* AllFieldsAreNumeric */
718 
719 
720 
721 
722 
723 FileDescPtr FileDesc::MergeSymbolicFields (const FileDesc& left,
724  const FileDesc& right,
725  RunLog& log
726  )
727 {
728  if (!left.SameExceptForSymbolicData (right, log))
729  {
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
733  << endl;
734 
735  return NULL;
736  }
737 
738  FileDescPtr f = new FileDesc ();
739 
740  kkint32 numOfFields = left.NumOfFields ();
741 
742  kkint32 fieldNum = 0;
743 
744  for (fieldNum = 0; fieldNum < numOfFields; fieldNum++)
745  {
746  const KKStr& lName = left.FieldName (fieldNum);
747  const KKStr& rName = right.FieldName (fieldNum);
748 
749  if (lName != rName)
750  {
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
754  << endl;
755 
756  return NULL;
757  }
758 
759  AttributeType lType = left.Type (fieldNum);
760  AttributeType rType = right.Type (fieldNum);
761 
762  if (lType != rType)
763  {
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
767  << endl;
768 
769  return NULL;
770  }
771 
772  f->AddAAttribute (left.GetAAttribute (fieldNum));
773  if (lType != AttributeType::Symbolic)
774  {
775  continue;
776  }
777 
778  // We can merge in Nominal Values for this field.
779 
780  kkint32 z;
781  for (z = 0; z < right.Cardinality (fieldNum); z++)
782  {
783  const KKStr& rightNomName = right.GetNominalValue (fieldNum, z);
784  kkint32 lCode = f->LookUpNominalCode (fieldNum, rightNomName);
785  if (lCode < 0)
786  {
787  bool alreadyExists = false;
788  f->AddANominalValue (fieldNum, rightNomName, alreadyExists, log);
789  lCode = f->LookUpNominalCode (fieldNum, rightNomName);
790  }
791  }
792  }
793 
794  return GetExistingFileDesc (f);
795 } /* MergeSymbolicFields */
796 
797 
798 
799 
801  XmlTagConstPtr tag,
802  VolConstBool& cancelFlag,
803  RunLog& log
804  )
805 {
806  XmlTokenPtr t = s.GetNextToken (cancelFlag, log);
807  while (t && (!cancelFlag))
808  {
810  {
811  XmlElementPtr e = dynamic_cast<XmlElementPtr> (t);
812  const KKStr& className = e->SectionName ();
813  const KKStr& varName = e->VarName ();
814  if (varName.EqualIgnoreCase ("FileName"))
815  {
816  XmlElementKKStrPtr eKKStr = dynamic_cast<XmlElementKKStrPtr>(e);
817  if (eKKStr)
818  FileName (*(eKKStr->Value ()));
819  }
820 
821  else if (varName.EqualIgnoreCase ("Attributes"))
822  {
823  XmlElementAttributeListPtr eAttributes = dynamic_cast<XmlElementAttributeListPtr>(e);
824  if (eAttributes && (eAttributes->Value ()))
825  AddAttributes (*(eAttributes->Value ()));
826  }
827 
828  else if (varName.EqualIgnoreCase ("Classes"))
829  {
831  if (eCLasses && (eCLasses->Value ()))
832  AddClasses (*(eCLasses->Value ()));
833  }
834 
835  else if (varName.EqualIgnoreCase ("ClassNameAttribute"))
836  {
837  XmlElementKKStrPtr eKKStr = dynamic_cast<XmlElementKKStrPtr>(e);
838  if (eKKStr)
839  ClassNameAttribute (*(eKKStr->Value ()));
840  }
841 
842  else if (varName.EqualIgnoreCase ("Version"))
843  {
844  XmlElementInt32Ptr eKKInt32 = dynamic_cast<XmlElementInt32Ptr>(e);
845  if (eKKInt32)
846  Version ((kkint16)eKKInt32->Value ());
847  }
848 
849  else if (varName.EqualIgnoreCase ("SparseMinFeatureNum"))
850  {
851  XmlElementInt32Ptr eKKInt32 = dynamic_cast<XmlElementInt32Ptr>(e);
852  if (eKKInt32)
853  SparseMinFeatureNum (eKKInt32->Value ());
854  }
855  else
856  {
857  log.Level (-1) << endl
858  << "XmlElementFileDesc ***ERROR*** Unexpected Element <" << className << ", VarName=" << varName.QuotedStr () << ">" << endl
859  << endl;
860  }
861  }
862 
863  delete t;
864  t = s.GetNextToken (cancelFlag, log);
865  }
866 
867  delete t;
868  t = NULL;
869 } /* ReadXML */
870 
871 
872 
873 
874 
875 void FileDesc::WriteXML (const KKStr& varName,
876  ostream& o
877  ) const
878 
879 
880 {
881  XmlTag startTag ("FileDesc", XmlTag::TagTypes::tagStart);
882  if (!varName.Empty ())
883  startTag.AddAtribute ("VarName", varName);
884  startTag.WriteXML (o);
885  o << endl;
886 
887  if (!fileName.Empty ())
888  XmlElementKKStr::WriteXML (fileName, "FileName", o);
889 
890  XmlElementAttributeList::WriteXML (attributes, "Attributes", o);
891 
892  XmlElementMLClassNameList::WriteXML (classes, "Classes", o);
893 
894  if (!ClassNameAttribute ().Empty ())
895  XmlElementKKStr::WriteXML (ClassNameAttribute (), "ClassNameAttribute", o);
896 
897  XmlElementInt32::WriteXML (version, "Version", o);
898 
899  if (sparseMinFeatureNum != 0)
900  XmlElementInt32::WriteXML (sparseMinFeatureNum, "SparseMinFeatureNum", o);
901 
902  XmlTag endTag ("FileDesc", XmlTag::TagTypes::tagEnd);
903  endTag.WriteXML (o);
904  o << endl;
905 }
906 
907 
908 
909 
910 
911 FileDescList::FileDescList (bool _owner):
913 {
914 }
915 
916 
917 
919 {
920 }
921 
922 
923 
924 
926  XmlStream& s,
927  VolConstBool& cancelFlag,
928  RunLog& log
929  ):
930  XmlElement (tag, s, log),
931  value (NULL)
932 {
933  value = new FileDesc ();
934  value->ReadXML (s, tag, cancelFlag, log);
935  value = FileDesc::GetExistingFileDesc (value);
936 }
937 
938 
939 
941 {
942  // You can not delete an instance of FileDesc.
943  value = NULL;
944 }
945 
946 
947 FileDescPtr XmlElementFileDesc::Value () const
948 {
949  return value;
950 }
951 
952 
954 {
955  FileDescPtr v = value;
956  value = NULL;
957  return v;
958 }
959 
960 
961 
962 void XmlElementFileDesc::WriteXML (const FileDesc& fileDesc,
963  const KKStr& varName,
964  ostream& o
965  )
966 {
967  fileDesc.WriteXML (varName, o);
968 } /* WriteXML */
969 
970 
971 
972 XmlFactoryMacro(FileDesc)
__int16 kkint16
16 bit signed integer.
Definition: KKBaseTypes.h:85
KKStr(kkint32 size)
Creates a KKStr object that pre-allocates space for &#39;size&#39; characters.
Definition: KKStr.cpp:655
XmlTag(const KKStr &_name, TagTypes _tagType)
Definition: XmlStream.cpp:586
KKStr TypeStr(kkint32 fieldNum) const
Definition: FileDesc.cpp:378
MLClass * MLClassPtr
Definition: MLClass.h:46
const KKMLL::AttributePtr LookUpByName(const KKStr &attributeName) const
Definition: FileDesc.cpp:682
void AddANominalValue(const KKStr &nominalValue, bool &alreadyExists)
Adds a allowable Nominal value to the Nominal or Symbolic field that this attribute represents...
Definition: Attribute.cpp:123
Provides a detailed description of the attributes of a dataset.
Definition: FileDesc.h:72
static FileDescPtr GetExistingFileDesc(FileDescPtr fileDesc)
Returns a pointer to an existing instance of &#39;fileDesc&#39; if it exists, otherwise will use one being pa...
Definition: FileDesc.cpp:555
bool EqualIgnoreCase(const char *s2) const
Definition: KKStr.cpp:1257
__int32 kkint32
Definition: KKBaseTypes.h:88
const KKStr & GetNominalValue(kkint32 code) const
Returns the nominal value for the given ordinal value.
Definition: Attribute.cpp:143
kkuint32 NumOfFields() const
Definition: FileDesc.h:197
FileDescList * FileDescListPtr
Definition: FileDesc.h:41
GoalKeeper * GoalKeeperPtr
void AddAAttribute(const KKB::KKStr &_name, KKMLL::AttributeType _type, bool &alreadyExists)
Definition: FileDesc.cpp:169
XmlElement(XmlTagPtr _nameTag, XmlStream &s, RunLog &log)
Definition: XmlStream.cpp:758
MLClassPtr GetMLClassPtr(const KKStr &className)
Definition: FileDesc.cpp:298
KKMLL::AttributeType Type(kkint32 fieldNum) const
Definition: FileDesc.cpp:370
void AddANominalValue(const KKStr &attributeName, const KKStr &nominalValue, bool &alreadyExist, RunLog &log)
Definition: FileDesc.cpp:264
kkint32 GetNominalCode(const KKStr &nominalValue) const
Definition: Attribute.cpp:185
static void Destroy(volatile GoalKeeperPtr &_goalKeeperInstance)
Destroys an existing instance of GoalKeeper.
Definition: GoalKeeper.cpp:491
MLClassPtr LookUpUnKnownMLClass()
Definition: FileDesc.cpp:291
XmlElementFileDesc(XmlTagPtr tag, XmlStream &s, VolConstBool &cancelFlag, RunLog &log)
Definition: FileDesc.cpp:925
void ReadXML(XmlStream &s, XmlTagConstPtr tag, VolConstBool &cancelFlag, RunLog &log)
Definition: FileDesc.cpp:800
XmlElementAttributeList * XmlElementAttributeListPtr
Definition: Attribute.h:231
void SparseMinFeatureNum(kkint32 _sparseMinFeatureNum)
Definition: FileDesc.h:125
bool SameExceptForSymbolicData(const FileDesc &otherFd, RunLog &log) const
Definition: FileDesc.cpp:472
void AddAAttribute(const KKMLL::Attribute &attribute)
Definition: FileDesc.cpp:140
static void Create(const KKStr &_name, volatile GoalKeeperPtr &_newGoalKeeper)
Create a GoalKeeper object and avoid a race condition doing it.
Definition: GoalKeeper.cpp:346
void Version(kkint16 _version)
Definition: FileDesc.h:126
kkint32 MemoryConsumedEstimated() const
Definition: FileDesc.cpp:102
void AddClasses(const MLClassList &classesToAdd)
Definition: FileDesc.cpp:196
bool operator!=(const FileDesc &rightSize) const
Returns true if file description on the right size is NOT identical.
Definition: FileDesc.cpp:456
FileDesc * FileDescPtr
Definition: FileDesc.h:75
XmlToken * XmlTokenPtr
Definition: XmlStream.h:18
const KKStr & FieldName(kkint32 fieldNum) const
Definition: FileDesc.cpp:387
unsigned __int32 kkuint32
Definition: KKBaseTypes.h:89
bool operator==(const FileDesc &rightSize) const
Returns true if file description on the right size is identical.
Definition: FileDesc.cpp:443
MLClassPtr LookUpMLClassByName(const KKStr &className)
Definition: FileDesc.cpp:284
VectorInt32 CreateCardinalityTable() const
Definition: FileDesc.cpp:430
describes a single Feature, Type and possible values.
Definition: Attribute.h:74
kkint32 LookUpNominalCode(kkint32 fieldNum, const KKStr &nominalValue) const
Definition: FileDesc.cpp:321
static void FinalCleanUp()
Clean up function, call just before exiting the application.
Definition: FileDesc.cpp:57
Attribute * AttributePtr
Definition: Attribute.h:156
kkint32 FieldNum() const
Definition: Attribute.h:106
KKTHread * KKTHreadPtr
void AddAttributes(const KKMLL::AttributeList &attributes)
Definition: FileDesc.cpp:156
void AddANominalValue(kkint32 fieldNum, const KKStr &nominalValue, bool &alreadyExist, RunLog &log)
Definition: FileDesc.cpp:220
const KKStr & GetNominalValue(kkint32 fieldNum, kkint32 code) const
Definition: FileDesc.cpp:395
bool AllFieldsAreNumeric() const
Allows the user to quickly determine if there are no nominal fields.
Definition: FileDesc.cpp:706
void StartBlock()
Initiates a Block as long as another thread has not already locked this object.
Definition: GoalKeeper.cpp:214
XmlElement * XmlElementPtr
Definition: XmlStream.h:21
void AddAtribute(const KKStr &attributeName, const KKStr &attributeValue)
Definition: XmlStream.cpp:602
const KKStr & FileName() const
Definition: FileDesc.h:119
bool Empty() const
Definition: KKStr.h:241
XmlTag const * XmlTagConstPtr
Definition: KKStr.h:45
Manages the reading and writing of objects in a simple XML format. For a class to be supported by Xml...
Definition: XmlStream.h:46
MLClassListPtr Value() const
Definition: MLClass.cpp:1484
void EndBlock()
Ends the block and allows other threads to pass through StatBlock.
Definition: GoalKeeper.cpp:295
static KKStr Concat(const std::vector< std::string > &values)
Concatenates the list of &#39;std::string&#39; strings.
Definition: KKStr.cpp:1082
std::vector< kkint32 > VectorInt32
Vector of signed 32 bit integers.
Definition: KKBaseTypes.h:144
AttributeType
Definition: Attribute.h:36
void AddANominalValue(const KKStr &nominalValue, bool &alreadyExist, RunLog &log)
Definition: FileDesc.cpp:242
bool operator!=(const KKStr &right) const
Definition: KKStr.cpp:1558
virtual const KKStr & VarName() const
Definition: XmlStream.cpp:794
KKStr StrFormatInt(kkint32 val, const char *mask)
Definition: KKStr.cpp:5004
AttributeType Type() const
Definition: Attribute.h:133
std::ostream &__cdecl operator<<(std::ostream &os, const KKStr &str)
const KKMLL::AttributePtr * CreateAAttributeTable() const
Definition: FileDesc.cpp:408
virtual const KKStr & SectionName() const
Definition: XmlStream.cpp:785
static FileDescPtr NewContinuousDataOnly(VectorKKStr &_fieldNames)
Creates a simple FileDesc that consists of continuous data only.
Definition: FileDesc.cpp:116
kkint32 GetFieldNumFromAttributeName(const KKStr &attributeName) const
Definition: FileDesc.cpp:690
AttributeTypeVector CreateAttributeTypeTable() const
Definition: FileDesc.cpp:419
XmlElementKKStr * XmlElementKKStrPtr
Definition: XmlStream.h:670
void WriteXML(std::ostream &o)
Definition: XmlStream.cpp:723
static void WriteXML(const FileDesc &fileDesc, const KKStr &varName, std::ostream &o)
Definition: FileDesc.cpp:962
Used for logging messages.
Definition: RunLog.h:49
void EncodeProblem(const struct svm_paramater &param, struct svm_problem &prob_in, struct svm_problem &prob_out)
FileDescPtr TakeOwnership()
Definition: FileDesc.cpp:953
virtual TokenTypes TokenType()=0
FileDescPtr Value() const
Definition: FileDesc.cpp:947
virtual XmlTokenPtr GetNextToken(VolConstBool &cancelFlag, RunLog &log)
Definition: XmlStream.cpp:116
kkint32 Cardinality(kkint32 fieldNum) const
Definition: FileDesc.cpp:341
KKException(const KKStr &_exceptionStr)
Definition: KKException.cpp:45
Maintains a list of MLClass instances.
Definition: MLClass.h:233
void DisplayAttributeMappings()
Definition: FileDesc.cpp:617
kkint32 Cardinality() const
Returns back the cardinality of the attribute; the number of possible values it can take...
Definition: Attribute.cpp:173
FileDescList(bool _owner)
Definition: FileDesc.cpp:911
static FileDescPtr MergeSymbolicFields(const FileDesc &left, const FileDesc &right, RunLog &log)
Merges the Symbolic fields of two different &#39;FileDesc&#39; instances producing a new instance of &#39;FileDes...
Definition: FileDesc.cpp:723
Container class file &#39;FileDesc&#39; instances.
Definition: FileDesc.cpp:42
#define INT_MAX
Adapted by Kurt Kramer be a &#39;class&#39; definition so as to make it more usable in th ePices software wor...
Definition: UsfCasCor.h:186
void WriteXML(const KKStr &varName, std::ostream &o) const
Definition: FileDesc.cpp:875
#define XmlFactoryMacro(NameOfClass)
Definition: XmlStream.h:688
const KKMLL::Attribute & GetAAttribute(kkint32 fieldNum) const
Definition: FileDesc.cpp:210
XmlElementMLClassNameList * XmlElementMLClassNameListPtr
Definition: MLClass.h:603
volatile const bool VolConstBool
Definition: KKBaseTypes.h:163