-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBdict.c
123 lines (94 loc) · 2.54 KB
/
Bdict.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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "bt/inc/btree.h"
#include <ncurses.h>
#include "model_lib.h"
#include "extio.h"
#define MAX_LEN_WORD 40
#define MAX_LEN_MEAN 2000
#define MAX 2000
void findSuggestion(BTA *soundExTree, char *word) {
char suggestion_str[10][MAX_LEN_WORD];
int size = suggestion(soundExTree, word, suggestion_str);
if (size > 0)
{
printf("Do you mean: \n");
for (int i = 0; i < size; i++)
{
printf("%s\n",suggestion_str[i] );
}
}
else printf("No suggetion found\n");
}
void searchWord(BTA *dict, BTA *soundExTree, char *word, char *mean) {
int val;
val = findWord(dict, word, mean);
if(val == 1) printf("%s\n", mean);
else findSuggestion(soundExTree, word);
}
void search(BTA *dict, BTA *soundExTree) {
char result[MAX_LEN_WORD];
char word[MAX_LEN_WORD];
char mean[MAX_LEN_MEAN];
word[0] = '\0';
int mode;
mode = get_word(word);
if(mode == 2) {
int val = autoComplete(soundExTree,word, result);
if (val > 0) {
printf("%s\n", result);
getchar();
searchWord(dict, soundExTree, result, mean);
}
else {
printf("%s\n",word);
getchar();
searchWord(dict, soundExTree, word, mean);
}
}
if (mode == 1)
{
printf("%s\n",word);
getchar();
searchWord(dict, soundExTree, word, mean);
}
}
void add(BTA *dict, BTA *soundExTree) {
char word[MAX_LEN_WORD];
char mean[MAX_LEN_MEAN];
printf("Word: \n");
int checkEmptyWord = getStr(word);
if(checkEmptyWord == 0) {
printf("Exit\n");
return;
}
int exist = findWord(dict, word, mean);
if(exist == 1) printf("Word '%s' exist \n", word);
else {
printf("Meaning: \n");
while(getStr(mean) == 0);
int adddict = addToDict(dict, word, mean);
int addSound = addToSoundExTree(soundExTree, word);
if (adddict == 0 ) printf("Added '%s' to dictionary\n",word);
else printf("Insertion error to dictionary\n");
if(addSound == 0 ) printf("Added '%s' to soundExTree\n",word);
else printf("Insertion error to soundExTree\n");
}
}
void delete(BTA *dict, BTA *soundExTree) {
char word[MAX_LEN_WORD];
char mean[MAX_LEN_MEAN];
printf("Delete word: ");
getStr(word);
int exist = findWord(dict, word, mean);
if (exist == 0) printf("Word not found\n");
else {
int deleteDict = deleteInDict(dict, word);
int deleteSoundExTree = deleteInSoundExTree(soundExTree, word);
if(deleteDict == 0) printf("%s deleted in dictionary\n",word);
else printf("Delete in dictionary error\n");
if (deleteSoundExTree == 0) printf("%s deleted in soundExTree\n",word );
else printf("Delete in soundExTree error\n");
}
}