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

📄 ghmm_gmlclasswriter.cpp

📁 General Hidden Markov Model Library 一个通用的隐马尔科夫模型的C代码库
💻 CPP
字号:
/* * * created: 26 Feb 2002 by Wasinee Rungsarityotin * authors: Wasinee Rungsarityotin (rungsari@molgen.mpg.de) * file   : $Source$ * $Id: GHMM_GMLClassWriter.cpp 267 2003-04-24 17:24:07Z wasinee $ * revision date   : $Date: 2003-04-24 19:24:07 +0200 (Thu, 24 Apr 2003) $  ___copyright__  */#include <iostream>#include <xmlio/XMLIO_Document.h>#include "ghmm++/GHMM_GMLAlphabet.h"#include "ghmm++/GHMM_GMLClass.h"#ifdef HAVE_NAMESPACESusing namespace std;#endifGHMM_GMLClass::GHMM_GMLClass() {  alphabet_type     = GHMM_SINGLE_CHAR_ALPHABET;  xmlio_indent_type = XMLIO_INDENT_BOTH;  tag               = "hmm:class";  reading = READ_NONE;  attributes["hmm:type"] = "discrete";   attributes["hmm:low"]  = "0";  attributes["hmm:high"]  = "0";}GHMM_GMLClass::~GHMM_GMLClass() {}XMLIO_Element* GHMM_GMLClass::XMLIO_startTag(const string& tag, XMLIO_Attributes &attrs) {  reading = READ_NONE;  if (tag == "map")     {      return this;    }  else    if (tag == "symbol") // HACK!! We should look at the text node , not attribute      { 	reading = READ_SINGLE_CHAR;	return this;      }    return NULL;}void GHMM_GMLClass::XMLIO_endTag(const string& tag) {  reading = READ_NONE;}void GHMM_GMLClass::XMLIO_getCharacters(const string& characters) {  switch (reading) {  case READ_SINGLE_CHAR:    cout << "Alphabet seen: " << characters.c_str() << endl;    addSymbol(characters);    char tmp[3];    sprintf(tmp, "%d", size()-1);    attributes["hmm:high"]  = tmp;    break;  case READ_NONE:    break;  }}const int GHMM_GMLClass::XMLIO_writeContent(XMLIO_Document& writer) {  int total_bytes = 0;  int result;  unsigned int i;  result = writer.writeEndl();  if (result < 0)    return result;  total_bytes += result;  writer.changeIndent(2);  result = writer.writef("%s<map>\n",writer.indent);  total_bytes += result;  for (i = 0; i < symbols.size(); ++i) {    result = writer.writef("%s<symbol code=\"%2d\">%s</symbol>\n",			   writer.indent, i, symbols[i].c_str());    if (result < 0)      return result;    total_bytes += result;  }  result = writer.writef("%s</map>\n",writer.indent);  total_bytes += result;  return total_bytes;}GHMM_GMLClassWriter::GHMM_GMLClassWriter(GHMM_Alphabet *alphabet) {  char tmp[3];  alphabet_type     = GHMM_SINGLE_CHAR_ALPHABET;  xmlio_indent_type = XMLIO_INDENT_BOTH;  tag               = "hmm:class";  attributes["hmm:low"]   = "0";  sprintf(tmp,"%d" , alphabet->size()-1);  attributes["hmm:high"]  = tmp;  for (int i = 0; i < alphabet->size(); ++i) {      addSymbol(alphabet->getSymbol(i));  }}const int GHMM_GMLClassWriter::XMLIO_writeContent(XMLIO_Document& writer) {  int total_bytes = 0;  int result;  unsigned int i;  result = writer.writeEndl();  if (result < 0)    return result;  total_bytes += result;  writer.changeIndent(2);  result = writer.writef("%s<map>\n",writer.indent);  total_bytes += result;  for (i = 0; i < symbols.size(); ++i) {    result = writer.writef("%s<symbol code=\"%2d\">%s</symbol>\n",			   writer.indent, i, symbols[i].c_str());    if (result < 0)      return result;    total_bytes += result;  }  result = writer.writef("%s</map>\n",writer.indent);  total_bytes += result;  return total_bytes;}

⌨️ 快捷键说明

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