forked from micro222/chatbot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
1228 lines (1024 loc) · 30 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "db.h"
#include "handle.h"
#include "time.h"
#include "hashtable.h"
#define TRUE 1
#define FALSE 0
#define MAX_WORDS 40
#define MAX_LETTERS 20
#define DEBUG TRUE
// Global Variables
char user_input[80];
char wholeline[80];
int number_of_words;
char words[MAX_WORDS][MAX_LETTERS]; //
char current_user_name[20]="unknown";
int current_user_id = 0;
int gender_code = 0;
int code;
int result;
char value[20];
char key[20];
typedef struct test {
char* line[80];
char* template2[80];
char* function_name[80];
int parameter1;
int parameter2;
int parameter3;
//int code;
} template_info_type;
// char current_time[MAX_STRING_LEN];
// char current_time[80];
int current_time;
// Experimental
#if 0
typedef struct {
char* input[80];
char* words[80][80];
char* first_name[80];
int gender_code;
} user_info_type;
#endif
// Prototypes
void get_string(void);
void parse(void);
int isword(char*);
int is_nonsense_word(char*);
int isconsonant(char);
int isvowel(char);
void handle_help(void);
int tokenize(char*, char*, char);
int separate_words(char*, char[MAX_WORDS][MAX_LETTERS]);
int template_search(char*, template_info_type*);
int check_gender_by_name(char*);
//void get_time(char*);
int get_time(void);
//int isvalidname(char*);
//-------------------------------------------------------
int main(void) {
char out[MAX_WORDS][MAX_LETTERS];
int n;
int result;
int same, token;
template_info_type template_info;
char key[80];
printf("type 'help' for a list of sentences I understand\r\n");
// THE MAIN LOOP
while(1) {
printf(">"); // user prompt
get_string(); // get user input
parse(); // separate the sentence into individual words
#if 1
// word substitutions
for(n=1; n<=number_of_words; n++) {
//if (strcmp(words[n],"does")==0) strcpy(words[n], "do");
if (strcmp(words[n],"has")==0) strcpy(words[n], "have");
if (strcmp(words[n],"are")==0) strcpy(words[n], "is");
if (strcmp(words[n],"wants")==0)strcpy(words[n], "want");
if (strcmp(words[n],"feels")==0)strcpy(words[n], "feel");
if (strcmp(words[n],"likes")==0)strcpy(words[n], "like");
if (strcmp(words[n],"i")==0) strcpy(words[n], current_user_name);
if (strcmp(words[n],"u")==0) strcpy(words[n], "you");
// if (strcmp(words[n],"you")==0) strcpy(words[n], "bot");
if (strcmp(words[n],"am")==0) strcpy(words[n], "is");
if (strcmp(words[n],"an")==0) strcpy(words[n], "a");
}
#endif
//---------------
#if 0
// Work in progress
// This is the code that makes use of template_search()
code = template_search(user_input, &template_info);
printf("\ncode: %d, template: %s, ", code, template_info.template2);
printf("\r\nfunction: %s\r", template_info.function_name);
if(template_info.parameter1 > 0) {
printf("\np1: %d\r\n", template_info.parameter1);
}
if(template_info.parameter2 > 0) {
printf("\np2: %d\r\n\n\n", template_info.parameter2);
}
continue;
#endif
//----------------
#if 0
// Does the user input = the template? If so, there are no wild cards
same = FALSE;
for(n=1; n<=number_of_words; n++) {
if(strcmp(words[n], out[n])==0) {
same=TRUE;
break;
}
}
#endif
//------------------
#if 0
// Experimental
token=0;
if(same==TRUE) {
if(strcmp(user_input, "what time is it")==0) token = 1;
else if(strcmp(user_input, "what is your name")==0) token = 2;
else if(strcmp(user_input, "hi")==0) token = 3;
else if(strcmp(user_input, "how are you")==0) token = 4;
else if(strcmp(user_input, "i am here")==0) token = 5;
}
switch(token) {
case 1:
printf("i dont have a watch\r\n ");
break;
case 2:
printf("joe king\r\n ");
break;
case 3:
printf("bye \r\n");
break;
case 4:
printf("could be worse \r\n");
break;
case 5:
printf("where is here? \r\n");
break;
}
//printf("%d ", token);
#endif
//----------------
#if 0
// experimenting with delays
current_time = get_time();
while (get_time() < current_time +5);
//printf("time: %d", current_time);
#endif
//------------------
// The main sentence processing starts here.
// Soon this will be replaced by using the templates in templates2.txt
if(number_of_words==1 &&
strcmp(words[1], "help")==0) {
handle_help();
}
// Log in?
// my name is ___
if(number_of_words==4 &&
strcmp(words[1],"my")==0 &&
strcmp(words[2],"name")==0 &&
strcmp(words[3],"is")==0) {
handle_login(words[4]);
continue;
}
if(number_of_words==1 &&
strcmp(words[1], "hi")==0) {
handle_greetings();
continue;
}
if(number_of_words==1 &&
strcmp(words[1], "hey")==0) {
handle_greetings();
continue;
}
if(number_of_words==1 &&
strcmp(words[1], "hello")==0) {
handle_greetings();
continue;
}
#if 0
// Logged in? If not, go no further. This can be disabled for testing purposes
if(current_user_id == 0) {
printf("what is your name?\r\n");
continue;
}
#endif
// - - - - MUST BE LOGGED IN TO GET PAST THIS POINT - - - - - - - - - - - - - - - - - -
#if 0 // this code is a mess
// Determine gender from the first name
// (known person) is male
if(db_get_id(words[1]) !=0 &&
strcmp(words[2],"is")==0 &&
strcmp(words[3],"male")==0 ) {
sprintf(key, "#%d > gender", current_user_id);
if(strcmp(words[1], current_user_name) == "unknown")
gender_code = 1;
db_add_pair(key, "male");
continue;
}
#endif
// my gender is male
if(number_of_words == 4 &&
strcmp(words[1],"my")==0 &&
strcmp(words[2],"gender")==0 &&
strcmp(words[3],"is")==0 &&
strcmp(words[4],"male")==0 ) {
sprintf(key, "#%d > gender", current_user_id);
gender_code = 1;
db_add_pair(key, "male");
continue;
}
// (known person) is female
if(db_get_id(words[1]) !=0 &&
strcmp(words[2],"is")==0 &&
strcmp(words[3],"female")==0 ) {
sprintf(key, "#%d > gender", current_user_id);
if(strcmp(words[1],current_user_name)== "unknown")
gender_code = 2;
db_add_pair(key, "female");
continue;
}
// my gender is female
if(number_of_words==4 &&
strcmp(words[1],"my")==0 &&
strcmp(words[2],"gender")==0 &&
strcmp(words[3],"is")==0 &&
strcmp(words[4],"female")==0 ) {
sprintf(key, "#%d > gender", current_user_id);
gender_code = 2;
db_add_pair(key, "female");
continue;
}
// CLASS (SUBSET OF)
// what is ___
if(number_of_words==3 &&
strcmp(words[1],"what")==0 &&
strcmp(words[2],"is")==0) {
handle_class_question(words[3]);
continue;
}
// what are ___
if(number_of_words==3 &&
strcmp(words[1],"what")==0 &&
strcmp(words[2],"are")==0) {
handle_class_question(words[3]);
continue;
}
// what is a ___
if(number_of_words==4 &&
strcmp(words[1],"what")==0 &&
strcmp(words[2],"is")==0 &&
strcmp(words[3],"a")==0) {
handle_class_question(words[4]);
continue;
}
// this needs to be placed before "___ is ___" and after "what is ___"
if(number_of_words==3 &&
strcmp(words[2],"is")==0) {
handle_attribute_statement(words[1],words[3]);
continue;
}
// a __ is a __
// ex: a cat is an animal
if(number_of_words==5 &&
strcmp(words[1],"a")==0 &&
strcmp(words[3],"is")==0 &&
strcmp(words[4],"a")==0
) {
handle_class_statement(words[2],words[5]);
continue;
}
if(number_of_words==4 &&
strcmp(words[2],"is")==0 &&
strcmp(words[3],"a")==0) {
handle_class_statement(words[1],words[4]);
continue;
}
if(number_of_words==3 &&
strcmp(words[2],"is")==0 ) {
handle_class_statement(words[1],words[3]);
continue;
}
// - - - - - - COLORS - - - - - - - - - - - - - - - -
//
// what color is ___
if(number_of_words==4 &&
strcmp(words[1],"what")==0 &&
strcmp(words[2],"color")==0&&
strcmp(words[3],"is")==0) {
handle_color_question(words[4]);
continue;
}
// is ___ <color>?
if(number_of_words==3 &&
strcmp(words[1],"is")==0 &&
db_root_check(words[3],"color")==FOUND) {
handle_color_confirmation_question(words[2],words[3]);
continue;
}
// ___ is <color>
// conditions: 3 words, middle word is "is"
if(number_of_words==3 &&
strcmp(words[2],"is")==0 &&
db_root_check(words[3],"color")==FOUND) {
handle_color_statement(words[1],words[3]);
continue;
}
// - - - - - - - - - - - - - - - - - - - - - -
// LOCATION
// where is ___
if(number_of_words==3 &&
strcmp(words[1],"where")==0 &&
strcmp(words[2],"is")==0) {
handle_location_question(words[3]);
continue;
}
// - - - - - - - - - - - - - - - - - - - - - -
// ABILITY
// can <subject> <action>
if(number_of_words==3 &&
strcmp(words[1],"can")==0 ) {
handle_ability_question(words[2],words[3]);
continue;
}
// - - - - - - - - - - - - - - - - - - - - - -
// rating
// Template: do you like <subject>
// Example: do you like beer
// else if(number_of_words==4 && strcmp(words[1],"do")==0 && strcmp(words[2],"you")==0 && strcmp(words[3],"like")==0 ){
// handle_rating_question();
// }
// Template: __ like __
// Example: i like beer
if(number_of_words==3 &&
strcmp(words[2],"like")==0) {
handle_rating_statement(words[1], words[3], "7");
continue;
}
// Template: <person> hate __
// Example: i hate beer
if(number_of_words==3 &&
strcmp(words[2],"hate")==0) {
handle_rating_statement(words[1], words[3], "0");
continue;
}
// <creature> love ___
// conditions: 3 words, middle word is "love"
if(number_of_words==3 &&
strcmp(words[2],"love")==0) {
handle_rating_statement(words[1], words[3], "10");
continue;
}
// ___ dont like ___
if(number_of_words==4 &&
strcmp(words[2],"dont")==0 &&
strcmp(words[3],"like")==0) {
handle_rating_statement(words[1], words[3], "3");
continue;
}
// Template: does <person> like <subject>
// Example: does fred like beer
if(number_of_words==4 &&
strcmp(words[1],"does")==0 &&
strcmp(words[3],"like")==0 ) {
handle_rating_question(words[2], words[4]);
continue;
}
// Template: list <class>
// Example: list action
if(number_of_words==2 &&
strcmp(words[1],"list")==0) {
handle_list_question(words[2]);
continue;
}
// - - - - - - - - - - - - - - - - - - - - - -
// "what is my name"
if(number_of_words==4 &&
strcmp(words[1],"what")==0 &&
strcmp(words[2],"is")==0 &&
strcmp(words[3],"my")==0 &&
strcmp(words[4],"name")==0) {
printf("%s\n",current_user_name);
continue;
}
// "what is my gender"
if(number_of_words==4 &&
strcmp(words[1],"what")==0 &&
strcmp(words[2],"is")==0 &&
strcmp(words[3],"my")==0 &&
strcmp(words[4],"gender")==0) {
switch(gender_code) {
case 1:
printf("male\n");
break;
case 2:
printf("female\n");
break;
case 0:
case 3:
printf("I don't know\n");
break;
}
continue;
}
// "say my name"
if(number_of_words==3 &&
strcmp(words[1],"say")==0 &&
strcmp(words[2],"my")==0 &&
strcmp(words[3],"name")==0) {
printf("%s\n",current_user_name);
continue;
}
// Log out
if(number_of_words==1 &&
strcmp(words[1],"bye")==0) {
printf("%talk to you later %s\r\n\r\n",current_user_name);
current_user_name[20]="unknown";
current_user_id = 0;
gender_code = 0;
continue;
}
// Get ID number
if(number_of_words==1 &&
strcmp(words[1],"id")==0) {
printf("%d\n",current_user_id);
continue;
}
// Get gender code
if(number_of_words==1 &&
strcmp(words[1],"g")==0) {
printf("%d\n",gender_code);
continue;
}
// Single word
if(number_of_words==1) {
sprintf(key, "%s > class", words[1]); // assemble a key
if(db_lookup(key, value) == FOUND) {
printf("That's a %s\n", value);
continue;
}
if(isword(words[1])==0) {
printf("%s is in my dictionary, but I'm not familiar with it\n", words[1]);
} else
printf("That's not in my dictionary\n");
continue;
}
// Nothing typed?
if(number_of_words==0) {
printf("You didn't type anything..\n");
continue;
}
// Default
printf("I'm not familiar with that kind of sentence\n");
continue;
// - - - - - -
// experimental
#if 0
switch(F) {
case:
HELP handle_help();
break;
case:
handle_ability_question();
break;
case:
handle_attribute_statement();
break;
case:
handle_class_question();
break;
case:
handle_class_statement();
break;
case:
handle_ability_question();
break;
case:
handle_color_confirmation_question();
break;
case:
handle_color_question();
break;
case:
handle_color_statement();
break;
case:
handle_def_question();
break;
case:
handle_def_statement();
break;
case:
handle_list_question();
break;
case:
handle_location_question();
break;
case:
handle_login();
break;
case:
handle_rating_question();
break;
case:
handle_rating_statement();
break;
}
#endif
// - - - - - -
} // main loop
return 0;
} // main
//-----------------------------------------------------------
void get_string(void) {
int position;
for(position = 0; position <= 78; position++) {
user_input[position] = getchar();
if(user_input[position]==10)break; // CR
if(user_input[position]==13)break; // LF
}
user_input[position] = 0;
}
//--------------------------------------------------------------
void parse(void) {
// input: user_input
// output: words, number_of_words
int position = 0;
int letter_position;
int word_position;
//while(1);
for(word_position=1; word_position < MAX_WORDS; word_position++) {
for(letter_position = 0; letter_position < MAX_LETTERS; letter_position++) {
// End of user input?
if(user_input[position]==0 || position >= 80) {
words[word_position][letter_position] = 0;
number_of_words = word_position;
return;
}
//end of word?
if(user_input[position]==' ') {
words[word_position][letter_position] = 0; // terminate the word
letter_position = 0; // probably not needed
position++; // skip over the space
break;
}
//
words[word_position][letter_position] = user_input[position];
position++;
}
}
}
//------------------------------------------------------------------
int isvowel(char c1) {
char vowels[6]="aeiouy";
int i;
for(i=0; i<6; i++) {
if(c1 == vowels[i])return 0;
}
return 1;
}
//---------------------------------------
int isconsonant(char c1) {
char consonants[20]="bcdfghjklmnpqrstvwxz";
int i;
for(i=0; i<20; i++) {
if(c1 == consonants[i]) return 0;
}
return 1;
}
//-----------------------------------------------------------------------
int is_nonsense_word(char* s1) {
//
// curently has trouble with: you, crackpot,apple,substance
//
//
// 3 vowels in a row?
int i,inarow;
int j;
char *list_nonsense[] = {"ch", "gh", "sc", "sp", "th", "ck", "pp", "tt"};
inarow=0;
for(i=0; i<80-3; i++) {
if(user_input[i]==0) break;
if(isvowel(user_input[i])==0) inarow++;
else inarow=0;
if(inarow>=4) break;
}
if(inarow>=3)printf(" 3 vowels in a row \n");
// replace all occurances of CH GH SC SP TH CK PP ST with vowels
for(i=0; i<80-3; i++) {
if(user_input[i]==0) break;
for (j=0; j<sizeof(list_nonsense); j++) {
if(strncmp(&user_input[i], "ch", 2))
strncpy(&user_input[i], "aa", 2);
}
}
// 3 consonants in a row?
inarow=0;
for(i=0; i<80-3; i++) {
if(user_input[i]==0) break;
if(isconsonant(user_input[i])==0) inarow++;
else inarow=0;
if(inarow>=4) break;
}
if(inarow>=4)printf(" that's jiberish\n");
}
//--------------------------------------------------------
int isword(char*word_to_lookup) {
FILE *general;
int result = 1;
char word_from_list[80];
char *status;
// open word list
general = fopen("word100k.txt","r");
if(general == NULL) {
printf("fopen failed while trying to open word100k.txt\n");
}
while(1) {
status = fgets(word_from_list,40,general);
if (status==0)break;
// remove the newline character
word_from_list[strlen(word_from_list)-1] = '\0';
if (strcmp(word_to_lookup, word_from_list) == 0) {
result = 0;
break;
}
}// end of while
fclose(general);
return result;
}
// --------------------------------------
void handle_login(char*name) {
int result, i;
int known=FALSE;
int new = TRUE;
char first_name[20], id_string[20];
char s2[20], value[20];
char key[80];
int id_number;
// Proceedure
//
// 1 is the person the current user?
// 2 is this person known? (search for first name in database)
// 3 if not known, create new entry in database
// 4 update user_id, user_name, gender)
//
////////////////////////////////////////////////////////////
// Step 1: check if already current user
if(strcmp(name, current_user_name)==0) {
printf("You told me that already\n");
known=TRUE;
return;
}
// Step #2
id_number = db_get_id(name);
if(id_number != 0) {
known=TRUE;
new = FALSE;
// get gender
sprintf(key,"#%d > gender", id_number);
result = db_lookup(key, value);
if(result != FOUND) {
gender_code=0;
}
if(strcmp(value, "male")==0) {
gender_code=1;
}
if(strcmp(value, "female")==0) {
gender_code=2;
}
} else {
known=FALSE;
}
// Step 3: add user to database
if(known==FALSE) {
// Get an id number
id_number = db_next_available_id();
// Add the following to the database
// #1 > class: person
// #1 > firstname:bob
// #1 > gender:male
snprintf (id_string, sizeof(id_string), "%d",id_number);
sprintf(key, "#%s > class", id_string);
db_add_pair(key, "person");
sprintf(key,"#%s > firstname", id_string);
db_add_pair(key, name);
sprintf(key,"#%s > gender", id_string);
gender_code = check_gender_by_name(name);
switch(gender_code) {
case 1:
db_add_pair(key, "male");
break;
case 2:
db_add_pair(key, "female");
}
known=TRUE;
new = TRUE;
}
// Step 4:
strcpy(current_user_name, name);
current_user_id = id_number;
if(new == TRUE) {
printf("hello %s\n", current_user_name);
} else {
printf("hi %s\n", current_user_name);
}
}
//-------------------------------------------------------
/*
int isvalidname(char* s1){
// valid characters are a-z 0-1 _
if ((isalpha(s1)==0) && (isdigit(s1)==0) && s1!='_'){
return 0; // not valid
}
else return 1; // is valid
}
*/
//--------------------------------------------------
void handle_help(void) {
printf("I can handle the following sentences\r\n\r\n");
printf(" my name is ___\n");
printf(" what is my name\n");
printf(" what is my gender\n");
printf(" I am male\n");
printf(" I am female\n");
printf(" my gender is male\n");
printf(" my gender is female\n");
printf(" say my name\n");
printf(" what color is ___, ex: what color is grass\n");
printf(" is <subject> <color>, ex: is grass green\n" );
printf(" where is <object>\n" );
printf(" can ___ ___, ");
printf(" what are ___\n" );
printf(" what is a ___\n" );
printf(" what is ___\n" );
printf(" a <object> is a ___, ex: a cat is an animal\n" );
printf(" ___ is <color>\n" );
printf(" ___ like ___, ex: I like pizza\n" );
printf(" ___ hate ___\n" );
printf(" ___ love ___\n" );
printf(" ___ dont like ___\n" );
printf(" do you like ___\n" );
//printf("who am i, ");
//printf("i am ___\r\n");
printf("bye\r\n");
//printf("is ___ ___, ");
//printf("what is ___, ");
//printf("have you heard of ___, ");
//printf("___ is ___\r\n");
//printf("can ___ ___, ");
//printf("do ___ ___, ");
//printf("___ can ___\r\n");
//printf("___ like ___, ");
//printf("do ___ like ___\r\n");
//printf("___ hates ___, ");
//printf("do ___ hate ___\r\n");
//printf("___ is in ___, ");
//printf("where is ___\r\n");
//printf("how old is/are ___\r\n");
//printf("do ___ feel ___, ");
//printf("___ feels ___\r\n");
//printf("do ___ want ___, ");
//printf("___ want _\r\n");
//printf("do ___ have ___\r\n");
//printf("what is the ___ of ___, ___ is the ___ of___\r\n");
//printf("what time is it\r\n");
//printf("lookup ___\r\n");
// continue;
}
//-------------------------------------------------------------
// Experimental. Not in use.
int tokenize(char* in_string, char* word_array, char delimiter) {
// input: in_string
// output: words, number_of_words
int position = 0;
int letter_position;
int word_position;
for(word_position=1; word_position < MAX_WORDS; word_position++) {
for(letter_position = 0; letter_position < MAX_LETTERS; letter_position++) {
// End of in_string?
if(in_string[position]==0 || position >= 80) {
//// word_array[word_position][letter_position] = 0;
return word_position;
}
//end of word?
if(in_string[position] == delimiter) {
//// word_array[word_position][letter_position] = 0; // terminate the word
letter_position = 0; // probably not needed
position++; // skip over the delimiter
break;
}
//// word_array[word_position][letter_position] = in_string[position];
position++;
}
}
}
// new function for chat 10
// compares user input with a sentence template
//
// example:
// user input: what color is grass?
// template : what color is *, color_question, 4
//
// the old way:
// else if(number_of_words==4 && strcmp(words[1],"what")==0 && strcmp(words[2],"color")==0&& strcmp(words[3],"is")==0){
// handle_color_question(words[4]);
// number of words: 4
// word 1: what
// word 2: color
// word 3: is
// function: color_question()
// parameter 1: word 4
// new proceedure:
// parse template by comma
// parse template sentence by space
// compare specified words in user sentence with template sentence
/*
void template_search (void)
open template.txt
outer loop
read template
inner loop
tokenize(template, token_array, ',');
tokenize(token_array[0], word_array, ' ');
// do the words match?
for(i=0, i<WORD_MAX, i++){
if(words!=word_array[i]) break;
if(w=='*') continue;
}
*/
//--------------------------------------------------
// This partialy works, but is not currently in use
// TEMPLATE SEARCH
//
// inputs
// what the user typed
//
// returns
// the matching template
// the result code
// 1) opens the tempate file
// 2) gets a line
// 3) extracts the template
// 4) checks the template to see if it's a match
//int template_search(char*user, char*template2)
//int template_search(char*user, char out[MAX_WORDS][MAX_LETTERS]){
int template_search(char*user, template_info_type* template_info) {
#define TEMPLATE_LINE_LENGTH 120
FILE *template_file_handle;
int line_position;
char *status;
char line[TEMPLATE_LINE_LENGTH];