Commit de5faa60f5039efbe9081710c74127b66d1d5116

Authored by bjeanlou
1 parent 0bc3d1ad

Update isEnd

Showing 2 changed files with 34 additions and 23 deletions   Show diff stats
... ... @@ -41,30 +41,34 @@ bool is_followed(tree t){
41 41 }
42 42 return false;
43 43 }
44   -bool is_end(tree t){
45   - return t->isEnd;
46   -}
  44 +
  45 +bool is_end(tree t){return t->isEnd%2;}
  46 +bool ends_with_apostrophe(tree t){return (t->isEnd/4)%2;}
  47 +
  48 +bool is_common_end(tree t){return !(t->isEnd/4);}
  49 +bool is_proper_end(tree t){return (t->isEnd/4)%2;}
  50 +bool is_acronyme_end(tree t){return t->isEnd/8;}
47 51 int hash(char c){
48   - //needs to check c wether isalpha or '\''
49   - if(c='\'')
50   - return 0;
51   - return c%32;
  52 + //needs to check c wether isalpha
  53 + return c%32-1;
52 54 }
53   -
54   -
  55 +bool is_proper_end(tree);//if true 1st letter is upper ;//if true all letters are lower
55 56  
56 57  
57 58  
58 59 //loading functions
59 60 bool addto_tree(tree t,string s){
60   - //recursive, when called : set isIn to true, and reset index
  61 + //recursive, need to check all letter in s are alpha or '\'s'
61 62 //return wether s is already in t or not
62 63 bool ret;
63 64 if(s[0]=='\0'){
64   - ret=t->isEnd;
  65 + ret=is_end(t);
65 66 t->isEnd=true;
66 67 return ret;
67 68 }
  69 + if(s[0]=='\''){
  70 +
  71 + }
68 72 if(t->next[hash(s[0])]==NULL){
69 73 t->next[hash(s[0])]=make_node(s[0],false);
70 74 addto_tree2(t->next[hash(s[0])],s+1);
... ... @@ -80,10 +84,8 @@ void addto_tree2(tree t,string s){
80 84 t->isEnd=true;
81 85 return;
82 86 }
  87 + if(s[0]=='\'')
83 88 t->next[hash(s[0])]=make_node(s[0],false);
84 89 addto_tree2(t->next[hash(s[0])],s+1);
85 90 }
86 91  
87   -void loadfrom_file(tree,FILE*){}
88   -void loadfrom_keyboard(tree){}
89   -
... ...
... ... @@ -6,26 +6,35 @@
6 6 #include <string.h>
7 7 #include <stdbool.h>
8 8  
9   -#define NBCHAR 27 //A-Z + '
  9 +#define NBCHAR 26 //A-Z
10 10  
11 11  
12 12 typedef struct _node node, *tree;
13 13 struct _node{
14 14 char letter;
15   - bool isEnd;
  15 + char isEnd;
  16 + //0 no,1 yes,+2 if ends with 's
  17 + //+4if proper, +8if allUpper
16 18 node* next[NBCHAR];
17 19 };
18 20  
19   -tree make_empty_tree();
20   -node* make_empty_node();
21   -node* make_node(char,bool);
22   -void delete_tree(tree);
  21 +tree make_empty_tree();//create a null node*
  22 +node* make_empty_node();//malloc a node and initialize it
  23 +node* make_node(char,bool);//id
  24 +void delete_tree(tree);//free(tree) and delete tree on all t->next
  25 +
  26 +bool is_empty(tree);//==NULL
  27 +bool is_followed(tree);//if true tree has following letters
  28 +
  29 +bool is_end(tree);//if true word can end here
  30 +bool is_proper_end(tree);//if true 1st letter is upper
  31 +bool is_common_end(tree);//if true all letters are lower
  32 +bool is_acronyme_end(tree);//if true all letters are upper
  33 +bool ends_with_apostrophe(tree);//if true word can be word's
23 34  
24   -bool is_empty(tree);
25   -bool is_end(tree);
26   -bool is_followed(tree);//tells if tree has following letters
27 35 int hash(char);//need to check if isalpha
28 36  
  37 +//recursive can only be called in a dico instance
29 38 void addto_tree(tree,string,int);
30 39 void addto_tree2(tree,string);
31 40  
... ...