예제 #1
0
int inithtk(int argc, char *argv[],const char * app_version, bool noGraphics)
{
	InitThreads(HT_MSGMON);   // enable msg driven monitoring
	if(InitShell(argc,argv,app_version)<SUCCESS) return FAIL;
	// CommonInit() expanded with incompatible things commented out: 
		InitMem();   InitLabel();
		InitMath();  InitSigP(); InitUtil();
		InitWave();  /*InitAudio();*/ InitModel();
		if(InitParm()<SUCCESS) return FAIL;
		InitGraf((Boolean)noGraphics);
		InitDict();  InitNet();   InitLM();
		InitRec();  InitLat();  /*InitAdapt();*/
		
		EnableBTrees();   /* allows unseen triphones to be synthesised */
		/*
		Register(abuffer_version);
		Register(acode_version);
		Register(acomponent_version);
		Register(adict_version);
		Register(agram_version);
		Register(angram_version);
		Register(ahmms_version);
		Register(ahtk_version);
		Register(amonitor_version);
		Register(apacket_version);
		Register(arec_version);
		Register(aresource_version);
		Register(arman_version);
		Register(asource_version);
		*/
		InfoPrinted();
		return SUCCESS;
}
예제 #2
0
파일: vm.c 프로젝트: nexusj/mint-lang
Object* PushDict(VM* vm)
{
	Object* obj = NewObject(vm, OBJ_DICT);
	InitDict(&obj->dict);
	PushObject(vm, obj);
	return obj;
}
예제 #3
0
CHEWING_API int chewing_Init(
		const char *dataPath,
		const char *hashPath )
{
	/* initialize Tree, Char, and Dict */
	/* FIXME: check the validation of dataPath */
	InitTree( dataPath );
	InitChar( dataPath );
	InitDict( dataPath );

	/* initialize Hash */
	/* FIXME: check the validation of hashPath */
	InitHash( hashPath );

	/* initialize SymbolTable */
	if ( ! InitSymbolTable( (char*) hashPath ) )
		InitSymbolTable( (char*) dataPath );
	if ( ! InitEasySymbolInput( (char *) hashPath ) )
		InitEasySymbolInput( (char *) dataPath );

	/* initialize HanyuPinYin table */
	if ( ! InitHanyuPinYin( hashPath ) )
		InitHanyuPinYin( dataPath );

#ifdef ENABLE_DEBUG
{
        char *dbg_path;
	int failsafe = 1;
	dbg_path = getenv( "CHEWING_DEBUG" );
	if ( dbg_path ) {
		fp_g = fopen( dbg_path, "w+" );
		if ( fp_g )
			failsafe = 0;
	}
	if ( failsafe == 1 ) {
		dbg_path = FAILSAFE_OUTPUT;
	        fp_g = fopen( dbg_path, "w+" );
		if ( ! fp_g ) {
			fprintf( stderr, 
				"Failed to record debug message in file.\n"
				"--> Output to stderr\n" );
		}
	}
	/* register debug service */
	if ( fp_g )
		addTerminateService( TerminateDebug );
}
#endif
	bTerminateCompleted = 0;
	return 0;
}
예제 #4
0
void Initialise(int argc, char *argv[])
{
   InitThreads(HT_MSGMON);
	if(InitShell(argc,argv,hnettest_version)<SUCCESS)
		HError(999,"Initialise: couldnt init HShell");
	InitMem();   InitLabel();
	InitMath();  InitSigP();
	InitWave();  InitAudio();
	if(InitParm()<SUCCESS)
		HError(999,"Initialise: couldnt init HParm");
	InitGraf(FALSE);  InitModel();
	InitDict();  InitNet();
	EnableBTrees();   /* allows unseen triphones to be synthesised */
	if (!InfoPrinted() && NumArgs() == 0)
		ReportUsage();
}
예제 #5
0
CHEWING_API ChewingContext *chewing_new()
{
	ChewingContext *ctx;
	int ret;
	char search_path[PATH_MAX];
	char path[PATH_MAX];

	ctx = ALC( ChewingContext, 1 );
	if ( !ctx )
		goto error;

	ctx->output = ALC ( ChewingOutput, 1 );
	if ( !ctx->output )
		goto error;

	ctx->data = allocate_ChewingData();
	if ( !ctx->data )
		goto error;

	chewing_Reset( ctx );

	ret = get_search_path( search_path, sizeof( search_path ) );
	if ( ret )
		goto error;

	ret = find_path_by_files(
		search_path, DICT_FILES, path, sizeof( path ) );
	if ( ret )
		goto error;
	ret = InitDict( ctx->data, path );
	if ( ret )
		goto error;
	ret = InitTree( ctx->data, path );
	if ( ret )
		goto error;

	ret = InitHash( ctx->data );
	if ( !ret )
		goto error;

	ctx->cand_no = 0;

	ret = find_path_by_files(
		search_path, SYMBOL_TABLE_FILES, path, sizeof( path ) );
	if ( ret )
		goto error;
	ret = InitSymbolTable( ctx->data, path );
	if ( ret )
		goto error;

	ret = find_path_by_files(
		search_path, EASY_SYMBOL_FILES, path, sizeof( path ) );
	if ( ret )
		goto error;
	ret = InitEasySymbolInput( ctx->data, path );
	if ( ret )
		goto error;

	ret = find_path_by_files(
		search_path, PINYIN_FILES, path, sizeof( path ) );
	if ( ret )
		goto error;
	ret = InitPinyin( ctx->data, path );
	if ( !ret )
		goto error;

	return ctx;
error:
	chewing_delete( ctx );
	return NULL;
}
예제 #6
0
파일: Tagger.cpp 프로젝트: chagge/nlp_rasp
void Tagger::Init(int argc, char * argv[])
{

	setlocale(LC_CTYPE, "iso_8858_1");
#ifdef SpecialMalloc
	/* Force fast allocation */
	set_small_allocation(100);
#endif

	/* Clear data structures */
	InitDict(dict);
	InitDict(skip_dict);
	InitTrans(trans);
	InitTrans(c_newtrans);
	odictfile = otranfile = NULL;

	/* Verify command line */
	if (argc <= 2)
	  error_exit("Usage: label corpus options\n");

	/* Form options */
	InitOptions;

	set_up_options(argc, argv, &iterations, &initialise, &dict_size,
				dictname, tranname, odictname, otranname, outname, mapname,
				skipname, reducename, fsmname, grammarname, infername, ukwname,
				ofeaturesname, obadwordname, bdbmname, runkstatname, wunkstatname);

	any_output = !no_output || Option(report_stats) || OutOpt(prob_dist);


	/* Open BDBM dictionary */
	if (Option(bdbm)){
		/* Berkeley DB: first of all need to create the dbp data structure*/
		if((ret = db_create(&dbp, NULL, 0)) != 0) {
			fprintf(stderr, "db_create: %s\n", db_strerror(ret));
			exit (1);
		}
		/* Berkeley DB: Then you open it, readonly  */
		if((ret = dbp->open(dbp,bdbmname, NULL, DB_BTREE, DB_RDONLY, 0777)) != 0) {
			dbp->err(dbp, ret, "%s", bdbmname);
			exit(1);
		} 
	}

	/* Read mappings */
	if (Option(verbose)) printf("Read mappings\n");
	read_mapping(mapname);

	/* Read tag reduction mappings */
	if (Option(reduced_tags))
	{
		if (Option(verbose)) printf("Read reduced tag set\n");
		read_reduce_mapping(reducename);
	}

#ifdef Use_Parser
	/* Read parse rules */
	if (Option(use_parser))
	{
		if (Option(verbose)) printf("Read parse rules\n");
		parser_read_named(grammarname);
	}
#endif
#ifdef Use_FSM
	/* Read FSM definitions */
	if (Option(use_fsm))
	{
		if (Option(verbose)) printf("Read FSMs\n");
		fsm_read_named(fsmname);
	}
#endif

	/* Read skip list */
	if (Option(skip_list))
	{
		if (Option(verbose)) printf("Read skip list\n");
		read_named_dict(skipname, &skip_dict, -1);
	}

	/* Read unknown word rules */
	if (Option(unknown_rules))
	{
		if (Option(verbose)) printf("Read unknown word rules\n");
		read_unknown_rules(ukwname);
	}

	/* Set up dictionary [note]:it costs a few seconds*/
	if (dictname[0] == 0)
	{
		create_dict(&dict, dict_size);
		clear_dict(&dict);
	}
	else
	{
		if (Option(verbose)) printf("Read dictionary\n");
		read_named_dict(dictname, &dict, -1);
		if (infername[0] != 0)
		{
			if (Option(verbose)) printf("Read inference rules\n");
			infer_tags((char *)infername, &dict);

		}
	}

	/* Set up transitions [note] it costs a few seconds*/
	if (tranname[0] == 0)
	{
		create_trans(&trans, tags_all);
		clear_trans_all(&trans);
	}
	else
	{
		if (Option(verbose)) printf("Read transitions\n");
		read_named_ascii_trans(tranname, &trans);

		/* Analyze selected features of lexicon to generate tag probabilities for unknown words. */
		if ( Option(unknown_morph) || Option(unknown_rules))
		{
			/* Initialize feature values */

			Allocate(features->featuretags, sizeof(FeatureTagSt), "features->featuretags: main");
			features->featuretags->next_open_slot = 0;

			features->gamma = trans.gamma;

			if ( features->maxsuffix == 0 )
			  features->maxsuffix = MinSuffixLen;
			if ( features->maxunkwords == 0 )
			  features->maxunkwords = MAXUNKWORDS;
			if ( features->maxprefcut == 0 )
			  features->maxprefcut = MinPrefixLen;
			if ( features->maxsuffcut == 0 )
			  features->maxsuffcut = MinSuffixLen;

			unknown_word_handling_initialization();
			gather_unigram_freqs( &dict );
		}

		if ( Option(unknown_morph) )
		{
			analyze_features( &dict, ofeaturesname, obadwordname, &trans, dbp, &dict, runkstatname );
		}
	}

	set_special_words(&dict, features );

	/* Create space for re-estimation or training */
	if (Option(reestimate) || Option(training))
	{
		c_newtrans.gamma = trans.gamma; /* Share arrays */
		create_trans(&c_newtrans, tags_all);
	}

	if (odictname[0] != 0)
	  odictfile = open_file(odictname, "w");
	if (otranname[0] != 0)
	  otranfile = open_file(otranname, "w");

	/* Set up anchor word */
	set_anchor(&dict);

	adjust_dict(&dict, trans.gamma, FALSE);
	adjust_trans(&trans, NULL);
}
예제 #7
0
ULong QLIECompress(LPVoid lpInput, Int32 InputSize, LPVoid lpOutput, Int32 OutputSize)
{
    Bool   bEnd;
    PByte  pbBuffer, pbOutEnd;
    UInt32 LastByte, CurrentByte;
    SPackEntryCompressedData *pData;
    SQLIECompressInfo Info;

    pData = (SPackEntryCompressedData *)lpOutput;
    if (pData == NULL)
        return InputSize + sizeof(*pData) - sizeof(pData->Data) + 256;
    else if (OutputSize < InputSize + sizeof(*pData) - sizeof(pData->Data) + 256)
        return 0;

    ZeroStruct(&Info);

    pData->Magic          = QLIE_COMP_MAGIC;
    pData->Flag           = FLAG_ENTRY_16BIT_LENGTH;
    pData->DecompressSize = InputSize;
    pbBuffer              = pData->Data;
    Info.pbBuffer         = (PByte)lpInput;
    Info.pbEnd            = Info.pbBuffer + InputSize;
    pbOutEnd              = (PByte)lpOutput + OutputSize;

    bEnd = False;
    while (!bEnd)
    {
        Long Index, val;
        ULong InsertIndex;
        bEnd = InitDict(&Info);

        Index = 0x100;
        while (Index-- > 0)
        {
            do
            {
                if (Info.dict_6200[Index] == Index && Info.dict_6100[Index] == 0)
                    break;
            } while (--Index >= 0);
            if (Index < 0)
                break;

            PByte dict_6000 = Info.dict_6000;
            PByte dict_4000 = Info.dict_4000;
            PByte dict_2000 = Info.dict_2000;

            val = 2;
            for (ULong i = 0x2000; i; --i)
            {
                if (*dict_6000 > val)
                {
                    val         = *dict_6000;
                    CurrentByte = *dict_2000;
                    LastByte    = *dict_4000;
                }

                dict_6000++;
                dict_2000++;
                dict_4000++;
            }

            if (val < 3)
                break;

            Int i, j, k;
            for (i = 0, k = 0, j = Info.DictLength - 1; i < j; ++i, ++k)
            {
                if (Info.dict_820C[i - 1] != CurrentByte || Info.dict_820C[i] != LastByte)
                {
                    Info.dict_820C[k - 1] = Info.dict_820C[i - 1];
                    continue;
                }

                if (i > 0)
                {
                    InsertIndex = AddNode(&Info, Info.dict_820C[k - 2], CurrentByte);
                    if (Info.dict_6000[InsertIndex] > 1)
                        --Info.dict_6000[InsertIndex];

                    InsertIndex = AddNode(&Info, Info.dict_820C[k - 2], Index);
                    if (Info.dict_6000[InsertIndex] != 0xFF)
                        ++Info.dict_6000[InsertIndex];
                }

                if (i < j - 1)
                {
                    InsertIndex = AddNode(&Info, LastByte, Info.dict_820C[i + 1]);
                    if (Info.dict_6000[InsertIndex] > 1)
                        --Info.dict_6000[InsertIndex];

                    InsertIndex = AddNode(&Info, Index, Info.dict_820C[i + 1]);
                    if (Info.dict_6000[InsertIndex] != 0xFF)
                        ++Info.dict_6000[InsertIndex];
                }

                Info.dict_820C[k - 1] = Index;
                ++i;
                --Info.DictLength;
            }

            Info.dict_820C[k - 1] = Info.dict_820C[i - 1];
            Info.dict_6200[Index] = CurrentByte;
            Info.dict_6100[Index] = LastByte;
            InsertIndex = AddNode(&Info, CurrentByte, LastByte);
            Info.dict_6000[InsertIndex] = 1;
        }

        pbBuffer = WriteBlock(&Info, pbBuffer, pbOutEnd);
        if (pbBuffer == NULL)
            return 0;
    }

    return pbBuffer - (PByte)pData;
}
예제 #8
0
int main(int argc, char *argv[])
{
   int i;
   char *s,*c;
   char fmt[256];
   dictList *dEntry,*d;

   InitShell(argc,argv,prog_version,prog_vc_id);
   InitMem();
   InitMath();
   InitWave();
   InitLabel();
   InitDict();
   InitWMap();
   InitLUtil();
   InitLModel();
   InitPCalc();

   if (!InfoPrinted() && NumArgs() == 0)
      ReportUsage();
   if (NumArgs() == 0) Exit(EXIT_SUCCESS);

   SetConfParms();

   CreateHeap(&langHeap,"langHeap",MSTAK,1,0.5,5000,40000);

   for (i=1; i<=LM_NSIZE; i++) cutOff[i] = 0;

   while (NextArg() == SWITCHARG) {
      s = GetSwtArg();
      if (strlen(s)!=1) 
         HError(16919,"Bad switch %s; must be single letter",s);
      switch(s[0]){
         case 'c':
           i = GetChkedInt(2,LM_NSIZE,s); 
	   cutOff[i] = GetChkedInt(1,1000,s);
	   break;
         case 'd':
	   if (NextArg()!=STRINGARG)
	     HError(16919,"LMCopy: Input dictionary file name expected");
	   dEntry=New(&gcheap,sizeof(dictList));
	   dEntry->fname=GetStrArg(); dEntry->next=NULL;
	   if (dList==NULL) dList=dEntry;
	   else {
	     for (d=dList;d->next!=NULL;d=d->next);
	     d->next=dEntry;
	   }
	   break;
         case 'f':
	   strcpy(fmt,GetStrArg());
	   for (c=fmt; *c!=0; *c=toupper(*c), c++);
	    if (strcmp(fmt, LM_TXT_TEXT)==0)
               saveFmt = LMF_TEXT;
	    else if (strcmp(fmt, LM_TXT_BINARY)==0)
               saveFmt = LMF_BINARY;
	    else if (strcmp(fmt, LM_TXT_ULTRA)==0)
               saveFmt = LMF_ULTRA;
	    else
	       HError(16919,"Unrecognised LM format, should be one of [%s, %s, %s]",
		      LM_TXT_TEXT, LM_TXT_BINARY, LM_TXT_ULTRA);
	   break;
	 case 'm':
	   remDup=FALSE;
	   break;
         case 'n':
            nSize = GetChkedInt(1,LM_NSIZE,s); break;
	 case 'o':
	   firstOnly=TRUE;
	   break;
	 case 'u':
	   if (NextArg()!=STRINGARG)
	     HError(16919,"LMCopy: Unigram file name expected");
	   uniFn = GetStrArg();
	   break;
         case 'v':
	   if (NextArg()!=STRINGARG)
	     HError(16919,"LMCopy: Dictionary output file name expected");
	   outDictFn = GetStrArg();
	   break;
         case 'w':
	    if (NextArg() != STRINGARG)
	       HError(16919,"LPlex: Word list file name expected");
	    wlistFN = GetStrArg();
	    break;
	 case 'T':
	    trace = GetChkedInt(0,077, s); break;
         default:
            HError(16919,"LMPlex: Unknown switch %s",s);
      }
   }
   if (NextArg()!=STRINGARG)  /* load the language model */
      HError(16919, "Input language model filename expected");
   srcFN = GetStrArg();

   if (NextArg()!=STRINGARG)  /* load the language model */
      HError(16919, "Output language model filename expected");
   tgtFN= GetStrArg();

   if (wlistFN!=NULL) {
      InitVocab(&vocab);   
      if(ReadDict(wlistFN,&vocab) < SUCCESS) 
	 HError(16913,"Could not read dict in %s", wlistFN);
      if (trace&T_TOP) {
	printf("Loaded %d words from %s\n",vocab.nwords,wlistFN); 
	fflush(stdout);
      }
      voc = &vocab;
      CreateWordList(wlistFN,&wlist,10);
      lm = LoadLangModel(srcFN,&wlist,1.0,LMP_FLOAT|LMP_COUNT,&langHeap);
   } else {
      voc = NULL;
      lm = LoadLangModel(srcFN,NULL,1.0,LMP_FLOAT|LMP_COUNT,&langHeap);
   }
   if (trace&T_TOP) {
     printf("Loaded model from %s\n",srcFN); 
     fflush(stdout);
   }
   if (lm->probType==LMP_COUNT) {
      RebuildLM(lm, cutOff, NULL, LMP_FLOAT); /* GLM there was no threshold before! */
   }
   if (uniFn!=NULL)
      ReplaceUnigrams(uniFn,lm);
   if (nSize>0 && nSize<lm->nSize)
      lm->nSize = nSize;
#ifdef HTK_CRYPT
   if (lm->encrypt && saveFmt==LMF_TEXT)
     saveFmt = LMF_BINARY;
#endif
   for (i=1;i<=lm->nSize;i++)
      lm->gInfo[i].fmt = (i==1) ? LMF_TEXT : saveFmt;
   SaveLangModel(tgtFN,lm);
   if (trace&T_TOP) {
     printf("Wrote model to %s\n",tgtFN); 
     fflush(stdout);
   }
   if (outDictFn) {
      MakeDictionary(outDictFn,dList,voc);
   }

   Exit(EXIT_SUCCESS);
   return EXIT_SUCCESS; /* never reached -- make compiler happy */
}   
예제 #9
0
#include "HLM.h"



