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
wagon_ask_question(LISP question,LISP value)47 int wagon_ask_question(LISP question, LISP value)
48 {
49 const char *str_oper = wgn_ques_oper_str(question);
50
51 if (streq("is",str_oper))
52 {
53 if (streq(get_c_string(value),
54 get_c_string(wgn_ques_operand(question))))
55 return TRUE;
56 else
57 return FALSE;
58 }
59 else if (streq("=",str_oper))
60 if (get_c_float(value) == get_c_float(wgn_ques_operand(question)))
61 return TRUE;
62 else
63 return FALSE;
64 else if (streq("<",str_oper))
65 if (get_c_float(value) < get_c_float(wgn_ques_operand(question)))
66 return TRUE;
67 else
68 return FALSE;
69 else if (streq(">",str_oper))
70 if (get_c_float(value) > get_c_float(wgn_ques_operand(question)))
71 return TRUE;
72 else
73 return FALSE;
74 else if (streq("matches",str_oper))
75 {
76 EST_Regex rgx(get_c_string(wgn_ques_operand(question)));
77 if (EST_String(get_c_string(value)).matches(rgx))
78 return TRUE;
79 else
80 return FALSE;
81 }
82 else if (streq("in",str_oper))
83 if (siod_member_str(get_c_string(value),
84 wgn_ques_operand(question)) != NIL)
85 return TRUE;
86 else
87 return FALSE;
88 else
89 {
90 cerr << "WAGON: unknown question operator: \"" <<
91 str_oper << "\"\n";
92 siod_error();
93 }
94 // not reached, just for the compiler
95 return FALSE;
96 }
97