GClasses
GClasses::GArffRelation Class Reference

Detailed Description

ARFF = Attribute-Relation File Format. This stores richer information than GRelation. This includes a name, a name for each attribute, and names for each supported nominal value.

#include <GMatrix.h>

Inheritance diagram for GClasses::GArffRelation:
GClasses::GMixedRelation GClasses::GRelation

Public Member Functions

 GArffRelation ()
 General-purpose constructor. More...
 
 GArffRelation (const GDomNode *pNode)
 Deserializing constructor. More...
 
virtual ~GArffRelation ()
 
void addAttribute (const char *szName, size_t nValues, std::vector< const char * > *pValues)
 Adds a new attribute (column) to the relation. More...
 
int addAttrValue (size_t nAttr, const char *szValue)
 Adds a new possible value to a nominal attribute. Returns the numerical form of the new value. More...
 
const char * attrName (size_t nAttr) const
 Returns the name of the attribute with index nAttr. More...
 
virtual std::string attrNameStr (std::size_t nAttr) const
 Returns the name of the attribute with index nAttr as a standard string object or "" if the atribute has no name. More...
 
virtual GRelationclone () const
 Returns a deep copy of this object. More...
 
virtual GRelationcloneMinimal () const
 Returns a relation containing the same value counts as this object, but not containing superfluous things, such as human-readable strings. (The returned relation will be of a different type.) More...
 
virtual GRelationcloneSub (size_t start, size_t count) const
 Makes a deep copy of the specified subset of this relation. More...
 
virtual void copyAttr (const GRelation *pThat, size_t nAttr)
 Adds a copy of the specified attribute to this relation. More...
 
virtual void deleteAttributes (size_t nAttr, size_t count)
 Deletes an attribute. More...
 
void dropValue (size_t attr, int val)
 Drops the specified value from the list of possible values. (Swaps the last value in to fill its slot.) More...
 
int findEnumeratedValue (size_t nAttr, const char *szValue) const
 Returns the nominal index for the specified attribute with the given value. More...
 
virtual void flush ()
 Deletes all the attributes. More...
 
virtual bool isCompatible (const GRelation &that) const
 Returns true iff the attributes in both relations have the same names, the same number of values, and the names of those values all match. (Empty strings are considered to match everything.) More...
 
const char * name () const
 Returns the name of the relation. More...
 
void parseAttribute (GArffTokenizer &tok)
 Parses the meta-data for an attribute. More...
 
double parseValue (size_t attr, const char *val)
 Parses a value. More...
 
virtual void printAttrName (std::ostream &stream, size_t column) const
 Prints the specified attribute name to a stream. More...
 
virtual void printAttrValue (std::ostream &stream, size_t column, double value, const char *missing="?") const
 Prints the specified value to a stream. More...
 
virtual GDomNodeserialize (GDom *pDoc) const
 Marshalls this object to a DOM, which can be saved to a variety of serial formats. More...
 
void setAttrName (size_t attr, const char *szNewName)
 Sets the name of the specified attribute. More...
 
virtual void setAttrValueCount (size_t nAttr, size_t nValues)
 Sets the number of values for the specified attribute. More...
 
void setName (const char *szName)
 Sets the name of this relation. More...
 
virtual void swapAttributes (size_t nAttr1, size_t nAttr2)
 Swaps two columns. More...
 
virtual RelationType type () const
 Returns the type of relation. More...
 
- Public Member Functions inherited from GClasses::GMixedRelation
 GMixedRelation ()
 Makes an empty relation. More...
 
 GMixedRelation (std::vector< size_t > &attrValues)
 Construct a mixed relation. attrValues specifies the number of nominal values in each attribute (column), or 0 for continuous attributes. More...
 
 GMixedRelation (const GDomNode *pNode)
 Loads from a DOM. More...
 
 GMixedRelation (const GRelation *pCopyMe)
 Makes a copy of pCopyMe. More...
 
 GMixedRelation (const GRelation *pCopyMe, size_t firstAttr, size_t attrCount)
 Makes a copy of the specified range of pCopyMe. More...
 
virtual ~GMixedRelation ()
 
void addAttr (size_t nValues)
 If nValues is zero, adds a real attribute. If nValues is

0, adds an attribute with "nValues" nominal values

More...
 
void addAttrs (size_t attrCount, size_t valueCount)
 Adds "attrCount" new attributes, each with "valueCount" values. (Use valueCount=0 for continuous attributes.) More...
 
void addAttrs (const GRelation &copyMe, size_t firstAttr=0, size_t attrCount=INVALID_INDEX)
 Copies the specified attributes and adds them to this relation. If attrCount < 0, then it will copy all attributes from firstAttr to the end. More...
 
virtual bool areContinuous (size_t first=0, size_t count=INVALID_INDEX) const
 Returns true iff all attributes in the specified range are continuous. More...
 
virtual bool areNominal (size_t first=0, size_t count=INVALID_INDEX) const
 Returns true iff all attributes in the specified range are nominal. More...
 
void copy (const GRelation *pCopyMe)
 Flushes this relation and then copies all of the attributes from pCopyMe. More...
 
virtual size_t size () const
 Returns the total number of attributes in this relation. More...
 
virtual size_t valueCount (size_t nAttr) const
 Returns the number of nominal values in the specified attribute. More...
 
- Public Member Functions inherited from GClasses::GRelation
 GRelation ()
 
virtual ~GRelation ()
 
void print (std::ostream &stream) const
 Prints this relation in ARFF format to the specified stream. More...
 
void printRow (std::ostream &stream, const double *pRow, char separator= ',', const char *missing="?") const
 Print a single row of data in ARFF format. More...
 
void save (const GMatrix *pData, const char *szFilename) const
 Saves to a file. More...
 

