⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vars.hpp

📁 orange源码 数据挖掘技术
💻 HPP
字号:
/*
    This file is part of Orange.

    Orange is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    Orange is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Orange; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

    Authors: Janez Demsar, Blaz Zupan, 1996--2002
    Contact: janez.demsar@fri.uni-lj.si
*/


#ifndef __VARS_HPP
#define __VARS_HPP

#include <string>
#include "orvector.hpp"

using namespace std;

#include "root.hpp"

class ORANGE_API TValue;
class ORANGE_API TExample;
class ORANGE_API TTransformValue;
class ORANGE_API TDistribution;

WRAPPER(Domain);
WRAPPER(ExampleGenerator)
WRAPPER(Classifier);
WRAPPER(RandomGenerator)

//#include "getarg.hpp"
#include "stladdon.hpp"

#ifdef _MSC_VER
 #pragma warning (disable : 4786 4114 4018 4267 4251)
#endif

WRAPPER(Variable);
WRAPPER(Classifier)


class ORANGE_API TVariable : public TOrange {
public:
  __REGISTER_ABSTRACT_CLASS

  string name; //P variable's name
  int  varType; //P variable type
  bool ordered; //P variable values are ordered
  bool distributed; //P variable values are distributions

  PRandomGenerator randomGenerator; //P random generator for random values (initialized when first needed)

  PVariable sourceVariable; //P The attribute that this attribute is computed from (when applicable)
  PClassifier getValueFrom; //P Function to compute the value from values of other variables
  bool getValueFromLocked;

protected:
  TValue DC_value;
  TValue DK_value;

public:
  TVariable(const int &avarType=TValue::NONE, const bool &ordered = false);
  TVariable(const string &aname, const int &avarType=TValue::NONE, const bool &ordered = false);

  virtual const TValue &DC() const;
  virtual const TValue &DK() const;
  virtual TValue specialValue(int) const;

  bool str2special(const string &valname, TValue &valu) const;  // Those two functions convert ? to DK, ~ to DC and vice-versa
  bool special2str(const TValue &val, string &str) const;

  virtual void val2str(const TValue &val, string &str) const =0;
  virtual void str2val(const string &valname, TValue &valu) =0;
  virtual bool str2val_try(const string &valname, TValue &valu);
  virtual void str2val_add(const string &valname, TValue &valu);

  virtual void val2filestr(const TValue &val, string &str, const TExample &) const;
  virtual void filestr2val(const string &valname, TValue &valu, TExample &);

  virtual bool   firstValue(TValue &val) const;
  virtual bool   nextValue(TValue &val) const;
  virtual TValue randomValue(const int &rand=-1);

  // Returns the number of different values, -1 if it cannot be done (for example, if variable is continuous)
  virtual int  noOfValues() const =0;

  virtual TValue computeValue(const TExample &);
};

WRAPPER(Variable)

#define TVarList TOrangeVector<PVariable> 
VWRAPPER(VarList)

#define TVarListList TOrangeVector<PVarList> 
VWRAPPER(VarListList)

class ORANGE_API TEnumVariable : public TVariable {
public:
  __REGISTER_CLASS

  PStringList values; //P attribute's values
  int baseValue;      //P the index of the base value

  TEnumVariable();
  TEnumVariable(const string &aname);
  TEnumVariable(const string &aname, PStringList val);
  TEnumVariable(const TEnumVariable &);

  void addValue(const string &);

  virtual bool   firstValue(TValue &val) const;
  virtual bool   nextValue(TValue &val) const;
  virtual TValue randomValue(const int &rand=-1);

  virtual int  noOfValues() const;

  virtual void val2str(const TValue &val, string &str) const;
  virtual void str2val(const string &valname, TValue &valu);
  virtual bool str2val_try(const string &valname, TValue &valu);
  virtual void str2val_add(const string &valname, TValue &valu);

private:
  map<string, int> valuesTree;
  void createValuesTree();
};


// A class describing integer variables
class ORANGE_API TIntVariable : public TVariable {
public:
  __REGISTER_CLASS

  int startValue; //P lowest value
  int endValue;   //P highest value

  TIntVariable();
  TIntVariable(const string &aname);

  virtual bool   firstValue(TValue &val) const;
  virtual bool   nextValue(TValue &val) const;
  virtual TValue randomValue(const int &rand=-1);

  virtual int noOfValues() const;

  virtual void val2str(const TValue &val, string &str) const;
  virtual void str2val(const string &valname, TValue &valu);
  virtual bool str2val_try(const string &valname, TValue &valu);
};



class ORANGE_API TFloatVariable : public TVariable {
public:
  __REGISTER_CLASS

  float startValue; //P lowest value
  float endValue;   //P highest value
  float stepValue;  //P step
  
  int numberOfDecimals; //P number of digits after decimal point
  bool scientificFormat; //P use scientific format in output
  int adjustDecimals; //P adjust number of decimals according to the values converted (0 - no, 1 - yes, 2 - yes, but haven't seen any yet)

  TFloatVariable();
  TFloatVariable(const string &aname);

  virtual bool   firstValue(TValue &val) const;
  virtual bool   nextValue(TValue &val) const;
  virtual TValue randomValue(const int &rand=-1);

  virtual int  noOfValues() const;
 
  virtual void val2str(const TValue &val, string &str) const;
  virtual void str2val(const string &valname, TValue &valu);
  virtual bool str2val_try(const string &valname, TValue &valu);
  int str2val_low(const string &valname, TValue &valu);
};

#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -