Esempio n. 1
0
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
bool CTDPartition::genRecords(CTDPartition*  pParentPartition,
                              CTDAttrib*     pSplitAttrib, 
                              CTDConcept*    pSplitConcept,
							  CTDAttribs*    pAttribs,
							  int			 childInd)
{
	m_genRecords.cleanup();
	int nAttribs = pAttribs->GetSize();
	int splitIdx = pSplitAttrib->m_attribIdx;

	for (int classInd = 0; classInd < m_nClasses; ++classInd){

		CTDAttrib* pAttrib = NULL;
		CTDValue* pNewValue = NULL;
		CTDRecord* pNewRecord = new CTDRecord(); 
		
		for (int attribID = 0; attribID < nAttribs; ++attribID){
	
			pNewValue = NULL;
			pAttrib = pAttribs->GetAt(attribID);

			if (pAttrib->isContinuous())
				pNewValue = new CTDNumericValue(-1.0);
			else
	            pNewValue = new CTDStringValue();

			if (!pNewValue) {
				ASSERT(false);
  				return false;
			}

	
			if (attribID == pAttribs->GetSize() - 1) {
				// Class attribute
				if (!pNewValue->assignGenClassValue(pAttrib, classInd))
					return false;
			}
			else if(attribID == splitIdx) {
				//split attribute
				if (!pNewValue->setSplitCurConcept(pSplitConcept, childInd))
					return false;	
			}

			else 
			{	// Other attributes
				// Initialize the current concept to the root concept. 
				if (!pNewValue->setCurConcept(pParentPartition->getGenRecords()->GetAt(0)->getValue(attribID)->getCurrentConcept()))
						return false;	
			}

			// Add the value to the record.
			if (!pNewRecord->addValue(pNewValue))
				return false;

		}    

		if (pNewRecord){
			pNewRecord->setRecordID(m_genRecords.Add(pNewRecord));
		}

	}
	if (m_genRecords.GetSize() != m_nClasses) {
		cerr << _T("CTDPartition::initGenRecords: Number of generalized record is not current.") << endl;
        return false;
    }

	 return true;
}