📄 ghmm_gmldoc.cpp
字号:
/* * * created: 26 Feb 2002 by Wasinee Rungsarityotin * authors: Wasinee Rungsarityotin (rungsari@molgen.mpg.de) * file : $Source: /cvsroot/ghmm/ghmm/ghmm++/GHMM_GMLDoc.cpp,v $ * $Id: GHMM_GMLDoc.cpp,v 1.7 2004/02/27 20:10:20 wasinee Exp $ * revision date : $Date: 2004/02/27 20:10:20 $ _Copyright (C) 1998-2001, ZAIK/ZPR, Universit鋞 zu K鰈n _ _This program is free software; you can redistribute it and/or modify _it under the terms of the GNU General Public License as published by _the Free Software Foundation; either version 2 of the License, or _(at your option) any later version. _ _This program is distributed in the hope that it will be useful, _but WITHOUT ANY WARRANTY; without even the implied warranty of _MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the _GNU General Public License for more details. _ _You should have received a copy of the GNU General Public License _along with this program; if not, write to the Free Software _Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA _ */#include <iostream>#include <assert.h>#include "ghmm++/GHMM_GMLDoc.h"#include "ghmm++/GHMM_ContinuousModel.h"#include "ghmm++/GHMM_Sequences.h"#include "ghmm++/GHMM_GMLAlphabet.h"#ifdef HAVE_NAMESPACESusing namespace std;#endifGHMM_GraphMLDoc::GHMM_GraphMLDoc(enumModelType model_type) { hmmclass = NULL; sdiscrete_model = NULL; continuous_model = NULL; sequences = NULL; reading_ghmm = false; tmp_alphabets = NULL; this->model_type = model_type;}GHMM_GraphMLDoc::~GHMM_GraphMLDoc() { if (sdiscrete_model != NULL ) { delete sdiscrete_model; } if (continuous_model != NULL ) { delete continuous_model; } if (hmmclass != NULL) { delete hmmclass; }}const char* GHMM_GraphMLDoc::toString() const { return "GHMM_GraphMLDoc";}GHMM_SWDiscreteModel* GHMM_GraphMLDoc::getDiscreteModel() const { return sdiscrete_model;}GHMM_ContinuousModel* GHMM_GraphMLDoc::getContinuousModel() const { return continuous_model;}GHMM_Sequences* GHMM_GraphMLDoc::getSequences() const { return sequences;}XMLIO_Element* GHMM_GraphMLDoc::XMLIO_startTag(const string& my_tag, XMLIO_Attributes &attrs) { if (my_tag == "graphml") { reading_ghmm = true; //printf("GHMM_GraphMLDoc::XMLIO_startTag\n"); //cout << "\t\t" << my_tag << endl; return this; } if (reading_ghmm) { if (my_tag == "desc") { return this; } if (my_tag == "hmm:class") { //printf("GHMM_GraphMLDoc::XMLIO_startTag\n"); //cout << "\t\t" << my_tag << endl; hmmclass = new GHMM_GMLClass(); return hmmclass; } if (my_tag == "paint") {return this; } if (my_tag == "point" || my_tag == "line") { return this;} if (my_tag == "map" || my_tag == "symbol") { return this; } if (my_tag == "hmm:alphabet") { //printf("GHMM_GraphMLDoc::XMLIO_startTag\n"); //cout << "\t\t" << my_tag << endl; tmp_alphabets = new GHMM_GMLAlphabet(); return tmp_alphabets; } if (my_tag == "key") { //printf("GHMM_GraphMLDoc::XMLIO_startTag\n"); //cout << "\t\t" << my_tag << endl; if (attrs["id"] == "emissions") { if ( attrs["gd:type"] == "HigherDiscreteProbDist" ) { model_type = GHMM_DISCRETE; return this; } else if ( attrs["gd:type"] == "ContinuousProbDist" ) { model_type = GHMM_CONTINUOUS; return this; } else { /* error message if no valid hmm type is specified. */ fprintf(stderr, "Need to know the type of the HMM\n"); exit(-1); } } else return this; } if (my_tag == "graph") { // printf("GHMM_GraphMLDoc::XMLIO_startTag:"); cout << my_tag << endl; if ( model_type != NONE ) { if ( model_type == GHMM_DISCRETE ) { fprintf(stderr, "Discrete model found\n"); GHMM_Alphabet *alphas = tmp_alphabets; assert( alphas != NULL ); assert( hmmclass != NULL ); if ( hmmclass->size() < 1 ) { // a set of transition matrices sdiscrete_model = new GHMM_SWDiscreteModel(tmp_alphabets, 1); // 1 class return sdiscrete_model; } else if ( hmmclass->size() > 1 ) // a set of transition matrices { sdiscrete_model = new GHMM_SWDiscreteModel(tmp_alphabets, (int)hmmclass->size()); return sdiscrete_model; } else { /* error message if no valid hmm type is specified. */ fprintf(stderr, "You need at least one transition class\n"); exit(-1); } } // DISCRETE if ( model_type == GHMM_CONTINUOUS ) { fprintf(stderr, "Continous model found\n"); continuous_model = new GHMM_ContinuousModel(); return continuous_model; } // CONTINUOUS } else { /* error message if no valid hmm type is specified. */ fprintf(stderr, "Need to know the type of the HMM\n"); exit(-1); } } else { fprintf(stderr,"Tag '%s' not recognized in graphml element.\n",my_tag.c_str()); exit(1); } } return NULL;}void GHMM_GraphMLDoc::XMLIO_endTag(const string& my_tag) { if (my_tag == "graphml") reading_ghmm = false;}int GHMM_GraphMLDoc::XMLIO_writeTrailer() { return writef("</graphml>\n");}int GHMM_GraphMLDoc::XMLIO_writeProlog() { int this_result; int return_result = 0; this_result = XMLIO_Document::XMLIO_writeProlog(); /* Returns error code if an error occured. */ if (this_result < 0) return this_result; return_result += this_result; this_result = writef("<graphml version=\"1.0\">"); /* Returns error code if an error occured. */ if (this_result < 0) return this_result; return_result += this_result; changeIndent(2); XMLIO_Element modeltype; modeltype.tag = "key"; modeltype.attributes["for"] ="node"; switch( model_type ) { case GHMM_DISCRETE: modeltype.attributes["gd:type"] = "HigherDiscreteProbDist"; break; case GHMM_CONTINUOUS: modeltype.attributes["gd:type"] = "ContinuousProbDist"; break; } modeltype.attributes["id"] = "emissions"; writeEndl(); this_result = writeElement(&modeltype); writeEndl(); /* Returns error code if an error occured. */ if (this_result < 0) return this_result; return_result += this_result; return return_result;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -