Zinnia: /home/taku/.trunk/zinnia/zinnia.h Source File

- Main Page
- Namespaces
- Classes
- Files

# /home/taku/.trunk/zinnia/zinnia.h

Go to the documentation of this file.

    00001 #ifndef ZINNIA_H_
    00002 #define ZINNIA_H_
    00003
    00004 /* C interface  */
    00005 #ifdef __cplusplus
    00006 #include <cstdio>
    00007 #else
    00008 #include <stdio.h>
    00009 #endif
    00010
    00011 #ifdef __cplusplus
    00012 extern "C" {
    00013 #endif
    00014
    00015 #ifdef _WIN32
    00016 #include <windows.h>
    00017 #  ifdef DLL_EXPORT
    00018 #    define ZINNIA_DLL_EXTERN  __declspec(dllexport)
    00019 #  else
    00020 #    define ZINNIA_DLL_EXTERN  __declspec(dllimport)
    00021 #  endif
    00022 #endif
    00023
    00024 #ifndef ZINNIA_DLL_EXTERN
    00025 #  define ZINNIA_DLL_EXTERN extern
    00026 #endif
    00027
    00028 #ifndef SWIG
    00029   typedef struct zinnia_character_t zinnia_character_t;
    00030   typedef struct zinnia_recognizer_t zinnia_recognizer_t;
    00031   typedef struct zinnia_result_t zinnia_result_t;
    00032   typedef struct zinnia_trainer_t zinnia_trainer_t;
    00033
    00034   /* C interface */
    00035   ZINNIA_DLL_EXTERN int zinnia_do(int argc, char **argv);
    00036   ZINNIA_DLL_EXTERN int zinnia_learn(int argc, char **argv);
    00037   ZINNIA_DLL_EXTERN int zinnia_convert(int argc, char **argv);
    00038   ZINNIA_DLL_EXTERN const char* zinnia_version();
    00039
    00040   /* character */
    00041   ZINNIA_DLL_EXTERN zinnia_character_t*  zinnia_character_new();
    00042   ZINNIA_DLL_EXTERN void        zinnia_character_destroy(zinnia_character_t *character);
    00043   ZINNIA_DLL_EXTERN void        zinnia_character_set_value(zinnia_character_t *character, const char *str);
    00044   ZINNIA_DLL_EXTERN void        zinnia_character_set_value2(zinnia_character_t *character, const char *str, size_t length);
    00045   ZINNIA_DLL_EXTERN const char *zinnia_character_value(zinnia_character_t *character);
    00046   ZINNIA_DLL_EXTERN void        zinnia_character_set_width(zinnia_character_t *character, size_t width);
    00047   ZINNIA_DLL_EXTERN void        zinnia_character_set_height(zinnia_character_t *character, size_t height);
    00048   ZINNIA_DLL_EXTERN size_t      zinnia_character_width(zinnia_character_t *character);
    00049   ZINNIA_DLL_EXTERN size_t      zinnia_character_height(zinnia_character_t *character);
    00050   ZINNIA_DLL_EXTERN void        zinnia_character_clear(zinnia_character_t *stroke);
    00051   ZINNIA_DLL_EXTERN int         zinnia_character_add(zinnia_character_t *character, size_t id, int x, int y);
    00052   ZINNIA_DLL_EXTERN size_t      zinnia_character_strokes_size(zinnia_character_t *character);
    00053   ZINNIA_DLL_EXTERN size_t      zinnia_character_stroke_size(zinnia_character_t *character, size_t id);
    00054   ZINNIA_DLL_EXTERN int         zinnia_character_x(zinnia_character_t *character, size_t id, size_t i);
    00055   ZINNIA_DLL_EXTERN int         zinnia_character_y(zinnia_character_t *character, size_t id, size_t i);
    00056   ZINNIA_DLL_EXTERN int         zinnia_character_parse(zinnia_character_t *character, const char *str);
    00057   ZINNIA_DLL_EXTERN int         zinnia_character_parse2(zinnia_character_t *character, const char *str, size_t length);
    00058   ZINNIA_DLL_EXTERN int         zinnia_character_to_string(zinnia_character_t *character, char *buf, size_t length);
    00059   ZINNIA_DLL_EXTERN const char* zinnia_character_strerror(zinnia_character_t *character);
    00060
    00061   /* Recognizer::Result */
    00062   ZINNIA_DLL_EXTERN const char *zinnia_result_value(zinnia_result_t *result, size_t i);
    00063   ZINNIA_DLL_EXTERN float       zinnia_result_score(zinnia_result_t *result, size_t i);
    00064   ZINNIA_DLL_EXTERN size_t      zinnia_result_size(zinnia_result_t *result);
    00065   ZINNIA_DLL_EXTERN void        zinnia_result_destroy(zinnia_result_t *result);
    00066
    00067   /* Recognizer */
    00068   ZINNIA_DLL_EXTERN zinnia_recognizer_t *zinnia_recognizer_new();
    00069   ZINNIA_DLL_EXTERN void                zinnia_recognizer_destroy(zinnia_recognizer_t *recognizer);
    00070   ZINNIA_DLL_EXTERN int                 zinnia_recognizer_open(zinnia_recognizer_t *recognizer, const char *filename);
    00071   ZINNIA_DLL_EXTERN int                 zinnia_recognizer_open_from_ptr(zinnia_recognizer_t *recognizer,
    00072                                                                       const char *ptr, size_t size);
    00073   ZINNIA_DLL_EXTERN int                 zinnia_recognizer_close(zinnia_recognizer_t *recognizer);
    00074   ZINNIA_DLL_EXTERN size_t              zinnia_recognizer_size(zinnia_recognizer_t *recognizer);
    00075   ZINNIA_DLL_EXTERN const char         *zinnia_recognizer_value(zinnia_recognizer_t *recognizer, size_t i);
    00076   ZINNIA_DLL_EXTERN const char*         zinnia_recognizer_strerror(zinnia_recognizer_t *recognizer);
    00077   ZINNIA_DLL_EXTERN zinnia_result_t *zinnia_recognizer_classify(zinnia_recognizer_t *recognizer,
    00078                                                                       const zinnia_character_t *character,
    00079                                                                       size_t nbest);
    00080
    00081   /* Trainer */
    00082   ZINNIA_DLL_EXTERN zinnia_trainer_t *zinnia_trainer_new();
    00083   ZINNIA_DLL_EXTERN void             zinnia_trainer_destroy(zinnia_trainer_t *trainer);
    00084   ZINNIA_DLL_EXTERN int              zinnia_trainer_add(zinnia_trainer_t *trainer, const zinnia_character_t* character);
    00085   ZINNIA_DLL_EXTERN void             zinnia_trainer_clear(zinnia_trainer_t *trainer);
    00086   ZINNIA_DLL_EXTERN int              zinnia_trainer_train(zinnia_trainer_t *trainer, const char *filename);
    00087   ZINNIA_DLL_EXTERN const char      *zinnia_trainer_strerror(zinnia_trainer_t *trainer);
    00088   ZINNIA_DLL_EXTERN int              zinnia_trainer_convert_model(const char *txt_model,
    00089                                                                   const char *binary_model,
    00090                                                                   double compression_threshold);
    00091   ZINNIA_DLL_EXTERN int              zinnia_trainer_make_header(const char *txt_model,
    00092                                                                 const char *header_file,
    00093                                                                 const char *name,
    00094                                                                 double compression_threshold);
    00095
    00096 #endif
    00097
    00098 #ifdef __cplusplus
    00099 }
    00100 #endif
    00101
    00102 /* C++ interface */
    00103 #ifdef __cplusplus
    00104
    00105 namespace zinnia {
    00106
    00107   ZINNIA_DLL_EXTERN const char *version();
    00108
    00109   class Character {
    00110   public:
    00111 #ifndef SWIG
    00112     virtual void set_value(const char *str, size_t length) = 0;
    00113 #endif
    00114     virtual void set_value(const char *str) = 0;
    00115     virtual const char *value() const = 0;
    00116     virtual void set_width(size_t width) = 0;
    00117     virtual void set_height(size_t height) = 0;
    00118     virtual size_t width() const = 0;
    00119     virtual size_t height() const = 0;
    00120     virtual void clear() = 0;
    00121     virtual bool add(size_t id, int x, int y) = 0;
    00122     virtual size_t strokes_size() const = 0;
    00123     virtual size_t stroke_size(size_t id) const = 0;
    00124     virtual int x(size_t id, size_t i) const = 0;
    00125     virtual int y(size_t id, size_t i) const = 0;
    00126     virtual bool parse(const char *str) = 0;
    00127     virtual const char *what() = 0;
    00128 #ifndef SWIG
    00129     virtual bool parse(const char *str, size_t length) = 0;
    00130     virtual bool toString(char *buf, size_t length) const = 0;
    00131     static Character *create();
    00132 #endif
    00133     virtual ~Character() {}
    00134   };
    00135
    00136   class Result {
    00137   public:
    00138     virtual const char *value(size_t i) const = 0;
    00139     virtual float score(size_t i) const = 0;
    00140     virtual size_t size() const = 0;
    00141     virtual ~Result() {}
    00142   };
    00143
    00144   class Recognizer {
    00145   public:
    00146     virtual bool open(const char *filename) = 0;
    00147     virtual bool open(const char *ptr, size_t size) = 0;
    00148     virtual bool close() = 0;
    00149     virtual size_t size() const = 0;
    00150     virtual const char *value(size_t i) const = 0;
    00151     virtual Result *classify(const Character &character, size_t nbest) const = 0;
    00152     virtual const char *what() = 0;
    00153     virtual ~Recognizer() {}
    00154 #ifndef SWIG
    00155     static Recognizer* create();
    00156 #endif
    00157   };
    00158
    00159   class Trainer {
    00160   public:
    00161     virtual bool add(const Character &character) = 0;
    00162     virtual void clear() = 0;
    00163     virtual bool train(const char *filename) = 0;
    00164     static bool convert(const char *txt_model,
    00165                         const char *binary_model,
    00166                         double compression_threshold);
    00167     static bool makeHeader(const char *txt_model,
    00168                            const char *header_file,
    00169                            const char *name,
    00170                            double compression_threshold);
    00171     virtual const char *what() = 0;
    00172     virtual ~Trainer() {}
    00173 #ifndef SWIG
    00174     static Trainer* create();
    00175 #endif
    00176   };
    00177
    00178 #ifndef SWIG
    00179   ZINNIA_DLL_EXTERN Recognizer* createRecognizer();
    00180   ZINNIA_DLL_EXTERN Character*  createCharacter();
    00181   ZINNIA_DLL_EXTERN Trainer*    createTrainer();
    00182 #endif
    00183 }
    00184
    00185 #endif
    00186 #endif