Protected Attributes

std::vector< GArffAttributem_attrs
 
std::string m_name
 
- Protected Attributes inherited from GClasses::GMixedRelation
std::vector< size_t > m_valueCounts
 

Friends

class GMatrix
 

Additional Inherited Members

- Public Types inherited from GClasses::GRelation
- Static Public Member Functions inherited from GClasses::GRelation
static GRelationdeserialize (const GDomNode *pNode)
 Load from a DOM. More...
 
static void test ()
 Performs unit tests for this class. Throws an exception if there is a failure. More...
 

Constructor & Destructor Documentation

GClasses::GArffRelation::GArffRelation ( )

General-purpose constructor.

GClasses::GArffRelation::GArffRelation ( const GDomNode pNode)

Deserializing constructor.

virtual GClasses::GArffRelation::~GArffRelation ( )
virtual

Member Function Documentation

void GClasses::GArffRelation::addAttribute ( const char *  szName,
size_t  nValues,
std::vector< const char * > *  pValues 
)

Adds a new attribute (column) to the relation.

int GClasses::GArffRelation::addAttrValue ( size_t  nAttr,
const char *  szValue 
)

Adds a new possible value to a nominal attribute. Returns the numerical form of the new value.

const char* GClasses::GArffRelation::attrName ( size_t  nAttr) const

Returns the name of the attribute with index nAttr.

Parameters
nAttrthe index of the attribute whose name is returned
Returns
the name of the attribute with index nAttr as a standard string object or "" if the atribute has no name
virtual std::string GClasses::GArffRelation::attrNameStr ( std::size_t  nAttr) const
inlinevirtual

Returns the name of the attribute with index nAttr as a standard string object or "" if the atribute has no name.

Parameters
nAttrthe index of the attribute whose name is returned
Returns
the name of the attribute with index nAttr as a standard string object or "" if the atribute has no name

Reimplemented from GClasses::GRelation.

virtual GRelation* GClasses::GArffRelation::clone ( ) const
virtual

Returns a deep copy of this object.

Reimplemented from GClasses::GMixedRelation.

virtual GRelation* GClasses::GArffRelation::cloneMinimal ( ) const
virtual

Returns a relation containing the same value counts as this object, but not containing superfluous things, such as human-readable strings. (The returned relation will be of a different type.)

Reimplemented from GClasses::GMixedRelation.

virtual GRelation* GClasses::GArffRelation::cloneSub ( size_t  start,
size_t  count 
) const
virtual

Makes a deep copy of the specified subset of this relation.

Reimplemented from GClasses::GMixedRelation.

virtual void GClasses::GArffRelation::copyAttr ( const GRelation pThat,
size_t  nAttr 
)
virtual

Adds a copy of the specified attribute to this relation.

Reimplemented from GClasses::GMixedRelation.

virtual void GClasses::GArffRelation::deleteAttributes ( size_t  nAttr,
size_t  count 
)
virtual

Deletes an attribute.

Reimplemented from GClasses::GMixedRelation.

void GClasses::GArffRelation::dropValue ( size_t  attr,
int  val 
)

Drops the specified value from the list of possible values. (Swaps the last value in to fill its slot.)

int GClasses::GArffRelation::findEnumeratedValue ( size_t  nAttr,
const char *  szValue 
) const

Returns the nominal index for the specified attribute with the given value.

virtual void GClasses::GArffRelation::flush ( )
virtual

Deletes all the attributes.

Reimplemented from GClasses::GMixedRelation.

virtual bool GClasses::GArffRelation::isCompatible ( const GRelation that) const
virtual

Returns true iff the attributes in both relations have the same names, the same number of values, and the names of those values all match. (Empty strings are considered to match everything.)

Reimplemented from GClasses::GRelation.

const char* GClasses::GArffRelation::name ( ) const
inline

Returns the name of the relation.

void GClasses::GArffRelation::parseAttribute ( GArffTokenizer &  tok)

Parses the meta-data for an attribute.

double GClasses::GArffRelation::parseValue ( size_t  attr,
const char *  val 
)

Parses a value.

virtual void GClasses::GArffRelation::printAttrName ( std::ostream &  stream,
size_t  column 
) const
virtual

Prints the specified attribute name to a stream.

Reimplemented from GClasses::GRelation.

virtual void GClasses::GArffRelation::printAttrValue ( std::ostream &  stream,
size_t  column,
double  value,
const char *  missing = "?" 
) const
virtual

Prints the specified value to a stream.

Reimplemented from GClasses::GRelation.

virtual GDomNode* GClasses::GArffRelation::serialize ( GDom pDoc) const
virtual

Marshalls this object to a DOM, which can be saved to a variety of serial formats.

Reimplemented from GClasses::GMixedRelation.

void GClasses::GArffRelation::setAttrName ( size_t  attr,
const char *  szNewName 
)

Sets the name of the specified attribute.

virtual void GClasses::GArffRelation::setAttrValueCount ( size_t  nAttr,
size_t  nValues 
)
virtual

Sets the number of values for the specified attribute.

Reimplemented from GClasses::GMixedRelation.

void GClasses::GArffRelation::setName ( const char *  szName)

Sets the name of this relation.

virtual void GClasses::GArffRelation::swapAttributes ( size_t  nAttr1,
size_t  nAttr2 
)
virtual

Swaps two columns.

Reimplemented from GClasses::GMixedRelation.

virtual RelationType GClasses::GArffRelation::type ( ) const
inlinevirtual

Returns the type of relation.

Reimplemented from GClasses::GMixedRelation.

Friends And Related Function Documentation

friend class GMatrix
friend

Member Data Documentation

std::vector<GArffAttribute> GClasses::GArffRelation::m_attrs
protected
std::string GClasses::GArffRelation::m_name
protected