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 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287
|
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* Copyright (C) 2006 Kouhei Sutou <kou@cozmixng.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307 USA
*
* $Id: tomoe-recognizer-simple.c 1212 2007-04-25 07:35:56Z makeinu $
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif /* HAVE_CONFIG_H */
#include <stdlib.h>
#include <gmodule.h>
#include <glib/gi18n-lib.h>
#include <tomoe-module-impl.h>
#include <tomoe-recognizer.h>
#include "tomoe-recognizer-simple-logic.h"
#define TOMOE_TYPE_RECOGNIZER_SIMPLE tomoe_type_recognizer_simple
#define TOMOE_RECOGNIZER_SIMPLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TOMOE_TYPE_RECOGNIZER_SIMPLE, TomoeRecognizerSimple))
#define TOMOE_RECOGNIZER_SIMPLE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TOMOE_TYPE_RECOGNIZER_SIMPLE, TomoeRecognizerSimpleClass))
#define TOMOE_IS_RECOGNIZER_SIMPLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TOMOE_TYPE_RECOGNIZER_SIMPLE))
#define TOMOE_IS_RECOGNIZER_SIMPLE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TOMOE_TYPE_RECOGNIZER_SIMPLE))
#define TOMOE_RECOGNIZER_SIMPLE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), TOMOE_TYPE_RECOGNIZER_SIMPLE, TomoeRecognizerSimpleClass))
enum {
PROP_0,
PROP_DICTIONARY
};
typedef struct _TomoeRecognizerSimple TomoeRecognizerSimple;
typedef struct _TomoeRecognizerSimpleClass TomoeRecognizerSimpleClass;
struct _TomoeRecognizerSimple
{
TomoeRecognizer object;
TomoeDict *dict;
};
struct _TomoeRecognizerSimpleClass
{
TomoeRecognizerClass parent_class;
};
static GType tomoe_type_recognizer_simple = 0;
static GObjectClass *parent_class;
static GObject *constructor (GType type,
guint n_props,
GObjectConstructParam *props);
static void dispose (GObject *object);
static void set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec);
static void get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec);
static GList *search (TomoeRecognizer *recognizer,
TomoeWriting *input);
static gboolean is_available (TomoeRecognizer *recognizer);
static void
class_init (TomoeRecognizerSimpleClass *klass)
{
GObjectClass *gobject_class;
TomoeRecognizerClass *recognizer_class;
parent_class = g_type_class_peek_parent (klass);
gobject_class = G_OBJECT_CLASS (klass);
gobject_class->constructor = constructor;
gobject_class->dispose = dispose;
gobject_class->set_property = set_property;
gobject_class->get_property = get_property;
recognizer_class = TOMOE_RECOGNIZER_CLASS (klass);
recognizer_class->search = search;
recognizer_class->is_available = is_available;
g_object_class_install_property (
gobject_class,
PROP_DICTIONARY,
g_param_spec_object (
"dictionary",
_("Dictionary"),
_("The dictionary of the recognizer"),
TOMOE_TYPE_DICT,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
}
static void
init (TomoeRecognizerSimple *recognizer)
{
}
static void
register_type (GTypeModule *type_module)
{
static const GTypeInfo info =
{
sizeof (TomoeRecognizerSimpleClass),
(GBaseInitFunc) NULL,
(GBaseFinalizeFunc) NULL,
(GClassInitFunc) class_init,
NULL, /* class_finalize */
NULL, /* class_data */
sizeof (TomoeRecognizerSimple),
0,
(GInstanceInitFunc) init,
};
tomoe_type_recognizer_simple =
g_type_module_register_type (type_module,
TOMOE_TYPE_RECOGNIZER,
"TomoeRecognizerSimple",
&info, 0);
}
G_MODULE_EXPORT GList *
TOMOE_MODULE_IMPL_INIT (GTypeModule *type_module)
{
GList *registered_types = NULL;
register_type (type_module);
if (tomoe_type_recognizer_simple) {
gchar *name = (gchar *) g_type_name (tomoe_type_recognizer_simple);
registered_types = g_list_prepend (registered_types, name);
}
return registered_types;
}
G_MODULE_EXPORT void
TOMOE_MODULE_IMPL_EXIT (void)
{
}
G_MODULE_EXPORT GObject *
TOMOE_MODULE_IMPL_INSTANTIATE (const gchar *first_property, va_list var_args)
{
return g_object_new_valist (TOMOE_TYPE_RECOGNIZER_SIMPLE,
first_property, var_args);
}
G_MODULE_EXPORT gchar *
TOMOE_MODULE_IMPL_GET_LOG_DOMAIN (void)
{
return g_strdup (G_LOG_DOMAIN);
}
static GObject *
constructor (GType type, guint n_props,
GObjectConstructParam *props)
{
GObject *object;
GObjectClass *klass = G_OBJECT_CLASS (parent_class);
TomoeRecognizerSimple *recognizer;
object = klass->constructor (type, n_props, props);
recognizer = TOMOE_RECOGNIZER_SIMPLE (object);
if (!recognizer->dict) {
const gchar *language;
gchar *dict_name;
gchar *filename;
language = tomoe_recognizer_get_language (TOMOE_RECOGNIZER (object));
if (language)
dict_name = g_strconcat ("handwriting-", language, ".xml", NULL);
else
dict_name = g_strdup ("handwriting.xml");
filename = g_build_filename (RECOGNIZER_DATADIR, dict_name, NULL);
recognizer->dict = tomoe_dict_new ("xml",
"filename", filename,
NULL);
if (recognizer->dict && !tomoe_dict_is_available (recognizer->dict)) {
g_object_unref (recognizer->dict);
recognizer->dict = NULL;
}
g_free(dict_name);
g_free(filename);
}
return object;
}
static void
set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
TomoeRecognizerSimple *recognizer = TOMOE_RECOGNIZER_SIMPLE (object);
switch (prop_id) {
case PROP_DICTIONARY:
if (recognizer->dict)
g_object_unref (recognizer->dict);
recognizer->dict = g_value_get_object (value);
if (recognizer->dict)
g_object_ref (recognizer->dict);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
TomoeRecognizerSimple *recognizer = TOMOE_RECOGNIZER_SIMPLE (object);
switch (prop_id) {
case PROP_DICTIONARY:
g_value_set_object (value, recognizer->dict);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
dispose (GObject *object)
{
TomoeRecognizerSimple *recognizer;
recognizer = TOMOE_RECOGNIZER_SIMPLE (object);
if (recognizer->dict)
g_object_unref (recognizer->dict);
recognizer->dict = NULL;
G_OBJECT_CLASS (parent_class)->dispose (object);
}
static GList *
search (TomoeRecognizer *_recognizer, TomoeWriting *input)
{
TomoeRecognizerSimple *recognizer;
recognizer = TOMOE_RECOGNIZER_SIMPLE (_recognizer);
return _tomoe_recognizer_simple_get_candidates (_recognizer,
recognizer->dict,
input);
}
static gboolean
is_available (TomoeRecognizer *_recognizer)
{
TomoeRecognizerSimple *recognizer;
recognizer = TOMOE_RECOGNIZER_SIMPLE (_recognizer);
return recognizer->dict != NULL;
}
/*
vi:ts=4:nowrap:ai:expandtab
*/
|