typedef enum {unknown, wordLoop, boBiGram, matBiGram, multiLat, wordPair} BuildType;



static int trace     = 0;           /* Trace flags */



static LabId enterId;               /* id of !ENTRY label in ngram */

static LabId exitId;                /* id of !EXIT label in ngram */

static LabId bStartId=NULL;         /* id of start bracket */

static LabId bEndId=NULL;           /* id of end bracket */



static LabId unknownId;             /* id of unknown label in ngram */

static Boolean zapUnknown = FALSE;  /* zap unknown symbols from bigram */



MemHeap buildStack;



/* ---------------- Configuration Parameters --------------------- */



static ConfParam *cParm[MAXGLOBS];

static int nParm = 0;            /* total num params */



/* ---------------- Process Command Line ------------------------- */



/* SetConfParms: set conf parms relevant to this tool */

void SetConfParms(void)

{

   int i;



   nParm = GetConfig("HBUILD", TRUE, cParm, MAXGLOBS);

   if (nParm>0){

      if (GetConfInt(cParm,nParm,"TRACE",&i)) trace = i;

   }

}



void ReportUsage(void)

{

   printf("\nUSAGE: HBuild [options] wordList latFile\n\n");

   printf(" Option                                       Default\n\n");

   printf(" -b      binary lattice output                ASCII\n");

   printf(" -m s    load matrix bigram from s            off\n");

   printf(" -n s    load back-off bigram from s          off\n");

   printf(" -s s1 s2 s1/s2 are bigram start/end labels   !ENTER !EXIT\n");

   printf(" -t s1 s2 bracket word-loop/pair with s1 s2   off\n");

   printf(" -u s    set unknown symbol to s              !NULL\n");

   printf(" -w s    load word-pair grammar from s        off\n");

   printf(" -x s    load multi-level lattice from s      off\n");

   printf(" -z      ignore ngrams with unknown symbol    off\n");

   PrintStdOpts(""); 

   printf("\n\n");

}



