Back to index

im-sdk  12.3.91
Classes | Defines | Typedefs | Enumerations | Functions
hhdict.h File Reference
#include "tree.h"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  _Dictionary
struct  _DictionaryHeader

Defines

#define Bool   Boolean

Typedefs

typedef struct _Dictionary
typedef struct _DictionaryHeader

Enumerations

enum  Boolean {
  True = 1, False = 0, True = 1, False = 0,
  True = 1, False = 0, True = 1, False = 0,
  True = 1, False = 0
}

Functions

Bool construct_binary_tree_from_file (char *dic_path, Tree **trees_return, int *n_trees_return)
Bool dictionary_search_hanja_candidates_in_utf16 (UTFCHAR *u16_hangul, int *n_return, UTFCHAR ***u16_hanja_return)

Class Documentation

struct _Dictionary

Definition at line 15 of file hhdict.h.

Collaboration diagram for _Dictionary:
Class Members
int n_trees
Tree * p_trees
struct _DictionaryHeader

Definition at line 30 of file hhdict.h.

Class Members
char dict_name
int dict_version_major
int dict_version_minor
int table_size

Define Documentation

#define Bool   Boolean

Definition at line 8 of file hhdict.h.


Typedef Documentation

typedef struct _Dictionary

Definition at line 13 of file hhdict.h.

typedef struct _DictionaryHeader

Definition at line 28 of file hhdict.h.


Enumeration Type Documentation

enum Boolean
Enumerator:
True 
False 
True 
False 
True 
False 
True 
False 
True 
False 

Definition at line 5 of file hhdict.h.

             {
  True=1, False=0
} Boolean;

Function Documentation

Bool construct_binary_tree_from_file ( char *  dic_path,
Tree **  trees_return,
int *  n_trees_return 
)

Definition at line 38 of file hhdict.c.

{
  FILE *fp;
  struct stat buf;
  int ret;
  int i;
  DictionaryHeader hdr;

  assert (dic_path != NULL);
  n_dictionary_creation_counter += 1;
  
  if (n_dictionary_creation_counter > 1){
    *trees_return = _p_trees;
    *n_trees_return = _n_trees;
  }
    
  
  if (dic_path == NULL){
    fprintf (stderr, "NULL path for dictionary was passed\n");
    return False;
  }
  
  ret = stat (dic_path, &buf);
  
  if (ret){
    /* in most case, the file isn't likely to exist */
    perror ("dictionary_build_btree_from_file error");
    return False;
  }
  
  fp = fopen (dic_path, "r");
    
  /* how many tree do I need to build */
  dictionary_get_header_info (fp, &hdr);
  
  _n_trees = hdr.table_size;
  _p_trees = (Tree *) tree_n_new (hdr.table_size);
  
  for (i = 0; i < _n_trees; i++)
    dictionary_build_tree_from_file (fp, &_p_trees[i]);

  fclose (fp);
  *n_trees_return = _n_trees;
  *trees_return = _p_trees;
  
  return True;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Bool dictionary_search_hanja_candidates_in_utf16 ( UTFCHAR u16_hangul,
int *  n_return,
UTFCHAR ***  u16_hanja_return 
)

Definition at line 214 of file hhdict.c.

{
  int hash_val;
  int i;
  unsigned char *p8hangul = NULL;
  UTFCHAR *conv_return;
  TreeNode *search_result;
    
  assert (u16_hangul != NULL);
  assert (n_return != NULL);
  assert (u16_hanja_return != NULL);

  if (u16_hangul == NULL || !_utfchar_length (u16_hangul)){
    fprintf (stdout,
            "dictionary_search_hanja_candidates_in_utf16 error: "
            "u16_hangul is null or zero length");
    return False;
  }
  if (n_return == NULL || u16_hanja_return == NULL){
    fprintf (stdout,
            "dictionary_search_hanja_candidates_in_utf16 error: "
            "n_return or u16_hanja_return is NULL");
    return False;
  }

  hash_val = hash (u16_hangul);
  p8hangul = (unsigned char *) _utfchar_convert_u16_to_u8 (u16_hangul);
  
  search_result = tree_search_hangul (_p_trees + hash_val, p8hangul);
  if (!search_result){
    fprintf (stdout, "dictionary_search_hanja_candidates_in_utf16 error"
            "no candidates found\n");
    if (p8hangul)
      free (p8hangul);

    return False;
  }
  
  *n_return = search_result->data->n_hanja;
  *u16_hanja_return =
    (UTFCHAR **) calloc (*n_return, sizeof (UTFCHAR *));

  for (i = 0 ; i < *n_return; i++){
    conv_return = 
      _utfchar_convert_u8_to_u16 (search_result->data->hanja_list[i]);
    /*
    if (conv_return == NULL)
          (*u16_hanja_return)[i] = NULL;
    */
    (*u16_hanja_return)[i] = conv_return;
  }

  if (p8hangul)
    free (p8hangul);
  return True;
}

Here is the call graph for this function:

Here is the caller graph for this function: