1/*---------------------------------------------------------------------------*
2 *  SR_SemanticGraphImpl.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#ifndef __SR_SEMANTICGRAPHIMPL_H
21#define __SR_SEMANTICGRAPHIMPL_H
22
23
24
25#include "SR_SemprocPrefix.h"
26#include "SR_SemanticGraph.h"
27#include "pstdio.h"
28#include "ptypes.h"
29#include "ESR_ReturnCode.h"
30
31/**
32 * SREC stuff
33 */
34#include "srec_context.h"
35
36
37/**
38 * SR_SemanticGraph implementation.
39 */
40typedef struct SR_SemanticGraphImpl_t
41{
42  /**
43   * Interface functions that must be implemented.
44   */
45  SR_SemanticGraph Interface;
46
47  /**
48   * Input labels are  words in a spoken utterance.
49   * These words are the SAME as those used by the recogizer graph, so I want to
50   * reuse that data rather than duplicate it.
51   * Withing this module, ilabls are constant... they are owned and may only be changed
52   * externally by AddWordToSlot() for example
53   */
54  wordmap* ilabels;
55
56  /**
57   * The word map containing the actual scripts. The index of teh script in the wordmap
58   * corresponds to the index found in the graph minus the script_olabel_offset
59   */
60  wordmap* scripts;
61
62  /**
63   * Integer offset for referencing script output labels when mapping between
64   * integer ids, and their respective string values.
65   */
66  labelID script_olabel_offset;     /* starts at SEMGRAPH_SCRIPT_OFFSET */
67
68  /**
69   * Output labels for end of scope markers. These are of the form
70   * "rule_name}"
71   * This is pretty static doesen't change
72   */
73  wordmap* scopes_olabels;
74
75  /**
76   * Integer offset for referencing end of scope output labels when mapping between
77   * integer ids, and their respective string values.
78   */
79  size_t scopes_olabel_offset;     /* starts at SEMGRAPH_SCOPE_OFFSET */
80
81  /**
82   * Double linked list of arcs forming graph
83   * ilables are integers which map to words in the word maps
84   * olabels are integers which map to words in the word maps
85   */
86  arc_token* arc_token_list;
87
88  /**
89   * The arc where additional words may be added on to (see addWordToSlot)
90   * Only Root slot supported for now.
91   */
92  arc_token* arc_token_insert_start;
93
94  /**
95   * The end node for dynamically added words.
96   */
97  arc_token* arc_token_insert_end;
98
99  /**
100   * Free list of arcs for dynamic add word to slot.
101   */
102  arc_token* arc_token_freelist;
103
104  /**
105   * The number of arcs in the graph
106   */
107  arcID arc_token_list_len;
108
109  /* slot addition */
110  arc_token* arcs_for_slot[MAX_NUM_SLOTS];
111
112}
113SR_SemanticGraphImpl;
114
115/* internal functions */
116arc_token* arc_tokens_find_ilabel(arc_token* base, arc_token* arc_token_list, wordID wdid);
117arc_token* arc_tokens_get_free(arc_token* base, arc_token** arc_token_freelist);
118
119/**
120 * Default implementation.
121 */
122SREC_SEMPROC_API ESR_ReturnCode SR_SemanticGraph_Destroy(SR_SemanticGraph* self);
123/**
124 * Default implementation.
125 */
126SREC_SEMPROC_API ESR_ReturnCode SR_SemanticGraph_Load(SR_SemanticGraph* self, wordmap* ilabels, const LCHAR* basename, int num_words_to_add);
127/**
128 * Default implementation.
129 */
130SREC_SEMPROC_API ESR_ReturnCode SR_SemanticGraph_Unload(SR_SemanticGraph* self);
131/**
132 * Default implementation.
133 */
134SREC_SEMPROC_API ESR_ReturnCode SR_SemanticGraph_Save(SR_SemanticGraph* self, const LCHAR* filename, int version_number);
135/**
136 * Default implementation.
137 */
138SREC_SEMPROC_API ESR_ReturnCode SR_SemanticGraph_AddWordToSlot(SR_SemanticGraph* self, const LCHAR* slot, const LCHAR* word, const LCHAR* tag, const ESR_BOOL maybeMultiMeaning);
139/**
140 * Default implementation.
141 */
142SREC_SEMPROC_API ESR_ReturnCode SR_SemanticGraph_Reset(SR_SemanticGraph* self);
143
144#endif /* __SR_SEMANTICGRAPHIMPL_H */
145