Version: 8.3.0
General methods

Functions

PMMLLIB_EXPORT PMMLlib::PMMLlib::PMMLlib (std::string file, bool log=false)
 
PMMLLIB_EXPORT PMMLlib::PMMLlib::PMMLlib (bool log=false)
 This constructor is mandatory for Swig because it can be used with no parameters. More...
 
PMMLLIB_EXPORT PMMLlib::PMMLlib::~PMMLlib ()
 
PMMLLIB_EXPORT void PMMLlib::PMMLlib::SetCurrentModel (std::string modelName, PMMLType type)
 
PMMLLIB_EXPORT void PMMLlib::PMMLlib::SetCurrentModel (std::string modelName)
 Throw an exception if there is no model or more than one model with name "modelName" in the PMML file. More...
 
PMMLLIB_EXPORT void PMMLlib::PMMLlib::SetCurrentModel ()
 Throw an exception if no model is found or if there are more than one model in the PMLL file. More...
 
PMMLLIB_EXPORT std::string PMMLlib::PMMLlib::makeLog () const
 
PMMLLIB_EXPORT void PMMLlib::PMMLlib::printLog () const
 
PMMLLIB_EXPORT void PMMLlib::PMMLlib::AddDataField (std::string name, std::string displayName, std::string optype, std::string dataType, std::string closure, double leftMargin, double rightMargin, bool interval=false)
 
PMMLLIB_EXPORT void PMMLlib::PMMLlib::AddMiningSchema (std::string name, std::string usageType)
 Common to all models. More...
 
PMMLLIB_EXPORT void PMMLlib::PMMLlib::SetHeader (std::string copyright, std::string description, std::string appName, std::string appVersion, std::string annotation)
 
PMMLLIB_EXPORT void PMMLlib::PMMLlib::UnlinkNode ()
 
PMMLLIB_EXPORT void PMMLlib::PMMLlib::BackupNode ()
 
PMMLLIB_EXPORT int PMMLlib::PMMLlib::GetModelsNb ()
 
PMMLLIB_EXPORT void PMMLlib::PMMLlib::Write ()
 
PMMLLIB_EXPORT void PMMLlib::PMMLlib::Write (std::string file)
 
PMMLLIB_EXPORT PMMLType PMMLlib::PMMLlib::GetCurrentModelType ()
 type is kUNDEFINED if no model is set or if model type is not handled More...
 
PMMLLIB_EXPORT std::string PMMLlib::PMMLlib::GetCurrentModelName ()
 name is "" if no model is set More...
 
xmlNodePtr PMMLlib::PMMLlib::GetChildByName (xmlNodePtr node, std::string nodename)
 
xmlNodePtr PMMLlib::PMMLlib::GetPtr (int ann_index, std::string name)
 
xmlNodePtr PMMLlib::PMMLlib::GetPtr (std::string ann_name, std::string name)
 
void PMMLlib::PMMLlib::CountModels ()
 
int PMMLlib::PMMLlib::CountNeuralNetModels ()
 
int PMMLlib::PMMLlib::CountRegressionModels ()
 
void PMMLlib::PMMLlib::SetRootNode ()
 
std::string PMMLlib::PMMLlib::GetModelName (xmlNodePtr node)
 
std::string PMMLlib::PMMLlib::GetTypeString ()
 

Detailed Description

Common methods to all kinds of PMML files and models

Function Documentation

void PMMLlib::PMMLlib::AddDataField ( std::string  fieldName,
std::string  displayName,
std::string  optype,
std::string  dataType,
std::string  closure,
double  leftMargin,
double  rightMargin,
bool  interval = false 
)

Add a DataField node to the DataDictionnary node

Parameters
fieldNameValue of property "name"
displayNameValue of property "displayName"
optypeValue of property "optype"
dataTypeValue of property "dataType"
closureValue of property "closure" in node Interval
leftMarginValue of property "leftMargin" in node Interval
rightMarginValue of property "rightMargin" in node Interval
intervalFlag to add a node Interval (if true)

Definition at line 1318 of file PMMLlib.cxx.

References PMMLlib::PMMLlib::_rootNode, and PMMLlib::PMMLlib::GetChildByName().

1326 {
1327  // if 'DataDictionary' node does not exist, create it
1328  xmlNodePtr dataDictNode = GetChildByName(_rootNode, "DataDictionary");
1329  if(!dataDictNode)
1330  {
1331  dataDictNode = xmlNewChild(_rootNode, 0, (const xmlChar*)"DataDictionary", 0);
1332  }
1333 
1334  // then append the node
1335  xmlNodePtr dataFieldNode = xmlNewChild(dataDictNode, 0, (const xmlChar*)"DataField", 0);
1336  xmlNewProp(dataFieldNode, (const xmlChar*)"name", (const xmlChar*)(fieldName.c_str()) );
1337  xmlNewProp(dataFieldNode, (const xmlChar*)"displayName", (const xmlChar*)(displayName.c_str()) );
1338  xmlNewProp(dataFieldNode, (const xmlChar*)"optype", (const xmlChar*)(optype.c_str()) );
1339  xmlNewProp(dataFieldNode, (const xmlChar*)"dataType", (const xmlChar*)(dataType.c_str()) );
1340 
1341  if ( interval )
1342  {
1343  xmlNodePtr intervalNode = xmlNewChild(dataFieldNode, 0, (const xmlChar*)"Interval", 0);
1344  xmlNewProp(intervalNode, (const xmlChar*)"closure", (const xmlChar*)(closure.c_str()) );
1345  stringstream ss;
1346  ss << scientific << leftMargin;
1347  xmlNewProp(intervalNode, (const xmlChar*)"leftMargin", (const xmlChar*)(ss.str().c_str()) );
1348  ss.str("");
1349  ss << scientific << rightMargin;
1350  xmlNewProp(intervalNode, (const xmlChar*)"rightMargin", (const xmlChar*)(ss.str().c_str()) );
1351  }
1352 }
void PMMLlib::PMMLlib::AddMiningSchema ( std::string  name,
std::string  usageType 
)

Common to all models.

Add the MiningSchema node.

Parameters
nameValue of property "name".
usageTypeValue of property "usageType".

Definition at line 287 of file PMMLlib.cxx.

References PMMLlib::PMMLlib::_currentModelNode, and PMMLlib::PMMLlib::GetChildByName().

289 {
290  xmlNodePtr netNode = _currentModelNode;
291 
292  // if 'MiningSchema' node does not exist, create it
293  xmlNodePtr miningSchemaNode = GetChildByName(netNode, "MiningSchema");
294  if(!miningSchemaNode)
295  {
296  miningSchemaNode = xmlNewChild(netNode, 0, (const xmlChar*)"MiningSchema", 0);
297  }
298 
299  // then append the node
300  xmlNodePtr miningFieldNode = xmlNewChild(miningSchemaNode, 0, (const xmlChar*)"MiningField", 0);
301  xmlNewProp(miningFieldNode, (const xmlChar*)"name", (const xmlChar*)(name.c_str()) );
302  xmlNewProp(miningFieldNode, (const xmlChar*)"usageType", (const xmlChar*)(usageType.c_str()) );
303 }
void PMMLlib::PMMLlib::BackupNode ( )

Make a backup of the current model node.

Definition at line 536 of file PMMLlib.cxx.

References PMMLlib::PMMLlib::_currentModelName, PMMLlib::PMMLlib::_currentModelNode, PMMLlib::PMMLlib::_log, PMMLlib::PMMLlib::GetPtr(), and PMMLlib::PMMLlib::GetTypeString().

537 {
538  // Node name depending of PMML type
539  string name = GetTypeString();
540  // Find the last save index number
541  int nCrtIndex = 0;
542  stringstream ss;
543  ss << _currentModelName << "_" << nCrtIndex;
544  xmlNodePtr ptr = GetPtr(ss.str(), name);
545  while( ptr )
546  {
547  nCrtIndex++;
548  if (_log)
549  cout << " ** nCrtIndex[" << nCrtIndex << "]" << endl;
550 
551  ss.str("");
552  ss << _currentModelName << "_" << nCrtIndex;
553  ptr = GetPtr(ss.str(), name);
554  }
555  if(_log)
556  cout << " *** Node \"" << _currentModelName << "\" found, then backup it with index [" << nCrtIndex << "]" << endl;
557  // Rename model
558  xmlUnsetProp(_currentModelNode, (const xmlChar*)"modelName");
559  xmlNewProp(_currentModelNode, (const xmlChar*)"modelName", (const xmlChar*)(ss.str().c_str()));
560 }
void PMMLlib::PMMLlib::CountModels ( )
private

Count the tags of all types of models (NeuralNetwork and RegressionModel).

Returns
Number of models

Definition at line 342 of file PMMLlib.cxx.

References PMMLlib::PMMLlib::_log, PMMLlib::PMMLlib::_nbModels, PMMLlib::PMMLlib::CountNeuralNetModels(), and PMMLlib::PMMLlib::CountRegressionModels().

Referenced by PMMLlib::PMMLlib::PMMLlib(), and PMMLlib::PMMLlib::Write().

343 {
344  int nCount = 0;
346  if ( _log)
347  cout << " ** End Of Count Models nCount[" << nCount << "]" << endl;
348  _nbModels = nCount ;
349 }
int PMMLlib::PMMLlib::CountNeuralNetModels ( )
private

Count NeuralNetwork models tags in the PMML file.

Returns
Number of models

Definition at line 355 of file PMMLlib.cxx.

References PMMLlib::PMMLlib::_log, PMMLlib::PMMLlib::_rootNode, PMMLlib::PMMLlib::_xmlCharToString(), and PMMLlib::PMMLlib::GetChildByName().

Referenced by PMMLlib::PMMLlib::CountModels().

356 {
357  int nCount = 0;
358  xmlNodePtr ptr = GetChildByName(_rootNode,"NeuralNetwork");
359  // Count the models
360  while (ptr != NULL && _xmlCharToString(ptr->name) == "NeuralNetwork")
361  {
362  nCount++;
363  if (_log)
364  cout << " ** nCount[" << nCount << "]" << endl;
365  ptr = ptr->next;
366  }
367  if ( _log)
368  cout << " ** End Of CountNetworks nCount[" << nCount << "]" << endl;
369  return nCount;
370 }
int PMMLlib::PMMLlib::CountRegressionModels ( )
private

Count RegressionModel models tags in the PMML file.

Returns
Number of models

Definition at line 376 of file PMMLlib.cxx.

References PMMLlib::PMMLlib::_log, PMMLlib::PMMLlib::_rootNode, PMMLlib::PMMLlib::_xmlCharToString(), and PMMLlib::PMMLlib::GetChildByName().

Referenced by PMMLlib::PMMLlib::CountModels().

377 {
378  int nCount = 0;
379  xmlNodePtr ptr = GetChildByName(_rootNode,"RegressionModel");
380  // Count the models
381  while (ptr != NULL && _xmlCharToString(ptr->name) == "RegressionModel")
382  {
383  nCount++;
384  if (_log)
385  cout << " ** nCount[" << nCount << "]" << endl;
386  ptr = ptr->next;
387  }
388  if ( _log)
389  cout << " ** End Of CountRegressions nCount[" << nCount << "]" << endl;
390  return nCount;
391 }
xmlNodePtr PMMLlib::PMMLlib::GetChildByName ( xmlNodePtr  node,
std::string  nodeName 
)
private

Get the child of a node from the name of this node

Parameters
nodeStart node for the research
nodeNameName of the node to find
Returns
Pointer to the node found

Definition at line 311 of file PMMLlib.cxx.

References PMMLlib::PMMLlib::_xmlCharToString().

Referenced by PMMLlib::PMMLlib::AddDataField(), PMMLlib::PMMLlib::AddMiningSchema(), PMMLlib::PMMLlib::AddNeuralInput(), PMMLlib::PMMLlib::AddNeuralOutput(), PMMLlib::PMMLlib::CountNeuralNetModels(), PMMLlib::PMMLlib::CountRegressionModels(), PMMLlib::PMMLlib::fillVectorsForExport(), PMMLlib::PMMLlib::GetNameInput(), PMMLlib::PMMLlib::GetNameOutput(), PMMLlib::PMMLlib::GetNbHiddenLayers(), PMMLlib::PMMLlib::GetNbInputs(), PMMLlib::PMMLlib::GetNbNeuronsAtLayer(), PMMLlib::PMMLlib::GetNbOutputs(), PMMLlib::PMMLlib::GetNeuronBias(), PMMLlib::PMMLlib::GetNormalisationInput(), PMMLlib::PMMLlib::GetNormalisationOutput(), PMMLlib::PMMLlib::GetNormalizationType(), PMMLlib::PMMLlib::GetNumericPredictorCoefficient(), PMMLlib::PMMLlib::GetNumericPredictorName(), PMMLlib::PMMLlib::GetNumericPredictorNb(), PMMLlib::PMMLlib::GetPrecNeuronSynapse(), PMMLlib::PMMLlib::GetPredictorTermCoefficient(), PMMLlib::PMMLlib::GetPredictorTermFieldRefName(), PMMLlib::PMMLlib::GetPredictorTermFieldRefNb(), PMMLlib::PMMLlib::GetPredictorTermName(), PMMLlib::PMMLlib::GetPredictorTermNb(), PMMLlib::PMMLlib::GetPtr(), PMMLlib::PMMLlib::GetRegressionTableIntercept(), PMMLlib::PMMLlib::HasIntercept(), PMMLlib::PMMLlib::ReadNetworkStructure(), PMMLlib::PMMLlib::ReadRegressionStructure(), PMMLlib::PMMLlib::SetCurrentModel(), and PMMLlib::PMMLlib::SetNeuralNetName().

