📄 myruleexporter.cpp
字号:
//-------------------------------------------------------------------// Author........: Aleksander 豩rn// Date..........:// Description...:// Revisions.....://===================================================================#include <stdafx.h> // Precompiled headers.#include <copyright.h>#include <kernel/algorithms/myruleexporter.h>#include <kernel/structures/rules.h>#include <kernel/structures/rule.h>#include <kernel/utilities/systemkit.h>#include <kernel/system/fstream.h>//-------------------------------------------------------------------// Methods for class MyRuleExporter.//===================================================================//-------------------------------------------------------------------// Constructors/destructor.//===================================================================MyRuleExporter::MyRuleExporter() {}MyRuleExporter::~MyRuleExporter() {}//-------------------------------------------------------------------// Methods inherited from Identifier.//===================================================================IMPLEMENTIDMETHODS(MyRuleExporter, MYRULEEXPORTER, RuleExporter)//-------------------------------------------------------------------// Methods inherited from Exporter.//===================================================================//-------------------------------------------------------------------// Method........: ExportPrologue// Author........: Aleksander 豩rn// Date..........:// Description...:// Comments......: Consider using IOKit instead.// Revisions.....://===================================================================boolMyRuleExporter::ExportPrologue(ofstream &stream, const Structure &structure) const { // Cast to already verified type (in Apply method). Handle<Rules> rules = dynamic_cast(Rules *, const_cast(Structure *, &structure)); // Write some general information. stream << "% Rules/patterns generated by ROSETTA." << endl; stream << "% Exported " << SystemKit::GetTimestamp() << " by " << SystemKit::GetUser() << "." << endl; stream << "%" << endl; stream << "% " << rules->GetName() << endl; stream << "% " << rules->GetNoRules() << " rules." << endl; stream << endl; return true;}//-------------------------------------------------------------------// Methods inherited from RuleExporter.//===================================================================//-------------------------------------------------------------------// Method........: ExportRule// Author........: Aleksander 豩rn// Date..........:// Description...: Overloaded to deal with this particular rule syntax.// Comments......:// Revisions.....://===================================================================boolMyRuleExporter::ExportRule(ofstream &stream, int /*rule_no*/, const Rule &rule) const { String formatted; bool masked = true; // Format rule. if (!rule.Format(formatted, GetDecisionTable(), masked)) { Message::Error("Error formatting rule."); return false; } // Dump formatted rule to file stream. stream << formatted << endl; int no_decision_values = rule.GetNoDecisionValues(); // Dump supports to file stream. stream << "Supp. (LHS) = [" << rule.GetSupport() << " object(s)" << "]" << endl; stream << "Supp. (RHS) = ["; int i; for (i = 0; i < no_decision_values; i++) { stream << rule.GetSupport(i) << " object(s)"; if (i < (no_decision_values - 1)) stream << ", "; } stream << "]" << endl; // Dump probabilities to file stream. stream << "Acc. (RHS) = ["; for (i = 0; i < no_decision_values; i++) { stream << rule.GetAccuracy(i); if (i < (no_decision_values - 1)) stream << ", "; } stream << "]" << endl; // Dump coverages to file stream. stream << "Cov. (LHS) = [" << rule.GetCoverage(no_objects_) << "]" << endl; stream << "Cov. (RHS) = ["; for (i = 0; i < no_decision_values; i++) { float coverage = rule.GetCoverage(i, decisions_, cardinalities_); if (coverage == Undefined::Float()) stream << Undefined::String(); else stream << coverage; if (i < (no_decision_values - 1)) stream << ", "; } stream << "]" << endl; // Dump stabilities to file stream. stream << "Stab. (LHS) = [" << rule.GetStability() << "]" << endl; stream << "Stab. (RHS) = ["; for (i = 0; i < no_decision_values; i++) { stream << rule.GetStability(i); if (i < (no_decision_values - 1)) stream << ", "; } stream << "]" << endl << endl; return true;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -