Home | History | Annotate | Download | only in include
      1 /*---------------------------------------------------------------------------*
      2  *  search_network.h  *
      3  *                                                                           *
      4  *  Copyright 2007, 2008 Nuance Communciations, Inc.                               *
      5  *                                                                           *
      6  *  Licensed under the Apache License, Version 2.0 (the 'License');          *
      7  *  you may not use this file except in compliance with the License.         *
      8  *                                                                           *
      9  *  You may obtain a copy of the License at                                  *
     10  *      http://www.apache.org/licenses/LICENSE-2.0                           *
     11  *                                                                           *
     12  *  Unless required by applicable law or agreed to in writing, software      *
     13  *  distributed under the License is distributed on an 'AS IS' BASIS,        *
     14  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
     15  *  See the License for the specific language governing permissions and      *
     16  *  limitations under the License.                                           *
     17  *                                                                           *
     18  *---------------------------------------------------------------------------*/
     19 
     20 /* this file containts data structures needed for defining FSM network*/
     21 
     22 #ifndef _h_search_network_
     23 #define _h_search_network_
     24 
     25 #include"srec_sizes.h"
     26 
     27 typedef struct FSMarc_t FSMarc;
     28 typedef struct FSMnode_t FSMnode;
     29 
     30 #define DEBUG_WDADD 0
     31 
     32 /* DEBUG_WDADD:
     33    it's really hard to debug the incremental word addition feature
     34    without being able to navigate through the graph structure, this
     35    is enabled in msdev by a compilation that uses actual pointers
     36    for arc and node references, arc and node pointers can be expanded
     37    in visual studio, but the IDs (offsets into base pointers) cannot.
     38    During dev, care should be take to keep the !DEBUG_WDADD fast
     39 
     40    ItoX, XtoP, etc .. convert IDs to X to Ptrs, where
     41    I ... means ID
     42    P ... means pointer
     43    X ... means ID or pointer, depending on DEBUG_WDADD
     44 */
     45 
     46 #if DEBUG_WDADD
     47 
     48 #define IF_DEBUG_WDADD(EXPRESSION) EXPRESSION
     49 #define printf_arc printf_arc1
     50 #define printf_node printf_node1
     51 #define TO_NODE(ARC) (ARC)->to_node
     52 #define NEXT_NODE(NOD) (NOD)->next_node
     53 #define LINKL_NEXT(ARC) (ARC)->linkl_next_arc
     54 #define LINKL_PREV(ARC) (ARC)->linkl_prev_arc
     55 #define FIRST_PREV(NOD) (NOD)->first_prev_arc
     56 #define FIRST_NEXT(NOD) (NOD)->first_next_arc
     57 #define ARC_XtoP(ARC) (ARC)
     58 #define ARC_XtoI(ARC)  ((arcID)((ARC)-fst->FSMarc_list))
     59 #define ARC_PtoX(ARC)  (ARC)
     60 #define ARC_ItoX(ARC_ID)  (&fst->FSMarc_list[ARC_ID])
     61 #define NODE_XtoP(NOD) (NOD)
     62 #define NODE_XtoI(NOD) ((nodeID)((NOD)-fst->FSMnode_list))
     63 #define NODE_PtoX(NOD) (NOD)
     64 #define NODE_ItoX(NODE_ID) (&fst->FSMnode_list[NODE_ID])
     65 #define FSMARC_NULL NULL
     66 #define FSMNODE_NULL NULL
     67 #define FSMARC_FREE (FSMarc*)0xffffffff
     68 #define FSMNODE_FREE (FSMnode*)0xffffffff
     69 
     70 #else
     71 
     72 #define IF_DEBUG_WDADD(EXPRESSION)
     73 #define printf_arc
     74 #define printf_node
     75 #define TO_NODE(ARC) fst->FSMarc_list[(ARC)].to_node
     76 #define NEXT_NODE(NOD) fst->FSMnode_list[(NOD)].un_ptr.next_node
     77 #define LINKL_NEXT(ARC) fst->FSMarc_list[(ARC)].linkl_next_arc
     78 #define LINKL_PREV(ARC) fst->FSMarc_list[(ARC)].linkl_prev_arc
     79 #define FIRST_PREV(NOD) fst->FSMnode_list[(NOD)].first_prev_arc
     80 #define FIRST_NEXT(NOD) fst->FSMnode_list[(NOD)].un_ptr.first_next_arc
     81 #define ARC_XtoP(ARC) (&fst->FSMarc_list[(ARC)])
     82 #define ARC_XtoI(ARC)  ((arcID)(ARC))
     83 #define ARC_PtoX(ARC)  ((arcID)((ARC)-fst->FSMarc_list))
     84 #define ARC_ItoX(ARC_ID)  ((arcID)(ARC_ID))
     85 #define NODE_XtoP(NOD) (&fst->FSMnode_list[(NOD)])
     86 #define NODE_XtoI(NOD) ((nodeID)(NOD))
     87 #define NODE_PtoX(NOD) ((nodeID)((NOD)-fst->FSMnode_list))
     88 #define NODE_ItoX(NODE_ID) ((nodeID)(NODE_ID))
     89 #define FSMARC_NULL MAXarcID
     90 #define FSMNODE_NULL MAXnodeID
     91 #define FSMARC_FREE MAXarcID-1
     92 
     93 #endif
     94 
     95 #if DEBUG_WDADD
     96 typedef FSMnode* FSMnode_ptr;
     97 typedef FSMarc*  FSMarc_ptr;
     98 #else
     99 typedef nodeID      FSMnode_ptr;
    100 typedef arcID       FSMarc_ptr;
    101 #endif
    102 
    103 /**
    104  * @todo document
    105  */
    106 typedef struct FSMnode_t
    107 {
    108   union {
    109     FSMarc_ptr first_next_arc;
    110     FSMnode_ptr next_node;
    111   } un_ptr;
    112   FSMarc_ptr first_prev_arc; /* this can be removed if not doing addword */
    113 }
    114 FSMnode_t;
    115 
    116 /**
    117  * @todo document
    118  */
    119 typedef struct FSMarc_t
    120 {
    121 #if DEBUG_WDADD
    122   char* ilabel_str;
    123   char* olabel_str;
    124 #endif
    125   FSMnode_ptr to_node;
    126   FSMarc_ptr linkl_next_arc;
    127 
    128   FSMnode_ptr fr_node;         /* this can be removed if not doing addword */
    129   FSMarc_ptr linkl_prev_arc;   /* this can be removed if not doing addword */
    130 
    131   labelID ilabel;              /* input label */
    132   labelID olabel;              /* output label */
    133   costdata cost;
    134 }
    135 FSMarc_t;
    136 
    137 /*according to Johan:*/
    138 #define EPSILON_OFFSET 3
    139 #define EPSILON_LABEL 0
    140 #define WORD_BOUNDARY 1
    141 #define PHONE_BOUNDARY 2
    142 
    143 /* */
    144 #define WORD_EPSILON_LABEL 0
    145 
    146 
    147 
    148 
    149 #endif
    150