Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

/magnus/back_end/KB/include/KBMachineRep.h

Go to the documentation of this file.
00001 /*
00002  *   $Id: KBMachineRep.h,v 1.4 1999/11/23 20:28:53 bormotov Exp $
00003  */
00004 
00005 // Copyright (C) 1994 The New York Group Theory Cooperative
00006 // See magnus/doc/COPYRIGHT for the full notice.
00007 
00008 // Contents: Definition of KBMachineRep class.
00009 //
00010 // Principal Author: Sarah Rees
00011 //
00012 // Status: in progress
00013 //
00014 // Revision History:
00015 //
00016 // * 08/96 Dmitry B. implemented IPC tools.
00017 //
00018 
00019 #ifndef _KBMachineRep_H_
00020 #define _KBMachineRep_H_
00021 
00022 #include <Integer.h>
00023 
00024 #include "Word.h"
00025 #include "Vector.h"
00026 /*
00027 #include "RKBPackage.h"
00028 */
00029 #include "DFSARep.h"
00030 
00031 
00032 class KBMachineRep : public GroupDFSARep {
00033 public:
00034   KBMachineRep() : 
00035     GroupDFSARep(),
00036     numRules(0),
00037     lhs(0),
00038     rhs(0),
00039     length(1,1),
00040     ruleIndex(1,1) { length[0]=ruleIndex[0]=0;}
00041 
00042   KBMachineRep(const VectorOf<Chars> & genNames) : 
00043     GroupDFSARep("",genNames),
00044     numRules(0),
00045     lhs(1),
00046     rhs(1), 
00047     length(1,1),
00048     ruleIndex(1,1) {length[0]=ruleIndex[0]=0;}
00049 
00050   KBMachineRep(const VectorOf<Chars> & genNames,const WordOrder & word_order) : 
00051     GroupDFSARep("",genNames,word_order),
00052     numRules(0),
00053     lhs(1),
00054     rhs(1), 
00055     length(1,1),
00056     ruleIndex(1,1) {length[0]=ruleIndex[0]=0;}
00057 
00058   KBMachineRep(const VectorOf<Chars> & genNames,int numOfRules) : 
00059     GroupDFSARep("",genNames),
00060     numRules(numOfRules),
00061     lhs(numRules+1), 
00062     rhs(numRules+1),
00063     length(1,1),
00064     ruleIndex(1,1) {length[0]=ruleIndex[0]=0;}
00065 
00066   KBMachineRep(const VectorOf<Chars> & genNames,
00067                             const WordOrder & word_order,int numOfRules) : 
00068     GroupDFSARep("",genNames,word_order),
00069     numRules(numOfRules),
00070     lhs(numRules+1), 
00071     rhs(numRules+1),
00072     length(1,1),
00073     ruleIndex(1,1) {length[0]=ruleIndex[0]=0;}
00074 
00075   KBMachineRep(const VectorOf<Chars> & genNames,int numOfRules,int numOfStates)
00076        : GroupDFSARep("",genNames,numOfStates,1),
00077     numRules(numOfRules),
00078     lhs(numRules+1), 
00079     rhs(numRules+1),
00080     length(numOfStates+1,1),
00081     ruleIndex(numOfStates+1,1) {
00082       for (int i=0;i<=numOfStates;i++) length[i]=ruleIndex[i]=0;
00083     }
00084 
00085   KBMachineRep(const VectorOf<Chars> & genNames,const WordOrder & word_order,
00086       int numOfRules,int numOfStates)
00087        : GroupDFSARep("",genNames,word_order,numOfStates,1),
00088     numRules(numOfRules),
00089     lhs(numRules+1), 
00090     rhs(numRules+1),
00091     length(numOfStates+1,1),
00092     ruleIndex(numOfStates+1,1) {
00093       for (int i=0;i<=numOfStates;i++) length[i]=ruleIndex[i]=0;
00094     }
00095 
00096   ~KBMachineRep() { }
00097   KBMachineRep( const KBMachineRep& K ) :  // Copy constructor does deep copy.
00098     GroupDFSARep(K), numRules(K.numRules), lhs(K.lhs), rhs(K.rhs),
00099     length(K.length), ruleIndex(K.ruleIndex) { }
00100 
00101 
00102   KBMachineRep & operator = ( const KBMachineRep & K )
00103   {
00104     DFSARep& temp = *this;
00105     temp = (DFSARep)K;
00106     numRules = K.numRules;
00107     lhs = K.lhs; rhs = K.rhs;
00108     length = K.length; ruleIndex = K.ruleIndex;
00109     return *this;  
00110   }
00111 
00112 
00113   FSARep *clone() const { return new KBMachineRep(*this); }
00114 
00115   Bool operator == ( const KBMachineRep& K ) const { 
00116     if (equalDFSA(K)==0) return 0;
00117     else if (numRules != K.numRules || lhs != K.lhs || rhs != K.rhs)
00118       return 1;
00119     else for (State s=1;s<=getNumStates();s++){
00120       if (length[s]!=K.length[s]) return 0;
00121       else if (ruleIndex[s]!=K.ruleIndex[s]) return 0;
00122     }
00123     return 1;
00124   }
00125 
00126   Bool accepts(Word w) const {};
00127   Bool rejectsInState(Word w, int& state) const {};
00128   Bool nextAcceptedWord(Word& w) const {};
00129 
00130 //  Bool nextAcceptedWord(Word w, int*& history) const {}; //@rn bad arg
00131   void minimize() {};
00132   
00133 //  void readFrom(istream &str = cin);
00134   void printOn(ostream &str = cout) const ;
00135   void oldFormatPrintOn(ostream &str = cout) const ;
00136 
00137   void setNumStates(int i);
00138   void setNumRules(int i) {numRules = i;};
00139   int getNumRules() {return numRules;};
00140   int getLength(State s) const { return length[s];}
00141   void setLength(State s,int i) { length[s] = i;}
00142   int getRuleIndex(State s) const { return ruleIndex[s];}
00143   void setRuleIndex(State s,int i) { ruleIndex[s] = i;}
00144   Word getLHS(int i) { return lhs[i];}
00145   Word getRHS(int i) { return rhs[i];}
00146   void setLHS(int i,Word w) { lhs[i]=w;}
00147   void setRHS(int i,Word w) { rhs[i]=w;}
00148   Bool  rewrite(Word & w) const;
00149   // Now defined as a DFSA function
00150   //Integer sizeLanguage() const;
00151   //Bool finiteLanguage() const {return (sizeLanguage() != -1);}
00152 
00153 
00154   /////////////////////////////////////////////////////////////////////////
00155   //                                                                     //
00156   // IPC tools:                                                          //
00157   //                                                                     //
00158   /////////////////////////////////////////////////////////////////////////
00159 
00160   void write( ostream& ostr ) const
00161   {
00162     GroupDFSARep::write(ostr);
00163     ostr < numRules < lhs < rhs < length < ruleIndex;
00164   }
00165 
00166   void read( istream& istr ) 
00167   {
00168     GroupDFSARep::read(istr);
00169     istr > numRules > lhs > rhs > length > ruleIndex;
00170   }
00171 
00172 
00173 private:
00174 
00175   int numRules;
00176   VectorOf<Word> lhs;       // @rn Really need to save these?
00177   VectorOf<Word> rhs;       //@sr Yes - we need them for rewriting.
00178 
00179   VectorOf<int> length;
00180   // length[s] is the length of a shortest path to state s.
00181 
00182   VectorOf<int> ruleIndex;
00183   // the prefix of length length[s] of the left hand
00184   // side of the i-th rule traces a path to the state s
00185   // if ruleIndex[s] = i.
00186 
00187 };
00188 #endif
00189 

Generated at Tue Jun 19 09:49:36 2001 for Magnus Classes by doxygen1.2.6 written by Dimitri van Heesch, © 1997-2001