;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; LUSH Lisp Universal Shell
;;;   Copyright (C) 2002 Leon Bottou, Yann Le Cun, AT&T Corp, NECI.
;;; Includes parts of TL3:
;;;   Copyright (C) 1987-1999 Leon Bottou and Neuristique.
;;; Includes selected parts of SN3.2:
;;;   Copyright (C) 1991-2001 AT&T Corp.
;;;
;;; Includes information derived from the GSL (Gnu Scientific Library)
;;;   header files which are copyrighted and distributed under the GPL
;;;   by their respective authors.
;;;
;;; 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, USA
;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(libload "htk/htk-config")



#? *** htk_net

;; dummy function that adds HTK C header files in C file
(eval `(de dummy_htk_net () ,htk-cpheader-cmd ()))

#? * (dummy_htk_net)
#? * (initnet)
#? * (newlattice <heap> <nn> <na>)
#? * (newilattice <heap> <nn> <na> <info>)
#? * (freelattice <lat>)
#? * (writelattice <lat> <file> <form>)
#? * (readlattice <file> <heap> <voc> <shortarc> <add2dict>)
#? * (adjsublist <lat> <sublatid> <sublat> <adj>)
#? * (sublatlist <lat> <tail> <depth>)
#? * (expandmultilevellattice <heap> <lat> <voc>)
#? * (latticefromlabels <ll> <bnd> <voc> <heap>)
#? * (numnodefoll <n>)
#? * (numnodepred <n>)
#? * (findlatstart <lat>)
#? * (findlatend <lat>)
#? * (expandwordnet <heap> <lat> <voc> <hset>)
#? * (gethmmsetcxtinfo <hset> <frccxtind>)
#? * (gethcicontext <hci> <labid>)
#? * (ishcicontextind <hci> <labid>)
#? * (gethcimodel <hci> <lc> <name> <rc>)
#? * (addhcicontext <hci> <labid>)

;; ********************************************************


(de InitNet (  )
    #{ InitNet(  );  #} 
    ()
)


(de NewLattice (  heap  nn  na )
    ((-gptr- "MemHeap *") heap) 
    ((-int-) nn) 
    ((-int-) na)  
    (gptr #{ NewLattice(  $heap   ,$nn   ,$na  )  #} )            ;; Lattice *   -> gptr
)


(de NewILattice (  heap  nn  na  info )
    ((-gptr- "MemHeap *") heap) 
    ((-int-) nn) 
    ((-int-) na) 
    ((-gptr- "Lattice *") info)  
    (gptr #{ NewILattice(  $heap   ,$nn   ,$na   ,$info  )  #} )            ;; Lattice *   -> gptr
)


(de FreeLattice (  lat )
    ((-gptr- "Lattice *") lat)  
    #{ FreeLattice(  $lat  );  #} 
    ()
)


(de WriteLattice (  lat  file  form )
    ((-gptr- "Lattice *") lat) 
    ((-gptr- "FILE *") file) 
    ((-int-) form)                               ;; LatFormat -> int
    (int   #{ WriteLattice(  $lat   ,$file   ,$form  )  #} )       ;; ReturnStatus -> int
)


(de ReadLattice (  file  heap  voc  shortarc  add2dict )
    ((-gptr- "FILE *") file) 
    ((-gptr- "MemHeap *") heap) 
    ((-gptr- "Vocab *") voc) 
    ((-int-) shortarc) 
    ((-int-) add2dict)  
    (gptr #{ ReadLattice(  $file   ,$heap   ,$voc   ,$shortarc   ,$add2dict  )  #} )            ;; Lattice *   -> gptr
)


(de AdjSubList (  lat  sublatid  sublat  adj )
    ((-gptr- "Lattice *") lat) 
    ((-gptr- "NameCell *") sublatid) 
    ((-gptr- "Lattice *") sublat) 
    ((-int-) adj)  
    (gptr #{ AdjSubList(  $lat   ,$sublatid   ,$sublat   ,$adj  )  #} )            ;; SubLatDef *   -> gptr
)


(de SubLatList (  lat  tail  depth )
    ((-gptr- "Lattice *") lat) 
    ((-gptr- "Lattice *") tail) 
    ((-int-) depth)  
    (gptr #{ SubLatList(  $lat   ,$tail   ,$depth  )  #} )            ;; Lattice *   -> gptr
)


(de ExpandMultiLevelLattice (  heap  lat  voc )
    ((-gptr- "MemHeap *") heap) 
    ((-gptr- "Lattice *") lat) 
    ((-gptr- "Vocab *") voc)  
    (gptr #{ ExpandMultiLevelLattice(  $heap   ,$lat   ,$voc  )  #} )            ;; Lattice *   -> gptr
)


(de LatticeFromLabels (  ll  bnd  voc  heap )
    ((-gptr- "LabList *") ll) 
    ((-gptr- "NameCell *") bnd) 
    ((-gptr- "Vocab *") voc) 
    ((-gptr- "MemHeap *") heap)  
    (gptr #{ LatticeFromLabels(  $ll   ,$bnd   ,$voc   ,$heap  )  #} )            ;; Lattice *   -> gptr
)


(de NumNodeFoll (  n )
    ((-gptr- "LNode *") n)               ;; NodeId -> gptr
    (int   #{ NumNodeFoll(  $n  )  #} )
)


(de NumNodePred (  n )
    ((-gptr- "LNode *") n)  
    (int   #{ NumNodePred(  $n  )  #} )
)


(de FindLatStart (  lat )
    ((-gptr- "Lattice *") lat)  
    (gptr   #{ FindLatStart(  $lat  )  #} )             ;; NodeId -> gptr
)


(de FindLatEnd (  lat )
    ((-gptr- "Lattice *") lat)  
    (gptr   #{ FindLatEnd(  $lat  )  #} )                ;; NodeId -> gptr
)


(de ExpandWordNet (  heap  lat  voc  hset )
    ((-gptr- "MemHeap *") heap) 
    ((-gptr- "Lattice *") lat) 
    ((-gptr- "Vocab *") voc) 
    ((-gptr- "HMMSet *") hset)  
    (gptr #{ ExpandWordNet(  $heap   ,$lat   ,$voc   ,$hset  )  #} )            ;; Network *   -> gptr
)


(de GetHMMSetCxtInfo (  hset  frccxtind )
    ((-gptr- "HMMSet *") hset) 
    ((-int-) frccxtind)  
    (gptr #{ GetHMMSetCxtInfo(  $hset   ,$frccxtind  )  #} )            ;; HMMSetCxtInfo *   -> gptr
)


(de GetHCIContext (  hci  labid )
    ((-gptr- "HMMSetCxtInfo *") hci) 
    ((-gptr- "NameCell *") labid)  
    (int   #{ GetHCIContext(  $hci   ,$labid  )  #} )
)


(de IsHCIContextInd (  hci  labid )
    ((-gptr- "HMMSetCxtInfo *") hci) 
    ((-gptr- "NameCell *") labid)  
    (int   #{ IsHCIContextInd(  $hci   ,$labid  )  #} )
)


(de GetHCIModel (  hci  lc  name  rc )
    ((-gptr- "HMMSetCxtInfo *") hci) 
    ((-int-) lc) 
    ((-gptr- "NameCell *") name) 
    ((-int-) rc)  
    (gptr   #{ GetHCIModel(  $hci   ,$lc   ,$name   ,$rc  )  #} )              ;; HLink -> gptr
)


(de AddHCIContext (  hci  labid )
    ((-gptr- "HMMSetCxtInfo *") hci) 
    ((-gptr- "NameCell *") labid)  
    (int   #{ AddHCIContext(  $hci   ,$labid  )  #} )
)

;; ********************************************************

(dhc-make-with-libs () (list htk-libhtk)
  dummy_htk_net
  initnet
  newlattice
  newilattice
  freelattice
  writelattice
  readlattice
  adjsublist
  sublatlist
  expandmultilevellattice
  latticefromlabels
  numnodefoll
  numnodepred
  findlatstart
  findlatend
  expandwordnet
  gethmmsetcxtinfo
  gethcicontext
  ishcicontextind
  gethcimodel
  addhcicontext
)
