/* * Recovers the probability for the given sufix. */ double recover_prob(char* sufix) { Tree_node* current_node = prob_root; for (int i = 0; sufix[i] != '\0'; i++) { current_node = get_child_node(current_node, sufix[i]); } return current_node->prob_data->probability; }
/* * Returns the prob_node which represents the same word as the given bic_node */ Tree_node* get_prob_node(Tree_node* bic_node) { Tree_node* prob_node = prob_root; Tree_node* parent_node = bic_node; while (parent_node != bic_root) { prob_node = get_child_node(prob_node, parent_node->symbol); parent_node = parent_node->parent; } return prob_node; }
/* * Calculates Ltau on the current Prob Tree */ double L_tau(Tau* tau) { double value = 1.0; Tau_item* item = tau->item; while (item != NULL) { char* word = item->string; int word_length = strlen(word); // go down the tree to find the correct node Tree_node* node = prob_root; for (int i = 0; i < word_length; i++) { node = get_child_node(node, word[i]); } if (node != NULL) { value *= node->prob_data->Lw; } item = item->next; } return value; }
Tree_node node_of_suffix(Tree_node tree, char *w) // w must be 0 terminated { for(int i = strlen(w); i; i--) tree = get_child_node(tree, w[i - 1]); return tree; }
/* * Go down a digital tree */ Tree_node node_of_word(Tree_node tree, char *w) // w must be 0 terminated { for(;*w;w++) tree = get_child_node(tree, *w); return tree; }