int main(int argc, char *argv[])

{

   char *wordListFn,*latFn,*ipFn=NULL;

   LModel *bigramLm;

   BuildType bType = unknown;

   Boolean saveLatBin = FALSE;

   LatFormat format = HLAT_LMLIKE;

   Lattice *lat,*ipLat;

   Vocab voc;

   char  *s;



   Lattice *ProcessWordLoop(MemHeap *latHeap, Vocab *voc);

   Lattice *ProcessBiGram(MemHeap *latHeap, Vocab *voc, LModel *biLM);

   void SaveLattice(Lattice *lat, char *latFn, LatFormat format);

   Lattice *LoadLattice(MemHeap *latHeap, char *latFn, Vocab *voc,

                        Boolean shortArc);

   Lattice *ProcessWordPair(MemHeap *latHeap, Vocab *voc, char *fn);



   if(InitShell(argc,argv,hbuild_version,hbuild_vc_id)<SUCCESS)

      HError(3000,"HBuild: InitShell failed");

   InitMem();   InitLabel();

   InitMath();  

   InitDict();  InitNet();  

   InitLM();



   CreateHeap(&buildStack, "HBuild Stack",  MSTAK, 1, 0.0, 100000, LONG_MAX );



   if (!InfoPrinted() && NumArgs() == 0)

      ReportUsage();

   if (NumArgs() == 0) Exit(0);

   SetConfParms();
예제 #10
0
int main(int argc, char *argv[])
{
   char *s,*lfn,*dfn;
   void  GenSentences(char *latfn, char *dicfn);
  
   if(InitShell(argc,argv,hsgen_version,hsgen_vc_id)<SUCCESS)
      HError(3400,"HSGen: InitShell failed");

   InitMem();   InitLabel();
   InitMath();  InitSigP();
   InitWave();  InitAudio();
   InitVQ();    InitModel();
   if(InitParm()<SUCCESS)
      HError(3200,"HSGen: InitParm failed");
   InitDict();
   InitNet();

   if (!InfoPrinted() && NumArgs() == 0)
      ReportUsage();
   if (NumArgs() == 0) Exit(0);

   SetConfParms();
   while (NextArg() == SWITCHARG) {
      s = GetSwtArg();
      if (strlen(s)!=1) 
         HError(3419, "Bad switch %s; must be single letter", s);
      switch(s[0]){
      case 's':
         stats = TRUE; break;
      case 'l':
         lnum = TRUE; break;
      case 'n':
         ngen = GetChkedInt(1,1000000,s); break;
      case 'q':
         quiet = TRUE; break;
      case 'T':
         trace = GetChkedInt(0,07,s); break;
      default:
         HError(3419, "Unknown switch %s", s);
      }
   }
   if (NextArg()!=STRINGARG)
      HError(3419, "lattice file name expected");
   lfn = GetStrArg(); 
   if (NextArg()!=STRINGARG)
      HError(3419, "dictionary file name expected");
   dfn = GetStrArg(); 
   GenSentences(lfn,dfn);
   
   if(InitShell(argc,argv,hsgen_version,hsgen_vc_id)<SUCCESS)
      HError(3400,"HSGen: InitShell failed");

   ResetNet();
   ResetDict();
   ResetParm();
   ResetModel();
   ResetVQ();
   ResetAudio();
   ResetWave();
   ResetSigP();
   ResetMath();
   ResetLabel();
   ResetMem();
   ResetShell();
   
   Exit(0);
   return (0);          /* never reached -- make compiler happy */
}
예제 #11
0
int main(int argc, char *argv[])
{
   char *s;

   void Initialise(void);
   void DoRecognition(void);
   void DoAlignment(void);

   if(InitShell(argc,argv,hvite_version,hvite_vc_id)<SUCCESS)
      HError(3200,"HVite: InitShell failed");

   InitMem();   InitLabel();
   InitMath();  InitSigP();
   InitWave();  InitAudio();
   InitVQ();    InitModel();

   if(InitParm()<SUCCESS)  
      HError(3200,"HVite: InitParm failed");

   InitDict();
   InitNet();   InitRec();
   InitUtil(); 
   InitAdapt(&xfInfo); InitMap();

   if (!InfoPrinted() && NumArgs() == 0)
      ReportUsage();
   if (NumArgs() == 0) Exit(0);

   SetConfParms();
   CreateHeap(&modelHeap, "Model heap",  MSTAK, 1, 0.0, 100000, 800000 );
   CreateHMMSet(&hset,&modelHeap,TRUE); 

   while (NextArg() == SWITCHARG) {
      s = GetSwtArg();
      if (strlen(s)!=1) 
         HError(3219,"HVite: Bad switch %s; must be single letter",s);
      switch(s[0]){
      case 'a':
         loadLabels=TRUE; break;
      case 'b':
         if (NextArg()!=STRINGARG)
            HError(3219,"HVite: Utterance boundary word expected");
         bndId = GetLabId(GetStrArg(),TRUE); break;
      case 'c':
         tmBeam = GetChkedFlt(0.0,1000.0,s); break;          
      case 'd':
         if (NextArg()!=STRINGARG)
            HError(3219,"HVite: HMM definition directory expected");
         hmmDir = GetStrArg(); break;
      case 'e':
         saveAudioOut=TRUE; break;
      case 'f':
         states=TRUE; break;
      case 'g':
         replay=TRUE; break;
      case 'i':
         if (NextArg()!=STRINGARG)
            HError(3219,"HVite: Output MLF file name expected");
         /* if(SaveToMasterfile(GetStrArg())<SUCCESS)
            HError(3214,"HCopy: Cannot write to MLF"); */
         SaveToMasterfile(GetStrArg());
         break;
      case 'k':
	 xfInfo.useInXForm = TRUE;
	 break;
      case 'j':
         if (NextArg()!=INTARG)
            HError(3219,"HVite: No. of files per online adaptation step expected");
         update = GetChkedInt(1,256,s);
         break;
      case 'l':
         if (NextArg()!=STRINGARG)
            HError(3219,"HVite: Label file directory expected");
         labDir = GetStrArg(); break;
      case 'm':
         models=TRUE; break;
      case 'n':
         nToks = GetChkedInt(2,MAX_TOKS,s);
         if (NextArg()==FLOATARG || NextArg()==INTARG)
            nTrans = GetChkedInt(1,10000,s);
         else
            nTrans = 1;
         break;      
      case 'o':
         if (NextArg()!=STRINGARG)
            HError(3219,"HVite: Output label format expected");
         labForm = GetStrArg(); break;
      case 'p':
         wordPen = GetChkedFlt(-1000.0,1000.0,s);  break;
      case 'q':
         if (NextArg()!=STRINGARG)
            HError(3219,"HVite: Output lattice format expected");
         latForm = GetStrArg(); break;
      case 'r':
         prScale = GetChkedFlt(0.0,1000.0,s);  break;
      case 's':
         lmScale = GetChkedFlt(0.0,1000.0,s);  break;
      case 't':
         genBeam = GetChkedFlt(0,1.0E20,s); 
	 if (genBeam == 0.0)
	    genBeam = -LZERO;
         if (NextArg()==FLOATARG || NextArg()==INTARG) {
             genBeamInc = GetChkedFlt(0.0,1.0E20,s);
             genBeamLim = GetChkedFlt(0.0,1.0E20,s);
             if (genBeamLim < (genBeam + genBeamInc)) {
                genBeamLim = genBeam; genBeamInc = 0.0;
             }
          }
          else {
             genBeamInc = 0.0;
             genBeamLim = genBeam;
          }  
          break;
      case 'w':
         if (NextArg()!=STRINGARG)
            loadNetworks=TRUE;
         else {
            wdNetFn = GetStrArg();
            if (strlen(wdNetFn)==0) {
               wdNetFn=NULL;
               loadNetworks=TRUE;
            }
         }
         break;
      case 'u':
         maxActive = GetChkedInt(0,100000,s); break;      
      case 'v':
         wordBeam = GetChkedFlt(0,1.0E20,s); 
         if (wordBeam == 0.0)
            wordBeam = -LZERO;
         break;
      case 'x':
         if (NextArg()!=STRINGARG)
            HError(3219,"HVite: HMM file extension expected");
         hmmExt = GetStrArg(); break;
      case 'y':
         if (NextArg()!=STRINGARG)
            HError(3219,"HVite: Output label file extension expected");
         labExt = GetStrArg(); break;
      case 'z':
         if (NextArg()!=STRINGARG)
            HError(3219,"HVite: Lattice output file extension expected");
         latExt = GetStrArg(); break;
      case 'F':
         if (NextArg() != STRINGARG)
            HError(3219,"HVite: Data File format expected");
         if((dfmt = Str2Format(GetStrArg())) == ALIEN)
            HError(-3289,"HVite: Warning ALIEN Input file format set");
         break;
      case 'G':
         if (NextArg() != STRINGARG)
            HError(3219,"HVite: Source Label File format expected");
         if((ifmt = Str2Format(GetStrArg())) == ALIEN)
            HError(-3289,"HVite: Warning ALIEN Input file format set");
         break;
      case 'H':
         if (NextArg() != STRINGARG)
            HError(3219,"HVite: MMF File name expected");
         AddMMF(&hset,GetStrArg()); 
         break;
      case 'I':
         if (NextArg() != STRINGARG)
            HError(3219,"HVite: MLF file name expected");
         LoadMasterFile(GetStrArg()); break;
      case 'L':
         if (NextArg()!=STRINGARG)
            HError(3219,"HVite: Label/network file directory expected");
         labInDir = GetStrArg(); break;
      case 'P':
         if (NextArg() != STRINGARG)
            HError(3219,"HVite: Target Label File format expected");
         if((ofmt = Str2Format(GetStrArg())) == ALIEN)
            HError(-3289,"HVite: Warning ALIEN Label output file format set");
         break;
      case 'B':
         saveBinary = TRUE;
         break;
      case 'T':
         trace = GetChkedInt(0,511,s); break;
      case 'X':
         if (NextArg()!=STRINGARG)
            HError(3219,"HVite: Input label/network file extension expected");
         labInExt = GetStrArg(); break;
      case 'h':
	if (NextArg()!=STRINGARG)
	  HError(1,"Speaker name pattern expected");
	xfInfo.outSpkrPat = GetStrArg();
	if (NextArg()==STRINGARG) {
	  xfInfo.inSpkrPat = GetStrArg();
	  if (NextArg()==STRINGARG)
	    xfInfo.paSpkrPat = GetStrArg(); 
	}
	if (NextArg() != SWITCHARG)
	  HError(2319,"HERest: cannot have -h as the last option");	  
	break;
      case 'E':
         if (NextArg()!=STRINGARG)
            HError(2319,"HERest: parent transform directory expected");
	 xfInfo.usePaXForm = TRUE;
         xfInfo.paXFormDir = GetStrArg(); 
         if (NextArg()==STRINGARG)
	   xfInfo.paXFormExt = GetStrArg(); 
	 if (NextArg() != SWITCHARG)
	   HError(2319,"HVite: cannot have -E as the last option");	  
         break;              
      case 'J':
         if (NextArg()!=STRINGARG)
            HError(2319,"HERest: input transform directory expected");
         AddInXFormDir(&hset,GetStrArg());
         if (NextArg()==STRINGARG)
	   xfInfo.inXFormExt = GetStrArg(); 
	 if (NextArg() != SWITCHARG)
	   HError(2319,"HVite: cannot have -J as the last option");	  
         break;              
      case 'K':
         if (NextArg()!=STRINGARG)
            HError(2319,"HVite: output transform directory expected");
         xfInfo.outXFormDir = GetStrArg(); 
	 xfInfo.useOutXForm = TRUE;
         if (NextArg()==STRINGARG)
	   xfInfo.outXFormExt = GetStrArg(); 
	 if (NextArg() != SWITCHARG)
	   HError(2319,"HVite: cannot have -K as the last option");	  
         break;              
      default:
         HError(3219,"HVite: Unknown switch %s",s);
      }
   }
   
   if (NextArg()!=STRINGARG)
      HError(3219,"HVite: Dictionary file name expected");
   dictFn = GetStrArg();
   if (NextArg()!=STRINGARG)
      HError(3219,"HVite: HMM list  file name expected");
   hmmListFn = GetStrArg();

#ifndef PHNALG
   if ((states || models) && nToks>1)
      HError(3230,"HVite: Alignment using multiple tokens is not supported");
#endif
   if (NumArgs()==0 && wdNetFn==NULL)
      HError(3230,"HVite: Network must be specified for recognition from audio");
   if (loadNetworks && loadLabels)
      HError(3230,"HVite: Must choose either alignment from network or labels");
   if (nToks>1 && latExt==NULL && nTrans==1)
      HError(-3230,"HVite: Performing nbest recognition with no nbest output");
   if (nToks > 1 && latExt != NULL && nTrans > 1) 
      HError(-3230,"HVite: Performing nbest recognition with 1-best and latttices output");
   if ((update>0) && (!xfInfo.useOutXForm))
      HError(3230,"HVite: Must use -K option with incremental adaptation");


   Initialise();


   /* Process the data */
   if (wdNetFn==NULL)
      DoAlignment();
   else
      DoRecognition();

   /* Free up and we are done */

   if (trace & T_MEM) {
      printf("Memory State on Completion\n");
      PrintAllHeapStats();
   }


   DeleteVRecInfo(vri);
   ResetHeap(&netHeap);
   FreePSetInfo(psi);
   UpdateSpkrStats(&hset,&xfInfo, NULL); 
   ResetHeap(&regHeap);
   ResetHeap(&modelHeap);
   Exit(0);
   return (0);          /* never reached -- make compiler happy */
}