313 {
314  if ( node == NULL )
315  return node;
316 
317  xmlNodePtr childNode = node->children;
318  if ( childNode == NULL )
319  return childNode;
320 
321  const xmlChar* name = childNode->name;
322  string strName("");
323  if ( name != NULL )
324  strName = _xmlCharToString(name);
325 
326  while( (childNode != NULL) && (strName != nodeName) )
327  {
328  childNode = childNode->next;
329  if ( childNode == NULL )
330  return childNode;
331  name = childNode->name;
332  if ( name != NULL )
333  strName = _xmlCharToString(name);
334  }
335  return childNode;
336 }
std::string PMMLlib::PMMLlib::GetCurrentModelName ( )

name is "" if no model is set

Get the current model name.

Returns
the type

Definition at line 515 of file PMMLlib.cxx.

References PMMLlib::PMMLlib::_currentModelNode, and PMMLlib::PMMLlib::_getProp().

516 {
517  if ( ! _currentModelNode )
518  return string("");
519  string name = _getProp(_currentModelNode, string("modelName"));
520  return name;
521 }
PMMLType PMMLlib::PMMLlib::GetCurrentModelType ( )

type is kUNDEFINED if no model is set or if model type is not handled

Get the current model type.

Returns
the type

Definition at line 497 of file PMMLlib.cxx.

References PMMLlib::PMMLlib::_currentModelNode, PMMLlib::PMMLlib::_xmlCharToString(), PMMLlib::kANN, PMMLlib::kLR, and PMMLlib::kUNDEFINED.

Referenced by PMMLlib::PMMLlib::SetCurrentModel().

498 {
499  PMMLType type = kUNDEFINED ;
500  if ( ! _currentModelNode )
501  return type;
502  string name = _xmlCharToString(_currentModelNode->name);
503  if ( name == "NeuralNetwork" )
504  type = kANN;
505  else if ( name == "RegressionModel" )
506  type = kLR;
507  return type;
508 }
std::string PMMLlib::PMMLlib::GetModelName ( xmlNodePtr  node)
private

Get the name of the XML node of a given model

Parameters
nodeModel node
Returns
value of attribute "modelName" of the model node

Definition at line 407 of file PMMLlib.cxx.

References PMMLlib::PMMLlib::_getProp().

408 {
409  string name("");
410  name = _getProp(node, string("modelName") );
411  return name;
412 }
int PMMLlib::PMMLlib::GetModelsNb ( )

Get the number of models

Returns
Number of models

Definition at line 397 of file PMMLlib.cxx.

References PMMLlib::PMMLlib::_nbModels.

398 {
399  return _nbModels;
400 }
xmlNodePtr PMMLlib::PMMLlib::GetPtr ( int  index,
std::string  name 
)
private

Get a pointer to the index-th node named name

Parameters
indexIndex of the node to search
nameName of the node
Returns
Pointer to the node found

Definition at line 420 of file PMMLlib.cxx.

References PMMLlib::PMMLlib::_doc, PMMLlib::PMMLlib::_rootNode, PMMLlib::PMMLlib::GetChildByName(), and CORBAEngineTest::i.

Referenced by PMMLlib::PMMLlib::BackupNode(), PMMLlib::PMMLlib::GetNeuralNetPtr(), and PMMLlib::PMMLlib::GetRegressionPtr().

422 {
423  xmlNodePtr node = NULL;
424 
425  if (_doc != NULL)
426  {
427  _rootNode = xmlDocGetRootElement(_doc);
428  node = GetChildByName(_rootNode, name);
429 
430  int i=0;
431  while ((i != index) && (node != NULL))
432  {
433  node = node->next;
434  i++;
435  }
436  }
437  return node;
438 }
xmlNodePtr PMMLlib::PMMLlib::GetPtr ( std::string  myModelName,
std::string  nodeName 
)
private

Get a pointer to the node named name whose 'modelName' attribute is ann_name

Parameters
modelNameModel name of the node to search
nodeNameName of the node
Returns
Pointer to the node found

Definition at line 446 of file PMMLlib.cxx.

References PMMLlib::PMMLlib::_doc, PMMLlib::PMMLlib::_getProp(), PMMLlib::PMMLlib::_rootNode, and PMMLlib::PMMLlib::GetChildByName().

448 {
449  xmlNodePtr node = NULL;
450  if (_doc != NULL)
451  {
452  node = GetChildByName(_rootNode, nodeName);
453  if( node )
454  {
455  string modelName = _getProp(node, string("modelName"));
456 
457  while ( (node != NULL) && modelName != myModelName )
458  {
459  node = node->next;
460  if( node )
461  {
462  modelName = _getProp(node, string("modelName"));
463  }
464  }
465  }
466  }
467  return node;
468 }
std::string PMMLlib::PMMLlib::GetTypeString ( )
private

Get the tag of the current model.

Returns
Current model tag

Definition at line 474 of file PMMLlib.cxx.

References PMMLlib::PMMLlib::_currentModelType, PMMLlib::kANN, and PMMLlib::kLR.

Referenced by PMMLlib::PMMLlib::BackupNode(), PMMLlib::PMMLlib::GetNeuralNetPtr(), and PMMLlib::PMMLlib::GetRegressionPtr().

475 {
476  string name = "";
477  switch(_currentModelType)
478  {
479  case kANN:
480  name = "NeuralNetwork";
481  break;
482  case kLR:
483  name = "RegressionModel";
484  break;
485  default:
486  throw string("Unknown PMML type.");
487  break;
488  }
489  return name;
490 }
std::string PMMLlib::PMMLlib::makeLog ( ) const

Make the string used by PMMLlib::printLog.

Returns
The log

Definition at line 214 of file PMMLlib.cxx.

References PMMLlib::PMMLlib::_log, and PMMLlib::PMMLlib::_pmmlFile.

Referenced by PMMLlib::PMMLlib::printLog().

215 {
216  ostringstream out;
217  out << "**\n**** Display of PMMLlib ****" << endl;
218  out << " ** _pmmlFile[" << _pmmlFile << "]" << endl;
219  out << " ** _log[" << (_log?1:0) << "]" << endl;
220  out << "**\n**** End of display of PMMLlib ****" << endl;
221  return out.str();
222 }
PMMLlib::PMMLlib::PMMLlib ( std::string  file,
bool  log = false 
)

Constructor to read a PMML file.

Parameters
fileName of the PMML file to read
logFlag to print logs or not

Definition at line 58 of file PMMLlib.cxx.

References PMMLlib::PMMLlib::_doc, PMMLlib::PMMLlib::_pmmlFile, PMMLlib::PMMLlib::_rootNode, and PMMLlib::PMMLlib::CountModels().

58  :
59  _log(log),
60  _pmmlFile(file),
61  _doc(NULL),
62  _rootNode(NULL),
63  _currentNode(NULL),
64  _nbModels(0),
67 {
68  try
69  {
70  xmlKeepBlanksDefault(0);
71  xmlInitParser();
72  _doc = xmlParseFile(_pmmlFile.c_str());
73  if ( _doc != NULL )
74  {
75  _rootNode = xmlDocGetRootElement(_doc);
76  CountModels();
77  }
78  else
79  throw string("Unable to read PMML file.");
80  }
81  catch ( std::string msg )
82  {
83  std::cerr << msg;
84  xmlFreeDoc(_doc);
85  xmlCleanupParser();
86  throw;
87  }
88 }
PMMLlib::PMMLlib::PMMLlib ( bool  log = false)

This constructor is mandatory for Swig because it can be used with no parameters.

Constructor to create a PMML file.

Parameters
logFlag to print logs or not

Definition at line 95 of file PMMLlib.cxx.

References PMMLlib::PMMLlib::SetRootNode().

96  :
97  _log(log),
98  _pmmlFile(""),
99  _doc(NULL),
100  _rootNode(NULL),
101  _currentNode(NULL),
102  _nbModels(0),
103  _currentModelName(""),
105 {
106  SetRootNode();
}
void PMMLlib::PMMLlib::printLog ( ) const

Print some information about the current PMML object.

Definition at line 227 of file PMMLlib.cxx.

References gui.logview::log, and PMMLlib::PMMLlib::makeLog().

228 {
229  string log = makeLog();
230  cout << log << endl;
231 }
void PMMLlib::PMMLlib::SetCurrentModel ( std::string  modelName,
PMMLType  type 
)

Set the current model and its type.

Parameters
modelNameName of the model to load (ie content of 'modelName' attribute)
typeType of PMML to read: one of kANN or kLR

Definition at line 125 of file PMMLlib.cxx.

References PMMLlib::PMMLlib::_currentModelName, PMMLlib::PMMLlib::_currentModelNode, PMMLlib::PMMLlib::_currentModelType, PMMLlib::PMMLlib::GetNeuralNetPtr(), PMMLlib::PMMLlib::GetRegressionPtr(), PMMLlib::kANN, and PMMLlib::kLR.

127 {
128  _currentModelName = modelName;
129  _currentModelType = type;
130  switch(type)
131  {
132  case kANN:
133  _currentModelNode = GetNeuralNetPtr(modelName);
134  break;
135  case kLR:
136  _currentModelNode = GetRegressionPtr(modelName);
137  break;
138  default:
139  throw string("Unknown PMML type.");
140  break;
141  }
142  if ( _currentModelNode == NULL )
143  throw string("Model not found.");
144 }
void PMMLlib::PMMLlib::SetCurrentModel ( std::string  modelName)

Throw an exception if there is no model or more than one model with name "modelName" in the PMML file.

Set the current model and its type.

Parameters
modelNameName of the model to load (ie content of 'modelName' attribute)

Definition at line 151 of file PMMLlib.cxx.

References PMMLlib::PMMLlib::_currentModelName, PMMLlib::PMMLlib::_currentModelNode, PMMLlib::PMMLlib::_currentModelType, PMMLlib::PMMLlib::_getProp(), PMMLlib::PMMLlib::_rootNode, and PMMLlib::PMMLlib::GetCurrentModelType().

152 {
153  if (_rootNode == NULL)
154  throw string("No PMML file set.");
155  xmlNodePtr node = NULL;
156  int nC = 0;
157  node = _rootNode->children;
158  while (node)
159  {
160  string nodeModelName = _getProp(node, string("modelName"));
161  if ( nodeModelName == modelName )
162  {
163  nC++;
164  _currentModelNode = node;
165  _currentModelName = modelName;
167  }
168  node = node->next;
169  }
170  if ( nC != 1 )
171  {
172  std::ostringstream oss;
173  oss << nC;
174  string msg = "SetCurrentModel(modelName) : found " + oss.str() + " model(s) in PMML file.\n";
175  msg += "Use SetCurrentModel(modelName,type).";
176  throw msg;
177  }
178 }
void PMMLlib::PMMLlib::SetCurrentModel ( )

Throw an exception if no model is found or if there are more than one model in the PMLL file.

Set the current model and its type.

Definition at line 184 of file PMMLlib.cxx.

References PMMLlib::PMMLlib::_currentModelName, PMMLlib::PMMLlib::_currentModelNode, PMMLlib::PMMLlib::_currentModelType, PMMLlib::PMMLlib::_getProp(), PMMLlib::PMMLlib::_nbModels, PMMLlib::PMMLlib::_rootNode, PMMLlib::PMMLlib::GetChildByName(), PMMLlib::kANN, and PMMLlib::kLR.

185 {
186  int nC = _nbModels;
187  if ( nC != 1 )
188  {
189  std::ostringstream oss;
190  oss << nC;
191  string msg = "SetCurrentModel() : found " + oss.str() + " model(s) in PMML file.\n";
192  msg += "Use SetCurrentModel(modelName) or SetCurrentModel(modelName,type).";
193  throw msg;
194  }
195  _currentModelNode = GetChildByName(_rootNode,"NeuralNetwork");
197  if (_currentModelNode == NULL)
198  {
199  _currentModelNode = GetChildByName(_rootNode,"RegressionModel");
201  }
202  if (_currentModelNode == NULL)
203  {
204  string msg("Couldn't get node in SetCurrentModel().");
205  throw msg;
206  }
207  _currentModelName = _getProp(_currentModelNode, string("modelName"));
208 }
void PMMLlib::PMMLlib::SetHeader ( std::string  copyright,
std::string  description,
std::string  appName,
std::string  appVersion,
std::string  annotation 
)

