[Kazehakase-cvs] CVS update: kazehakase/module/search

Back to archive index

Hiroyuki Ikezoe ikezo****@users*****
Tue Dec 5 21:22:30 JST 2006


Index: kazehakase/module/search/Makefile.am
diff -u kazehakase/module/search/Makefile.am:1.3 kazehakase/module/search/Makefile.am:1.4
--- kazehakase/module/search/Makefile.am:1.3	Mon Dec  4 09:12:05 2006
+++ kazehakase/module/search/Makefile.am	Tue Dec  5 21:22:30 2006
@@ -45,3 +45,13 @@
 libhyperestraier_la_CPPFLAGS = $(EST_CFLAGS)
 
 endif
+
+if WITH_ANTHY
+search_LTLIBRARIES += libanthy-trainer.la
+
+libanthy_trainer_la_SOURCES = \
+	kz-anthy-trainer.h kz-anthy-trainer.c
+libanthy_trainer_la_LIBADD = $(ANTHY_LIBS) $(MECAB_LIBS)
+libanthy_trainer_la_CPPFLAGS = $(ANTHY_CFLAGS) $(MECAB_CFLAGS)
+
+endif
Index: kazehakase/module/search/kz-anthy-trainer.c
diff -u /dev/null kazehakase/module/search/kz-anthy-trainer.c:1.1
--- /dev/null	Tue Dec  5 21:22:30 2006
+++ kazehakase/module/search/kz-anthy-trainer.c	Tue Dec  5 21:22:30 2006
@@ -0,0 +1,265 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+/*
+ *  Copyright (C) 2004 Hiroyuki Ikezoe
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2, or (at your option)
+ *  any later version.
+ *
+ *  This program 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 General Public License for more details.
+ *
+ *  You should have received a copy of the GNU 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.
+ */
+
+#include <glib/gi18n.h>
+#include <glib.h>
+#include <gmodule.h>
+
+#include <anthy/anthy.h>
+
+#include <mecab.h>
+
+#include "kazehakase.h"
+#include "kz-anthy-trainer.h"
+#include "utils.h"
+
+
+typedef struct _KzAnthyTrainerPrivate	KzAnthyTrainerPrivate;
+struct _KzAnthyTrainerPrivate
+{
+	gchar *dbname;
+	mecab_t *mecab;
+};
+
+typedef struct _KzAnthyTrainerClass	KzAnthyTrainerClass;
+struct _KzAnthyTrainerClass
+{
+	KzSearchClass parent_class;
+};
+
+#define KZ_ANTHY_TRAINER_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), KZ_TYPE_ANTHY_TRAINER, KzAnthyTrainerPrivate))
+
+#define KZ_ANTHY_TRAINER_CLASS(klass)	(G_TYPE_CHECK_CLASS_CAST ((klass), KZ_TYPE_ANTHY_TRAINER, KzAnthyTrainerClass))
+#define KZ_IS_ANTHY_TRAINER_CLASS(klass) 	(G_TYPE_CHECK_CLASS_TYPE ((klass), KZ_TYPE_ANTHY_TRAINER))
+#define KZ_ANTHY_TRAINER_GET_CLASS(obj)  	(G_TYPE_INSTANCE_GET_CLASS ((obj), KZ_TYPE_ANTHY_TRAINER, KzAnthyTrainerClass))
+
+/* for module */
+void        kz_search_module_init		(GTypeModule *module);
+void        kz_search_module_exit		(void);
+KzSearch   *kz_search_module_create		(void);
+
+/* KzAnthyTrainer Class */
+static void   kz_anthy_trainer_class_init (KzAnthyTrainerClass *klass);
+static void   kz_anthy_trainer_init       (KzAnthyTrainer *search);
+
+/* GObject Class */
+static GObject *constructor  (GType type,
+                              guint n_props,
+                              GObjectConstructParam *props);
+static void     dispose      (GObject *object);
+
+/* KzSearch Class */
+static gboolean    register_document          (KzSearch *search,
+					       const gchar *uri,
+					       const gchar *encoding,
+					       const gchar *title,
+					       const gchar *contents,
+					       GTime mtime);
+static gboolean    unregister_document        (KzSearch *search, const gchar *uri);
+static GPid        optimize_index             (KzSearch *search);
+static void        make_index                 (KzSearch *search);
+static gboolean    exist_index_dir            (KzSearch *search);
+
+static KzAnthyTrainer *the_kz_anthy_trainer = NULL;
+
+static GObjectClass *parent_class;
+static GType kz_anthy_trainer_type = 0;
+
+static void
+kz_anthy_trainer_register_type (GTypeModule *module)
+{
+	static const GTypeInfo kz_anthy_trainer_info =
+	{
+		sizeof (KzAnthyTrainerClass),
+		NULL,		/* base_init */
+		NULL,		/* base_finalize */
+		(GClassInitFunc) kz_anthy_trainer_class_init,
+		NULL,		/* class_finalize */
+		NULL,		/* class_data */
+		sizeof (KzAnthyTrainer),
+		0,		/* n_preallocs */
+		(GInstanceInitFunc) kz_anthy_trainer_init,
+	};
+
+	kz_anthy_trainer_type = g_type_module_register_type (module,
+			KZ_TYPE_SEARCH,
+			"KzAnthyTrainer",
+			&kz_anthy_trainer_info, 0);
+}
+
+G_MODULE_EXPORT void 
+kz_search_module_init (GTypeModule *module)
+{
+	kz_anthy_trainer_register_type(module);
+}
+
+G_MODULE_EXPORT void 
+kz_search_module_exit (void)
+{
+}
+
+G_MODULE_EXPORT KzSearch * 
+kz_search_module_create (void)
+{
+	return kz_anthy_trainer_new();
+}
+
+GType
+kz_anthy_trainer_get_type (void)
+{
+	return kz_anthy_trainer_type;
+}
+
+static void
+kz_anthy_trainer_class_init (KzAnthyTrainerClass *klass)
+{
+	GObjectClass *object_class;
+	KzSearchClass *search_class;
+
+	parent_class = g_type_class_peek_parent (klass);
+	object_class = (GObjectClass *) klass;
+	search_class = (KzSearchClass *) klass;
+
+	object_class->constructor = constructor;
+	object_class->dispose     = dispose;
+	
+	search_class->get_search_result_html     = NULL;
+	search_class->get_search_result_bookmark = NULL;
+	search_class->register_document          = register_document;
+	search_class->unregister_document        = unregister_document;
+	search_class->optimize_index             = optimize_index;
+	search_class->make_index                 = make_index;
+	search_class->exist_index_dir            = exist_index_dir;
+
+	g_type_class_add_private (object_class, sizeof(KzAnthyTrainerPrivate));
+}
+
+
+static void
+kz_anthy_trainer_init (KzAnthyTrainer *search)
+{
+	KzAnthyTrainerPrivate *priv = KZ_ANTHY_TRAINER_GET_PRIVATE(search);
+
+	priv->dbname = g_build_filename(g_get_home_dir(), "."PACKAGE, "anthy", NULL);
+	priv->mecab = mecab_new2("");
+}
+
+static GObject *
+constructor (GType                  type,
+             guint                  n_props,
+             GObjectConstructParam *props)
+{
+	GObject *object;
+
+	if (!the_kz_anthy_trainer) 
+	{
+		GObjectClass *klass = G_OBJECT_CLASS(parent_class);
+		object = klass->constructor(type, n_props, props);
+		the_kz_anthy_trainer = KZ_ANTHY_TRAINER(object);
+	}
+	else
+	{
+		object = g_object_ref(G_OBJECT(the_kz_anthy_trainer));
+	}
+	return object;
+}
+
+static void
+dispose (GObject *object)
+{
+	KzAnthyTrainerPrivate *priv = KZ_ANTHY_TRAINER_GET_PRIVATE(object);
+	
+	if (priv->dbname)
+		g_free(priv->dbname);
+
+	if (priv->mecab)
+		mecab_destroy(priv->mecab);
+
+	priv->mecab  = NULL;
+	priv->dbname = NULL;
+
+	if (G_OBJECT_CLASS(parent_class)->dispose)
+		G_OBJECT_CLASS(parent_class)->dispose(object);
+}
+
+
+KzSearch *
+kz_anthy_trainer_new (void)
+{
+	return KZ_SEARCH(g_object_new(KZ_TYPE_ANTHY_TRAINER, NULL));
+}
+
+
+gboolean
+register_document (KzSearch *search, const gchar *uri, const gchar *encoding, const gchar *title, const gchar *contents, GTime mtime)
+{
+	KzAnthyTrainerPrivate *priv = KZ_ANTHY_TRAINER_GET_PRIVATE(search);
+	mecab_node_t *node;
+	gchar *text;
+	text = html_to_text(contents);
+	node = mecab_sparse_tonode(priv->mecab, text);
+	g_free(text);
+	if (!node) return FALSE;
+
+	for (;  node; node = node->next)
+	{
+		gchar *surface;
+
+		if (node->stat == MECAB_BOS_NODE ||
+		    node->stat == MECAB_EOS_NODE)
+			continue;
+
+		surface = g_new0(gchar, node->length + 2);
+		g_snprintf(surface, node->length+1, "%s", node->surface);
+	
+		g_warning("%s: %s", surface, node->feature);
+		g_free(surface);
+	}
+
+	return FALSE;
+}
+
+gboolean
+unregister_document (KzSearch *search, const gchar *uri)
+{
+	return FALSE;
+}
+
+static GPid
+optimize_index (KzSearch *search)
+{
+	return 0;
+}
+
+static void
+make_index (KzSearch *search)
+{
+}
+
+static gboolean
+exist_index_dir(KzSearch *search)
+{
+	gboolean exist = FALSE;
+	KzAnthyTrainerPrivate *priv = KZ_ANTHY_TRAINER_GET_PRIVATE(search);
+
+	exist = g_file_test(priv->dbname, G_FILE_TEST_IS_DIR);
+
+	return exist;
+}
Index: kazehakase/module/search/kz-anthy-trainer.h
diff -u /dev/null kazehakase/module/search/kz-anthy-trainer.h:1.1
--- /dev/null	Tue Dec  5 21:22:30 2006
+++ kazehakase/module/search/kz-anthy-trainer.h	Tue Dec  5 21:22:30 2006
@@ -0,0 +1,46 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+/*
+ *  Copyright (C) 2004 Hiroyuki Ikezoe
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2, or (at your option)
+ *  any later version.
+ *
+ *  This program 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 General Public License for more details.
+ *
+ *  You should have received a copy of the GNU 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.
+ */
+
+#ifndef __KZ_ANTHY_TRAINER_H__
+#define __KZ_ANTHY_TRAINER_H__
+
+#include <glib-object.h>
+#include "kz-search.h"
+
+G_BEGIN_DECLS
+
+#define KZ_TYPE_ANTHY_TRAINER		(kz_anthy_trainer_get_type ())
+#define KZ_ANTHY_TRAINER(obj)		(G_TYPE_CHECK_INSTANCE_CAST ((obj), KZ_TYPE_ANTHY_TRAINER, KzAnthyTrainer))
+#define KZ_IS_ANTHY_TRAINER(obj)	(G_TYPE_CHECK_INSTANCE_TYPE ((obj), KZ_TYPE_ANTHY_TRAINER))
+
+typedef struct _KzAnthyTrainer		KzAnthyTrainer;
+
+struct _KzAnthyTrainer
+{
+	KzSearch parent;
+};
+
+GType      kz_anthy_trainer_get_type (void) G_GNUC_CONST;
+
+KzSearch  *kz_anthy_trainer_new      (void);
+
+G_END_DECLS
+
+#endif /* __ANTHY_TRAINERH__ */


More information about the Kazehakase-cvs mailing list
Back to archive index