Edinburgh Speech Tools  2.1-release
wagonint.cc
Go to the documentation of this file.
1 /*************************************************************************/
2 /* */
3 /* Centre for Speech Technology Research */
4 /* University of Edinburgh, UK */
5 /* Copyright (c) 1996,1997 */
6 /* All Rights Reserved. */
7 /* */
8 /* Permission is hereby granted, free of charge, to use and distribute */
9 /* this software and its documentation without restriction, including */
10 /* without limitation the rights to use, copy, modify, merge, publish, */
11 /* distribute, sublicense, and/or sell copies of this work, and to */
12 /* permit persons to whom this work is furnished to do so, subject to */
13 /* the following conditions: */
14 /* 1. The code must retain the above copyright notice, this list of */
15 /* conditions and the following disclaimer. */
16 /* 2. Any modifications must be clearly marked as such. */
17 /* 3. Original authors' names are not deleted. */
18 /* 4. The authors' names are not used to endorse or promote products */
19 /* derived from this software without specific prior written */
20 /* permission. */
21 /* */
22 /* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */
23 /* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
24 /* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
25 /* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */
26 /* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
27 /* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
28 /* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
29 /* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
30 /* THIS SOFTWARE. */
31 /* */
32 /*************************************************************************/
33 /* Author : Alan W Black */
34 /* Date : October 1997 */
35 /*-----------------------------------------------------------------------*/
36 /* Some high level functions used to interpret CART trees */
37 /* */
38 /*=======================================================================*/
39 #include <cstdlib>
40 #include <iostream>
41 #include <fstream>
42 #include <cstring>
43 #include "EST_cutils.h"
44 #include "EST_Token.h"
45 #include "EST_Wagon.h"
46 
47 using namespace std;
48 
49 int wagon_ask_question(LISP question, LISP value)
50 {
51  const char *str_oper = wgn_ques_oper_str(question);
52 
53  if (streq("is",str_oper))
54  {
55  if (streq(get_c_string(value),
56  get_c_string(wgn_ques_operand(question))))
57  return TRUE;
58  else
59  return FALSE;
60  }
61  else if (streq("=",str_oper))
62  if (get_c_float(value) == get_c_float(wgn_ques_operand(question)))
63  return TRUE;
64  else
65  return FALSE;
66  else if (streq("<",str_oper))
67  if (get_c_float(value) < get_c_float(wgn_ques_operand(question)))
68  return TRUE;
69  else
70  return FALSE;
71  else if (streq(">",str_oper))
72  if (get_c_float(value) > get_c_float(wgn_ques_operand(question)))
73  return TRUE;
74  else
75  return FALSE;
76  else if (streq("matches",str_oper))
77  {
78  EST_Regex rgx(get_c_string(wgn_ques_operand(question)));
79  if (EST_String(get_c_string(value)).matches(rgx))
80  return TRUE;
81  else
82  return FALSE;
83  }
84  else if (streq("in",str_oper))
85  if (siod_member_str(get_c_string(value),
86  wgn_ques_operand(question)) != NIL)
87  return TRUE;
88  else
89  return FALSE;
90  else
91  {
92  cerr << "WAGON: unknown question operator: \"" <<
93  str_oper << "\"\n";
94  siod_error();
95  }
96  // not reached, just for the compiler
97  return FALSE;
98 }
int wagon_ask_question(LISP question, LISP value)
Definition: wagonint.cc:49
float get_c_float(LISP x)
Definition: slib.cc:1858
#define siod_error()
Definition: siod.h:211
A Regular expression class to go with the CSTR EST_String class.
Definition: EST_Regex.h:56
#define NIL
Definition: siod_defs.h:92
#define wgn_ques_oper_str(X)
Definition: EST_Wagon.h:286
#define streq(X, Y)
Definition: EST_cutils.h:57
const char * get_c_string(LISP x)
Definition: slib.cc:638
#define FALSE
Definition: EST_bool.h:119
#define wgn_ques_operand(X)
Definition: EST_Wagon.h:287
EST_String
#define TRUE
Definition: EST_bool.h:118
LISP siod_member_str(const char *key, LISP list)
Definition: siod.cc:167