Set the header node in the tree.

Parameters
copyrightCopyright of the PMML file
descriptionDescription of the model
appNameName of the application that produced the file
appVersionVersion of the application that produced the file
annotationSome annotation

Definition at line 264 of file PMMLlib.cxx.

References PMMLlib::PMMLlib::_rootNode.

269 {
270  xmlNodePtr headerNode = xmlNewChild(_rootNode, 0, (const xmlChar*)"Header", 0);
271  xmlNewProp(headerNode, (const xmlChar*)"copyright", (const xmlChar*)(copyright.c_str()));
272  xmlNewProp(headerNode, (const xmlChar*)"description", (const xmlChar*)(description.c_str()));
273 
274  xmlNodePtr appNode = xmlNewChild(headerNode, 0, (const xmlChar*)"Application", 0);
275  xmlNewProp(appNode, (const xmlChar*)"name", (const xmlChar*)(appName.c_str()));
276  xmlNewProp(appNode, (const xmlChar*)"version", (const xmlChar*)(appVersion.c_str()));
277 
278  xmlNewChild(headerNode, 0, (const xmlChar*)"Annotation", (const xmlChar*)(annotation.c_str()));
279 }
void PMMLlib::PMMLlib::SetRootNode ( )
private

Set the root node in the tree:

<PMML version="4.1" xmlns="http://www.dmg.org/PMML-4_1">

Definition at line 239 of file PMMLlib.cxx.

References PMMLlib::PMMLlib::_doc, PMMLlib::PMMLlib::_rootNode, and PMMLlib::PMMLlib::_stringToXmlChar().

Referenced by PMMLlib::PMMLlib::PMMLlib().

240 {
241  xmlChar * xs = _stringToXmlChar("1.0");
242  _doc = xmlNewDoc(xs);
243  xmlFree(xs);
244 
245  xmlChar *xp = _stringToXmlChar("PMML");
246  _rootNode = xmlNewNode(0, xp);
247  xmlFree(xp);
248 
249  xmlNewProp(_rootNode, (const xmlChar*)"xmlns", (const xmlChar*)"http://www.dmg.org/PMML-4_1");
250  xmlNewProp(_rootNode, (const xmlChar*)"version", (const xmlChar*)"4.1");
251 
252  xmlDocSetRootElement(_doc, _rootNode);
253 }
void PMMLlib::PMMLlib::UnlinkNode ( )

Unlink the current model node.

Definition at line 526 of file PMMLlib.cxx.

References PMMLlib::PMMLlib::_currentModelNode.

527 {
528  xmlNodePtr ptr = _currentModelNode ;
529  xmlUnlinkNode( ptr );
530  xmlFreeNode( ptr );
531 }
void PMMLlib::PMMLlib::Write ( )

Save the XML tree in the PMML file

Definition at line 565 of file PMMLlib.cxx.

References PMMLlib::PMMLlib::_pmmlFile, and PMMLlib::PMMLlib::CountModels().

566 {
567  // Enregistrement de l'arbre DOM dans le fichier pmml
568  Write(_pmmlFile);
569  // Mise à jour du nombre de modèles
570  CountModels();
571 }
void PMMLlib::PMMLlib::Write ( std::string  file)

Save the XML tree in a given file

Parameters
Nameof the file

Definition at line 577 of file PMMLlib.cxx.

References PMMLlib::PMMLlib::_doc, PMMLlib::PMMLlib::_log, and PMMLBasicsTestLauncher::ret.

578 {
579  // Enregistrement de l'arbre DOM sous forme de fichier pmml
580  int ret = xmlSaveFormatFile( file.c_str(), _doc, 1);
581  if ( ret == -1 )
582  {
583  std::string msg(" *** Error :: unable to write the PMML file \"" + file + "\"") ;
584  cout << msg << endl;
585  throw msg;
586  }
587  if ( _log )
588  cout << " *** Write the PMML file \"" << file <<"\"" << endl;
589 }
PMMLlib::PMMLlib::~PMMLlib ( )

Destructor of the class.

Definition at line 111 of file PMMLlib.cxx.

References PMMLlib::PMMLlib::_doc, and PMMLlib::PMMLlib::_log.

112 {
113  if (_doc)
114  xmlFreeDoc(_doc);
115  xmlCleanupParser();
116  if ( _log )
117  cout << "~PMMLlib" << endl;
118 }