Changeset 3998:74f0dd50c047 in orange


Ignore:
Timestamp:
07/19/07 13:15:02 (7 years ago)
Author:
janezd <janez.demsar@…>
Branch:
default
Convert:
c715e71f7714fe8d744fa7e7cb268378da5461b5
Message:
  • fixed a problem with wrong counting of number of decimals for continuous attributes
  • two attributes with the same name and type loaded from different files are now the same attribute
  • values of discrete attribtues loaded from files are now sorted alphabetically
  • attributes are constructed in scripts are different attributes, but there is a function getExisting, which returns an existing attribute, if it's there
  • pickling bugs, which caused the above changes, are presumably fixed
  • user-specified flags for loaders (dontCheckStored etc) are now treated inconsistently and have unknown effects
  • DomainDepots still exist
File:
1 edited

Legend:

Unmodified
Added
Removed
  • source/orange/vars.cpp

    r3451 r3998  
    2929#include <algorithm> 
    3030#include <queue> 
     31#include <list> 
    3132#include <float.h> 
    3233 
     
    4647DEFINE_TOrangeVector_classDescription(PVariable, "TVarList", true, ORANGE_API) 
    4748DEFINE_TOrangeVector_classDescription(PVarList, "TVarListList", true, ORANGE_API) 
     49 
     50list<TVariable *> TVariable::allVariables; 
     51 
     52 
     53const char *sortedDaNe[] = {"da", "ne", 0 }; 
     54const char *resortedDaNe[] = {"ne", "da", 0}; 
     55 
     56const char **specialSortCases[] = { sortedDaNe, 0}; 
     57const char **specialCasesResorted[] = { resortedDaNe, 0}; 
     58 
     59const char *putAtBeginning[] = {"no", "none", "absent", "normal", 0}; 
     60 
     61TVariable *TVariable::getExisting(const string &name, const int &varType, TStringList *fixedOrderValues, set<string> *values) 
     62{ 
     63  if ((fixedOrderValues && fixedOrderValues->size() ) && (varType != TValue::INTVAR)) 
     64    ::raiseErrorWho("Variable", "cannot specify the value list for non-discrete attributes"); 
     65     
     66  TVariable *var = NULL; 
     67   
     68  ITERATE(list<TVariable *>, vi, TVariable::allVariables) 
     69    if (((*vi)->varType == varType) && ((*vi)->name == name)) { 
     70      var = *vi; 
     71      break; 
     72    } 
     73     
     74  TEnumVariable *evar = dynamic_cast<TEnumVariable *>(var); 
     75  if (evar) {  
     76    if (fixedOrderValues) { 
     77      if (!evar->checkValuesOrder(*fixedOrderValues)) 
     78        ::raiseErrorWho("Variable", "a discrete variable named '%s' already exists, but with different order of values", name.c_str()); 
     79      const_PITERATE(TStringList, si, fixedOrderValues) 
     80        evar->addValue(*si); 
     81    } 
     82       
     83    if (values) { 
     84      vector<string> sorted; 
     85      TEnumVariable::presortValues(*values, sorted); 
     86      const_ITERATE(vector<string>, ssi, sorted) 
     87        evar->addValue(*ssi); 
     88    } 
     89  } 
     90   
     91  return var; 
     92} 
    4893 
    4994 
     
    403448 
    404449 
     450bool TEnumVariable::checkValuesOrder(const TStringList &refValues) 
     451{ 
     452  for(TStringList::const_iterator ni(refValues.begin()), ne(refValues.end()), ei(values->begin()), ee(values->end());  
     453      (ei != ee) && (ni != ne); ei++, ni++) 
     454    if (*ei != *ni) 
     455      return false; 
     456  return true; 
     457} 
     458 
     459 
     460void TEnumVariable::presortValues(const set<string> &unsorted, vector<string> &sorted) 
     461{ 
     462  sorted.clear(); 
     463  sorted.insert(sorted.begin(), unsorted.begin(), unsorted.end()); 
     464   
     465  vector<string>::iterator si, se(sorted.end()); 
     466  const char ***ssi, **ssii, ***rssi; 
     467  for(ssi = specialSortCases, rssi = specialCasesResorted; *ssi; ssi++, rssi++) { 
     468    for(si = sorted.begin(), ssii = *ssi; *ssii && (si != se) && !_stricmp(*ssii, si->c_str()); *ssii++); 
     469    if (!*ssii && (si==se)) { 
     470      sorted.clear(); 
     471      sorted.insert(sorted.begin(), *rssi, *rssi + (ssii - *ssi)); 
     472      return; 
     473    } 
     474  } 
     475   
     476  se = sorted.end(); 
     477  for(ssii = putAtBeginning; *ssii; ssii++) { 
     478    for(si = sorted.begin(); (si != se) && _stricmp(*ssii, si->c_str()); si++); 
     479    if (si != se) { 
     480      const string toMove = *si; 
     481      sorted.erase(si); 
     482      sorted.insert(sorted.begin(), toMove); 
     483      break; 
     484    } 
     485  } 
     486} 
     487 
    405488 
    406489TIntVariable::TIntVariable() 
     
    544627{ 
    545628  const char *valsi; 
    546   for(valsi = vals; *valsi && ((*valsi<'0') || (*valsi>'9')); valsi++); 
     629  for(valsi = vals; *valsi && ((*valsi<'0') || (*valsi>'9')) && (*valsi != '.'); valsi++); 
    547630  if (!*valsi) 
    548631    return -1; 
Note: See TracChangeset for help on using the changeset viewer.