/* language-model.c generated by valac 0.56.19, the Vala compiler
 * generated from language-model.vala, do not modify */

/*
 * Copyright (C) 2012-2014 Daiki Ueno <ueno@gnu.org>
 * Copyright (C) 2012-2014 Red Hat, Inc.
 *
 * 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 3 of the License, 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, see <http://www.gnu.org/licenses/>.
 */

#include "libkkc/libkkc.h"
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <glib-object.h>
#include <json-glib/json-glib.h>
#include <gee.h>
#include <glib/gstdio.h>
#include <gio/gio.h>
#include <float.h>
#include <math.h>

#if !defined(VALA_STRICT_C)
#if !defined(__clang__) && defined(__GNUC__) && (__GNUC__ >= 14)
#pragma GCC diagnostic warning "-Wincompatible-pointer-types"
#elif defined(__clang__) && (__clang_major__ >= 16)
#pragma clang diagnostic ignored "-Wincompatible-function-pointer-types"
#pragma clang diagnostic ignored "-Wincompatible-pointer-types"
#endif
#endif

#define _g_free0(var) (var = (g_free (var), NULL))
enum  {
	KKC_LANGUAGE_MODEL_METADATA_0_PROPERTY,
	KKC_LANGUAGE_MODEL_METADATA_MODEL_TYPE_PROPERTY,
	KKC_LANGUAGE_MODEL_METADATA_NUM_PROPERTIES
};
static GParamSpec* kkc_language_model_metadata_properties[KKC_LANGUAGE_MODEL_METADATA_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define __vala_JsonNode_free0(var) ((var == NULL) ? NULL : (var = (_vala_JsonNode_free (var), NULL)))
enum  {
	KKC_LANGUAGE_MODEL_0_PROPERTY,
	KKC_LANGUAGE_MODEL_METADATA_PROPERTY,
	KKC_LANGUAGE_MODEL_BOS_PROPERTY,
	KKC_LANGUAGE_MODEL_EOS_PROPERTY,
	KKC_LANGUAGE_MODEL_NUM_PROPERTIES
};
static GParamSpec* kkc_language_model_properties[KKC_LANGUAGE_MODEL_NUM_PROPERTIES];

struct _KkcLanguageModelMetadataPrivate {
	GType _model_type;
};

struct _KkcLanguageModelPrivate {
	KkcLanguageModelMetadata* _metadata;
};

static gint KkcLanguageModelMetadata_private_offset;
static gpointer kkc_language_model_metadata_parent_class = NULL;
static GeeMap* kkc_language_model_metadata_model_types;
static GeeMap* kkc_language_model_metadata_model_types = NULL;
static gint KkcLanguageModel_private_offset;
static gpointer kkc_language_model_parent_class = NULL;
static GInitableIface * kkc_language_model_g_initable_parent_iface = NULL;

static gboolean kkc_language_model_metadata_real_parse (KkcMetadataFile* base,
                                                 JsonObject* object,
                                                 GError** error);
static JsonNode* _vala_JsonNode_copy (JsonNode* self);
static void _vala_JsonNode_free (JsonNode* self);
VALA_EXTERN gchar** kkc_utils_build_data_path (const gchar* subdir,
                                   gint* result_length1);
static GType* _g_type_dup (GType* self);
static void kkc_language_model_metadata_finalize (GObject * obj);
static GType kkc_language_model_metadata_get_type_once (void);
static void _vala_kkc_language_model_metadata_get_property (GObject * object,
                                                     guint property_id,
                                                     GValue * value,
                                                     GParamSpec * pspec);
static void _vala_kkc_language_model_metadata_set_property (GObject * object,
                                                     guint property_id,
                                                     const GValue * value,
                                                     GParamSpec * pspec);
static GeeCollection* kkc_language_model_real_unigram_entries (KkcLanguageModel* self,
                                                        const gchar* input);
static GeeCollection* kkc_language_model_real_entries (KkcLanguageModel* self,
                                                const gchar* input);
static KkcLanguageModelEntry* kkc_language_model_real_get (KkcLanguageModel* self,
                                                    const gchar* input,
                                                    const gchar* output);
static gboolean kkc_language_model_real_parse (KkcLanguageModel* self,
                                        GError** error);
static gboolean kkc_language_model_real_init (GInitable* base,
                                       GCancellable* cancellable,
                                       GError** error);
static void kkc_language_model_finalize (GObject * obj);
static GType kkc_language_model_get_type_once (void);
static void _vala_kkc_language_model_get_property (GObject * object,
                                            guint property_id,
                                            GValue * value,
                                            GParamSpec * pspec);
static void _vala_kkc_language_model_set_property (GObject * object,
                                            guint property_id,
                                            const GValue * value,
                                            GParamSpec * pspec);
static GType kkc_unigram_language_model_get_type_once (void);
static GType kkc_bigram_language_model_get_type_once (void);
static GType kkc_trigram_language_model_get_type_once (void);
static void _vala_array_destroy (gpointer array,
                          gssize array_length,
                          GDestroyNotify destroy_func);
static void _vala_array_free (gpointer array,
                       gssize array_length,
                       GDestroyNotify destroy_func);

GQuark
kkc_language_model_error_quark (void)
{
	return g_quark_from_static_string ("kkc-language-model-error-quark");
}

static GType
kkc_language_model_error_get_type_once (void)
{
	static const GEnumValue values[] = {{KKC_LANGUAGE_MODEL_ERROR_NOT_FOUND, "KKC_LANGUAGE_MODEL_ERROR_NOT_FOUND", "not-found"}, {0, NULL, NULL}};
	GType kkc_language_model_error_type_id;
	kkc_language_model_error_type_id = g_enum_register_static ("KkcLanguageModelError", values);
	return kkc_language_model_error_type_id;
}

GType
kkc_language_model_error_get_type (void)
{
	static volatile gsize kkc_language_model_error_type_id__once = 0;
	if (g_once_init_enter (&kkc_language_model_error_type_id__once)) {
		GType kkc_language_model_error_type_id;
		kkc_language_model_error_type_id = kkc_language_model_error_get_type_once ();
		g_once_init_leave (&kkc_language_model_error_type_id__once, kkc_language_model_error_type_id);
	}
	return kkc_language_model_error_type_id__once;
}

void
kkc_language_model_entry_copy (const KkcLanguageModelEntry* self,
                               KkcLanguageModelEntry* dest)
{
	const gchar* _tmp0_;
	gchar* _tmp1_;
	const gchar* _tmp2_;
	gchar* _tmp3_;
	_tmp0_ = (*self).input;
	_tmp1_ = g_strdup (_tmp0_);
	_g_free0 ((*dest).input);
	(*dest).input = _tmp1_;
	_tmp2_ = (*self).output;
	_tmp3_ = g_strdup (_tmp2_);
	_g_free0 ((*dest).output);
	(*dest).output = _tmp3_;
	(*dest).id = (*self).id;
}

void
kkc_language_model_entry_destroy (KkcLanguageModelEntry* self)
{
	_g_free0 ((*self).input);
	_g_free0 ((*self).output);
}

KkcLanguageModelEntry*
kkc_language_model_entry_dup (const KkcLanguageModelEntry* self)
{
	KkcLanguageModelEntry* dup;
	dup = g_new0 (KkcLanguageModelEntry, 1);
	kkc_language_model_entry_copy (self, dup);
	return dup;
}

void
kkc_language_model_entry_free (KkcLanguageModelEntry* self)
{
	kkc_language_model_entry_destroy (self);
	g_free (self);
}

static GType
kkc_language_model_entry_get_type_once (void)
{
	GType kkc_language_model_entry_type_id;
	kkc_language_model_entry_type_id = g_boxed_type_register_static ("KkcLanguageModelEntry", (GBoxedCopyFunc) kkc_language_model_entry_dup, (GBoxedFreeFunc) kkc_language_model_entry_free);
	return kkc_language_model_entry_type_id;
}

GType
kkc_language_model_entry_get_type (void)
{
	static volatile gsize kkc_language_model_entry_type_id__once = 0;
	if (g_once_init_enter (&kkc_language_model_entry_type_id__once)) {
		GType kkc_language_model_entry_type_id;
		kkc_language_model_entry_type_id = kkc_language_model_entry_get_type_once ();
		g_once_init_leave (&kkc_language_model_entry_type_id__once, kkc_language_model_entry_type_id);
	}
	return kkc_language_model_entry_type_id__once;
}

static inline gpointer
kkc_language_model_metadata_get_instance_private (KkcLanguageModelMetadata* self)
{
	return G_STRUCT_MEMBER_P (self, KkcLanguageModelMetadata_private_offset);
}

KkcLanguageModelMetadata*
kkc_language_model_metadata_construct (GType object_type,
                                       const gchar* name,
                                       const gchar* filename,
                                       GError** error)
{
	KkcLanguageModelMetadata * self = NULL;
	GError* _inner_error0_ = NULL;
	g_return_val_if_fail (name != NULL, NULL);
	g_return_val_if_fail (filename != NULL, NULL);
	self = (KkcLanguageModelMetadata*) kkc_metadata_file_construct (object_type, name, filename, &_inner_error0_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (self);
		return NULL;
	}
	return self;
}

KkcLanguageModelMetadata*
kkc_language_model_metadata_new (const gchar* name,
                                 const gchar* filename,
                                 GError** error)
{
	return kkc_language_model_metadata_construct (KKC_TYPE_LANGUAGE_MODEL_METADATA, name, filename, error);
}

static JsonNode*
_vala_JsonNode_copy (JsonNode* self)
{
	return g_boxed_copy (json_node_get_type (), self);
}

static gpointer
__vala_JsonNode_copy0 (gpointer self)
{
	return self ? _vala_JsonNode_copy (self) : NULL;
}

static void
_vala_JsonNode_free (JsonNode* self)
{
	g_boxed_free (json_node_get_type (), self);
}

static gboolean
kkc_language_model_metadata_real_parse (KkcMetadataFile* base,
                                        JsonObject* object,
                                        GError** error)
{
	KkcLanguageModelMetadata * self;
	JsonNode* member = NULL;
	JsonNode* _tmp2_;
	JsonNode* _tmp3_;
	gchar* type = NULL;
	JsonNode* _tmp4_;
	const gchar* _tmp5_;
	gchar* _tmp6_;
	GeeMap* _tmp7_;
	const gchar* _tmp8_;
	GeeMap* _tmp12_;
	const gchar* _tmp13_;
	gpointer _tmp14_;
	GType* _tmp15_;
	GError* _inner_error0_ = NULL;
	gboolean result;
	self = (KkcLanguageModelMetadata*) base;
	g_return_val_if_fail (object != NULL, FALSE);
	if (!json_object_has_member (object, "type")) {
		GError* _tmp0_;
		gboolean _tmp1_ = FALSE;
		_tmp0_ = g_error_new_literal (KKC_METADATA_FORMAT_ERROR, KKC_METADATA_FORMAT_ERROR_MISSING_FIELD, "type is not defined in metadata");
		_inner_error0_ = _tmp0_;
		g_propagate_error (error, _inner_error0_);
		return _tmp1_;
	}
	_tmp2_ = json_object_get_member (object, "type");
	_tmp3_ = __vala_JsonNode_copy0 (_tmp2_);
	member = _tmp3_;
	_tmp4_ = member;
	_tmp5_ = json_node_get_string (_tmp4_);
	_tmp6_ = g_strdup (_tmp5_);
	type = _tmp6_;
	_tmp7_ = kkc_language_model_metadata_model_types;
	_tmp8_ = type;
	if (!gee_map_has_key (_tmp7_, _tmp8_)) {
		const gchar* _tmp9_;
		GError* _tmp10_;
		gboolean _tmp11_ = FALSE;
		_tmp9_ = type;
		_tmp10_ = g_error_new (KKC_METADATA_FORMAT_ERROR, KKC_METADATA_FORMAT_ERROR_INVALID_FIELD, "unknown language model type %s", _tmp9_);
		_inner_error0_ = _tmp10_;
		g_propagate_error (error, _inner_error0_);
		_g_free0 (type);
		__vala_JsonNode_free0 (member);
		return _tmp11_;
	}
	_tmp12_ = kkc_language_model_metadata_model_types;
	_tmp13_ = type;
	_tmp14_ = gee_map_get (_tmp12_, _tmp13_);
	_tmp15_ = (GType*) _tmp14_;
	kkc_language_model_metadata_set_model_type (self, *_tmp15_);
	_g_free0 (_tmp15_);
	result = TRUE;
	_g_free0 (type);
	__vala_JsonNode_free0 (member);
	return result;
}

KkcLanguageModelMetadata*
kkc_language_model_metadata_find (const gchar* name)
{
	gchar** dirs = NULL;
	gint _tmp0_ = 0;
	gchar** _tmp1_;
	gint dirs_length1;
	gint _dirs_size_;
	gchar** _tmp2_;
	gint _tmp2__length1;
	GError* _inner_error0_ = NULL;
	KkcLanguageModelMetadata* result;
	g_return_val_if_fail (name != NULL, NULL);
	_tmp1_ = kkc_utils_build_data_path ("models", &_tmp0_);
	dirs = _tmp1_;
	dirs_length1 = _tmp0_;
	_dirs_size_ = dirs_length1;
	_tmp2_ = dirs;
	_tmp2__length1 = dirs_length1;
	{
		gchar** dir_collection = NULL;
		gint dir_collection_length1 = 0;
		gint _dir_collection_size_ = 0;
		gint dir_it = 0;
		dir_collection = _tmp2_;
		dir_collection_length1 = _tmp2__length1;
		for (dir_it = 0; dir_it < dir_collection_length1; dir_it = dir_it + 1) {
			gchar* _tmp3_;
			gchar* dir = NULL;
			_tmp3_ = g_strdup (dir_collection[dir_it]);
			dir = _tmp3_;
			{
				gchar* metadata_filename = NULL;
				const gchar* _tmp4_;
				gchar* _tmp5_;
				const gchar* _tmp6_;
				_tmp4_ = dir;
				_tmp5_ = g_build_filename (_tmp4_, name, "metadata.json", NULL);
				metadata_filename = _tmp5_;
				_tmp6_ = metadata_filename;
				if (g_file_test (_tmp6_, G_FILE_TEST_EXISTS)) {
					{
						KkcLanguageModelMetadata* _tmp7_ = NULL;
						const gchar* _tmp8_;
						KkcLanguageModelMetadata* _tmp9_;
						KkcLanguageModelMetadata* _tmp10_;
						_tmp8_ = metadata_filename;
						_tmp9_ = kkc_language_model_metadata_new (name, _tmp8_, &_inner_error0_);
						_tmp7_ = _tmp9_;
						if (G_UNLIKELY (_inner_error0_ != NULL)) {
							goto __catch0_g_error;
						}
						_tmp10_ = _tmp7_;
						_tmp7_ = NULL;
						result = _tmp10_;
						_g_object_unref0 (_tmp7_);
						_g_free0 (metadata_filename);
						_g_free0 (dir);
						dirs = (_vala_array_free (dirs, dirs_length1, (GDestroyNotify) g_free), NULL);
						return result;
					}
					goto __finally0;
					__catch0_g_error:
					{
						g_clear_error (&_inner_error0_);
						_g_free0 (metadata_filename);
						_g_free0 (dir);
						continue;
					}
					__finally0:
					_g_free0 (metadata_filename);
					_g_free0 (dir);
					dirs = (_vala_array_free (dirs, dirs_length1, (GDestroyNotify) g_free), NULL);
					g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
					g_clear_error (&_inner_error0_);
					return NULL;
				}
				_g_free0 (metadata_filename);
				_g_free0 (dir);
			}
		}
	}
	result = NULL;
	dirs = (_vala_array_free (dirs, dirs_length1, (GDestroyNotify) g_free), NULL);
	return result;
}

static gpointer
_g_object_ref0 (gpointer self)
{
	return self ? g_object_ref (self) : NULL;
}

KkcLanguageModel*
kkc_language_model_metadata_create_language_model (KkcLanguageModelMetadata* self,
                                                   GError** error)
{
	GObject* _tmp0_ = NULL;
	GType _tmp1_;
	GObject* _tmp2_;
	KkcLanguageModel* _tmp3_;
	GError* _inner_error0_ = NULL;
	KkcLanguageModel* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp1_ = self->priv->_model_type;
	_tmp2_ = g_initable_new (_tmp1_, NULL, &_inner_error0_, "metadata", self, NULL, NULL);
	_tmp0_ = _tmp2_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		return NULL;
	}
	_tmp3_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_tmp0_, KKC_TYPE_LANGUAGE_MODEL, KkcLanguageModel));
	result = _tmp3_;
	_g_object_unref0 (_tmp0_);
	return result;
}

GType
kkc_language_model_metadata_get_model_type (KkcLanguageModelMetadata* self)
{
	GType result;
	g_return_val_if_fail (self != NULL, G_TYPE_INVALID);
	result = self->priv->_model_type;
	return result;
}

void
kkc_language_model_metadata_set_model_type (KkcLanguageModelMetadata* self,
                                            GType value)
{
	GType old_value;
	g_return_if_fail (self != NULL);
	old_value = kkc_language_model_metadata_get_model_type (self);
	if (old_value != value) {
		self->priv->_model_type = value;
		g_object_notify_by_pspec ((GObject *) self, kkc_language_model_metadata_properties[KKC_LANGUAGE_MODEL_METADATA_MODEL_TYPE_PROPERTY]);
	}
}

static GType*
_g_type_dup (GType* self)
{
	GType* dup;
	dup = g_new0 (GType, 1);
	memcpy (dup, self, sizeof (GType));
	return dup;
}

static void
kkc_language_model_metadata_class_init (KkcLanguageModelMetadataClass * klass,
                                        gpointer klass_data)
{
	GeeHashMap* _tmp0_;
	GeeMap* _tmp1_;
	GType _tmp2_;
	GeeMap* _tmp3_;
	GType _tmp4_;
	GeeMap* _tmp5_;
	GType _tmp6_;
	GeeMap* _tmp7_;
	GType _tmp8_;
	kkc_language_model_metadata_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &KkcLanguageModelMetadata_private_offset);
	((KkcMetadataFileClass *) klass)->parse = (gboolean (*) (KkcMetadataFile*, JsonObject*, GError**)) kkc_language_model_metadata_real_parse;
	G_OBJECT_CLASS (klass)->get_property = _vala_kkc_language_model_metadata_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_kkc_language_model_metadata_set_property;
	G_OBJECT_CLASS (klass)->finalize = kkc_language_model_metadata_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), KKC_LANGUAGE_MODEL_METADATA_MODEL_TYPE_PROPERTY, kkc_language_model_metadata_properties[KKC_LANGUAGE_MODEL_METADATA_MODEL_TYPE_PROPERTY] = g_param_spec_gtype ("model-type", "model-type", "model-type", G_TYPE_NONE, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT));
	_tmp0_ = gee_hash_map_new (G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, G_TYPE_GTYPE, (GBoxedCopyFunc) _g_type_dup, (GDestroyNotify) g_free, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
	_g_object_unref0 (kkc_language_model_metadata_model_types);
	kkc_language_model_metadata_model_types = (GeeMap*) _tmp0_;
	_tmp1_ = kkc_language_model_metadata_model_types;
	_tmp2_ = KKC_TYPE_TEXT_BIGRAM_LANGUAGE_MODEL;
	gee_map_set (_tmp1_, "text2", &_tmp2_);
	_tmp3_ = kkc_language_model_metadata_model_types;
	_tmp4_ = KKC_TYPE_TEXT_TRIGRAM_LANGUAGE_MODEL;
	gee_map_set (_tmp3_, "text3", &_tmp4_);
	_tmp5_ = kkc_language_model_metadata_model_types;
	_tmp6_ = KKC_TYPE_SORTED_BIGRAM_LANGUAGE_MODEL;
	gee_map_set (_tmp5_, "sorted2", &_tmp6_);
	_tmp7_ = kkc_language_model_metadata_model_types;
	_tmp8_ = KKC_TYPE_SORTED_TRIGRAM_LANGUAGE_MODEL;
	gee_map_set (_tmp7_, "sorted3", &_tmp8_);
}

static void
kkc_language_model_metadata_instance_init (KkcLanguageModelMetadata * self,
                                           gpointer klass)
{
	self->priv = kkc_language_model_metadata_get_instance_private (self);
}

static void
kkc_language_model_metadata_finalize (GObject * obj)
{
	KkcLanguageModelMetadata * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, KKC_TYPE_LANGUAGE_MODEL_METADATA, KkcLanguageModelMetadata);
	G_OBJECT_CLASS (kkc_language_model_metadata_parent_class)->finalize (obj);
}

static GType
kkc_language_model_metadata_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (KkcLanguageModelMetadataClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) kkc_language_model_metadata_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (KkcLanguageModelMetadata), 0, (GInstanceInitFunc) kkc_language_model_metadata_instance_init, NULL };
	GType kkc_language_model_metadata_type_id;
	kkc_language_model_metadata_type_id = g_type_register_static (KKC_TYPE_METADATA_FILE, "KkcLanguageModelMetadata", &g_define_type_info, 0);
	KkcLanguageModelMetadata_private_offset = g_type_add_instance_private (kkc_language_model_metadata_type_id, sizeof (KkcLanguageModelMetadataPrivate));
	return kkc_language_model_metadata_type_id;
}

GType
kkc_language_model_metadata_get_type (void)
{
	static volatile gsize kkc_language_model_metadata_type_id__once = 0;
	if (g_once_init_enter (&kkc_language_model_metadata_type_id__once)) {
		GType kkc_language_model_metadata_type_id;
		kkc_language_model_metadata_type_id = kkc_language_model_metadata_get_type_once ();
		g_once_init_leave (&kkc_language_model_metadata_type_id__once, kkc_language_model_metadata_type_id);
	}
	return kkc_language_model_metadata_type_id__once;
}

static void
_vala_kkc_language_model_metadata_get_property (GObject * object,
                                                guint property_id,
                                                GValue * value,
                                                GParamSpec * pspec)
{
	KkcLanguageModelMetadata * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, KKC_TYPE_LANGUAGE_MODEL_METADATA, KkcLanguageModelMetadata);
	switch (property_id) {
		case KKC_LANGUAGE_MODEL_METADATA_MODEL_TYPE_PROPERTY:
		g_value_set_gtype (value, kkc_language_model_metadata_get_model_type (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_kkc_language_model_metadata_set_property (GObject * object,
                                                guint property_id,
                                                const GValue * value,
                                                GParamSpec * pspec)
{
	KkcLanguageModelMetadata * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, KKC_TYPE_LANGUAGE_MODEL_METADATA, KkcLanguageModelMetadata);
	switch (property_id) {
		case KKC_LANGUAGE_MODEL_METADATA_MODEL_TYPE_PROPERTY:
		kkc_language_model_metadata_set_model_type (self, g_value_get_gtype (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static inline gpointer
kkc_language_model_get_instance_private (KkcLanguageModel* self)
{
	return G_STRUCT_MEMBER_P (self, KkcLanguageModel_private_offset);
}

static GeeCollection*
kkc_language_model_real_unigram_entries (KkcLanguageModel* self,
                                         const gchar* input)
{
	g_critical ("Type `%s' does not implement abstract method `kkc_language_model_unigram_entries'", g_type_name (G_TYPE_FROM_INSTANCE (self)));
	return NULL;
}

GeeCollection*
kkc_language_model_unigram_entries (KkcLanguageModel* self,
                                    const gchar* input)
{
	KkcLanguageModelClass* _klass_;
	g_return_val_if_fail (self != NULL, NULL);
	_klass_ = KKC_LANGUAGE_MODEL_GET_CLASS (self);
	if (_klass_->unigram_entries) {
		return _klass_->unigram_entries (self, input);
	}
	return NULL;
}

static GeeCollection*
kkc_language_model_real_entries (KkcLanguageModel* self,
                                 const gchar* input)
{
	g_critical ("Type `%s' does not implement abstract method `kkc_language_model_entries'", g_type_name (G_TYPE_FROM_INSTANCE (self)));
	return NULL;
}

GeeCollection*
kkc_language_model_entries (KkcLanguageModel* self,
                            const gchar* input)
{
	KkcLanguageModelClass* _klass_;
	g_return_val_if_fail (self != NULL, NULL);
	_klass_ = KKC_LANGUAGE_MODEL_GET_CLASS (self);
	if (_klass_->entries) {
		return _klass_->entries (self, input);
	}
	return NULL;
}

static KkcLanguageModelEntry*
kkc_language_model_real_get (KkcLanguageModel* self,
                             const gchar* input,
                             const gchar* output)
{
	g_critical ("Type `%s' does not implement abstract method `kkc_language_model_get'", g_type_name (G_TYPE_FROM_INSTANCE (self)));
	return NULL;
}

KkcLanguageModelEntry*
kkc_language_model_get (KkcLanguageModel* self,
                        const gchar* input,
                        const gchar* output)
{
	KkcLanguageModelClass* _klass_;
	g_return_val_if_fail (self != NULL, NULL);
	_klass_ = KKC_LANGUAGE_MODEL_GET_CLASS (self);
	if (_klass_->get) {
		return _klass_->get (self, input, output);
	}
	return NULL;
}

KkcLanguageModel*
kkc_language_model_construct (GType object_type,
                              KkcLanguageModelMetadata* metadata,
                              GError** error)
{
	KkcLanguageModel * self = NULL;
	GError* _inner_error0_ = NULL;
	g_return_val_if_fail (metadata != NULL, NULL);
	self = (KkcLanguageModel*) g_object_new (object_type, "metadata", metadata, NULL);
	g_initable_init ((GInitable*) self, NULL, &_inner_error0_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (self);
		return NULL;
	}
	return self;
}

static gboolean
kkc_language_model_real_parse (KkcLanguageModel* self,
                               GError** error)
{
	gboolean _tmp0_ = FALSE;
	g_critical ("Type `%s' does not implement abstract method `kkc_language_model_parse'", g_type_name (G_TYPE_FROM_INSTANCE (self)));
	return _tmp0_;
}

gboolean
kkc_language_model_parse (KkcLanguageModel* self,
                          GError** error)
{
	KkcLanguageModelClass* _klass_;
	g_return_val_if_fail (self != NULL, FALSE);
	_klass_ = KKC_LANGUAGE_MODEL_GET_CLASS (self);
	if (_klass_->parse) {
		return _klass_->parse (self, error);
	}
	return FALSE;
}

static gboolean
kkc_language_model_real_init (GInitable* base,
                              GCancellable* cancellable,
                              GError** error)
{
	KkcLanguageModel * self;
	GError* _inner_error0_ = NULL;
	gboolean result;
	self = (KkcLanguageModel*) base;
	kkc_language_model_parse (self, &_inner_error0_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		gboolean _tmp0_ = FALSE;
		g_propagate_error (error, _inner_error0_);
		return _tmp0_;
	}
	result = TRUE;
	return result;
}

KkcLanguageModel*
kkc_language_model_load (const gchar* name,
                         GError** error)
{
	KkcLanguageModelMetadata* metadata = NULL;
	KkcLanguageModelMetadata* _tmp0_;
	KkcLanguageModelMetadata* _tmp1_;
	KkcLanguageModel* _tmp3_ = NULL;
	KkcLanguageModelMetadata* _tmp4_;
	KkcLanguageModel* _tmp5_;
	KkcLanguageModel* _tmp6_;
	GError* _inner_error0_ = NULL;
	KkcLanguageModel* result;
	g_return_val_if_fail (name != NULL, NULL);
	_tmp0_ = kkc_language_model_metadata_find (name);
	metadata = _tmp0_;
	_tmp1_ = metadata;
	if (_tmp1_ == NULL) {
		GError* _tmp2_;
		_tmp2_ = g_error_new (KKC_LANGUAGE_MODEL_ERROR, KKC_LANGUAGE_MODEL_ERROR_NOT_FOUND, "can't find language model %s", name);
		_inner_error0_ = _tmp2_;
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (metadata);
		return NULL;
	}
	_tmp4_ = metadata;
	_tmp5_ = kkc_language_model_metadata_create_language_model (_tmp4_, &_inner_error0_);
	_tmp3_ = _tmp5_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (metadata);
		return NULL;
	}
	_tmp6_ = _tmp3_;
	_tmp3_ = NULL;
	result = _tmp6_;
	_g_object_unref0 (_tmp3_);
	_g_object_unref0 (metadata);
	return result;
}

KkcLanguageModelMetadata*
kkc_language_model_get_metadata (KkcLanguageModel* self)
{
	KkcLanguageModelMetadata* result;
	KkcLanguageModelMetadata* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_metadata;
	result = _tmp0_;
	return result;
}

void
kkc_language_model_set_metadata (KkcLanguageModel* self,
                                 KkcLanguageModelMetadata* value)
{
	KkcLanguageModelMetadata* old_value;
	g_return_if_fail (self != NULL);
	old_value = kkc_language_model_get_metadata (self);
	if (old_value != value) {
		KkcLanguageModelMetadata* _tmp0_;
		_tmp0_ = _g_object_ref0 (value);
		_g_object_unref0 (self->priv->_metadata);
		self->priv->_metadata = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, kkc_language_model_properties[KKC_LANGUAGE_MODEL_METADATA_PROPERTY]);
	}
}

void
kkc_language_model_get_bos (KkcLanguageModel* self,
                            KkcLanguageModelEntry * result)
{
	KkcLanguageModelClass* _klass_;
	g_return_if_fail (self != NULL);
	_klass_ = KKC_LANGUAGE_MODEL_GET_CLASS (self);
	if (_klass_->get_bos) {
		_klass_->get_bos (self, result);
	}
	return;
}

void
kkc_language_model_get_eos (KkcLanguageModel* self,
                            KkcLanguageModelEntry * result)
{
	KkcLanguageModelClass* _klass_;
	g_return_if_fail (self != NULL);
	_klass_ = KKC_LANGUAGE_MODEL_GET_CLASS (self);
	if (_klass_->get_eos) {
		_klass_->get_eos (self, result);
	}
	return;
}

static void
kkc_language_model_class_init (KkcLanguageModelClass * klass,
                               gpointer klass_data)
{
	kkc_language_model_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &KkcLanguageModel_private_offset);
	((KkcLanguageModelClass *) klass)->unigram_entries = (GeeCollection* (*) (KkcLanguageModel*, const gchar*)) kkc_language_model_real_unigram_entries;
	((KkcLanguageModelClass *) klass)->entries = (GeeCollection* (*) (KkcLanguageModel*, const gchar*)) kkc_language_model_real_entries;
	((KkcLanguageModelClass *) klass)->get = (KkcLanguageModelEntry* (*) (KkcLanguageModel*, const gchar*, const gchar*)) kkc_language_model_real_get;
	((KkcLanguageModelClass *) klass)->parse = (gboolean (*) (KkcLanguageModel*, GError**)) kkc_language_model_real_parse;
	G_OBJECT_CLASS (klass)->get_property = _vala_kkc_language_model_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_kkc_language_model_set_property;
	G_OBJECT_CLASS (klass)->finalize = kkc_language_model_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), KKC_LANGUAGE_MODEL_METADATA_PROPERTY, kkc_language_model_properties[KKC_LANGUAGE_MODEL_METADATA_PROPERTY] = g_param_spec_object ("metadata", "metadata", "metadata", KKC_TYPE_LANGUAGE_MODEL_METADATA, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT));
	g_object_class_install_property (G_OBJECT_CLASS (klass), KKC_LANGUAGE_MODEL_BOS_PROPERTY, kkc_language_model_properties[KKC_LANGUAGE_MODEL_BOS_PROPERTY] = g_param_spec_boxed ("bos", "bos", "bos", KKC_TYPE_LANGUAGE_MODEL_ENTRY, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), KKC_LANGUAGE_MODEL_EOS_PROPERTY, kkc_language_model_properties[KKC_LANGUAGE_MODEL_EOS_PROPERTY] = g_param_spec_boxed ("eos", "eos", "eos", KKC_TYPE_LANGUAGE_MODEL_ENTRY, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
}

static void
kkc_language_model_g_initable_interface_init (GInitableIface * iface,
                                              gpointer iface_data)
{
	kkc_language_model_g_initable_parent_iface = g_type_interface_peek_parent (iface);
	iface->init = (gboolean (*) (GInitable*, GCancellable*, GError**)) kkc_language_model_real_init;
}

static void
kkc_language_model_instance_init (KkcLanguageModel * self,
                                  gpointer klass)
{
	self->priv = kkc_language_model_get_instance_private (self);
}

static void
kkc_language_model_finalize (GObject * obj)
{
	KkcLanguageModel * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, KKC_TYPE_LANGUAGE_MODEL, KkcLanguageModel);
	_g_object_unref0 (self->priv->_metadata);
	G_OBJECT_CLASS (kkc_language_model_parent_class)->finalize (obj);
}

static GType
kkc_language_model_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (KkcLanguageModelClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) kkc_language_model_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (KkcLanguageModel), 0, (GInstanceInitFunc) kkc_language_model_instance_init, NULL };
	static const GInterfaceInfo g_initable_info = { (GInterfaceInitFunc) kkc_language_model_g_initable_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
	GType kkc_language_model_type_id;
	kkc_language_model_type_id = g_type_register_static (G_TYPE_OBJECT, "KkcLanguageModel", &g_define_type_info, G_TYPE_FLAG_ABSTRACT);
	g_type_add_interface_static (kkc_language_model_type_id, g_initable_get_type (), &g_initable_info);
	KkcLanguageModel_private_offset = g_type_add_instance_private (kkc_language_model_type_id, sizeof (KkcLanguageModelPrivate));
	return kkc_language_model_type_id;
}

GType
kkc_language_model_get_type (void)
{
	static volatile gsize kkc_language_model_type_id__once = 0;
	if (g_once_init_enter (&kkc_language_model_type_id__once)) {
		GType kkc_language_model_type_id;
		kkc_language_model_type_id = kkc_language_model_get_type_once ();
		g_once_init_leave (&kkc_language_model_type_id__once, kkc_language_model_type_id);
	}
	return kkc_language_model_type_id__once;
}

static void
_vala_kkc_language_model_get_property (GObject * object,
                                       guint property_id,
                                       GValue * value,
                                       GParamSpec * pspec)
{
	KkcLanguageModel * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, KKC_TYPE_LANGUAGE_MODEL, KkcLanguageModel);
	switch (property_id) {
		case KKC_LANGUAGE_MODEL_METADATA_PROPERTY:
		g_value_set_object (value, kkc_language_model_get_metadata (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_kkc_language_model_set_property (GObject * object,
                                       guint property_id,
                                       const GValue * value,
                                       GParamSpec * pspec)
{
	KkcLanguageModel * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, KKC_TYPE_LANGUAGE_MODEL, KkcLanguageModel);
	switch (property_id) {
		case KKC_LANGUAGE_MODEL_METADATA_PROPERTY:
		kkc_language_model_set_metadata (self, g_value_get_object (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

gdouble
kkc_unigram_language_model_unigram_cost (KkcUnigramLanguageModel* self,
                                         KkcLanguageModelEntry* entry)
{
	KkcUnigramLanguageModelIface* _iface_;
	g_return_val_if_fail (self != NULL, -1.0);
	_iface_ = KKC_UNIGRAM_LANGUAGE_MODEL_GET_INTERFACE (self);
	if (_iface_->unigram_cost) {
		return _iface_->unigram_cost (self, entry);
	}
	return -1.0;
}

gdouble
kkc_unigram_language_model_unigram_backoff (KkcUnigramLanguageModel* self,
                                            KkcLanguageModelEntry* entry)
{
	KkcUnigramLanguageModelIface* _iface_;
	g_return_val_if_fail (self != NULL, -1.0);
	_iface_ = KKC_UNIGRAM_LANGUAGE_MODEL_GET_INTERFACE (self);
	if (_iface_->unigram_backoff) {
		return _iface_->unigram_backoff (self, entry);
	}
	return -1.0;
}

static void
kkc_unigram_language_model_default_init (KkcUnigramLanguageModelIface * iface,
                                         gpointer iface_data)
{
}

static GType
kkc_unigram_language_model_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (KkcUnigramLanguageModelIface), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) kkc_unigram_language_model_default_init, (GClassFinalizeFunc) NULL, NULL, 0, 0, (GInstanceInitFunc) NULL, NULL };
	GType kkc_unigram_language_model_type_id;
	kkc_unigram_language_model_type_id = g_type_register_static (G_TYPE_INTERFACE, "KkcUnigramLanguageModel", &g_define_type_info, 0);
	g_type_interface_add_prerequisite (kkc_unigram_language_model_type_id, KKC_TYPE_LANGUAGE_MODEL);
	return kkc_unigram_language_model_type_id;
}

GType
kkc_unigram_language_model_get_type (void)
{
	static volatile gsize kkc_unigram_language_model_type_id__once = 0;
	if (g_once_init_enter (&kkc_unigram_language_model_type_id__once)) {
		GType kkc_unigram_language_model_type_id;
		kkc_unigram_language_model_type_id = kkc_unigram_language_model_get_type_once ();
		g_once_init_leave (&kkc_unigram_language_model_type_id__once, kkc_unigram_language_model_type_id);
	}
	return kkc_unigram_language_model_type_id__once;
}

gboolean
kkc_bigram_language_model_has_bigram (KkcBigramLanguageModel* self,
                                      KkcLanguageModelEntry* pentry,
                                      KkcLanguageModelEntry* entry)
{
	KkcBigramLanguageModelIface* _iface_;
	g_return_val_if_fail (self != NULL, FALSE);
	_iface_ = KKC_BIGRAM_LANGUAGE_MODEL_GET_INTERFACE (self);
	if (_iface_->has_bigram) {
		return _iface_->has_bigram (self, pentry, entry);
	}
	return FALSE;
}

gdouble
kkc_bigram_language_model_bigram_cost (KkcBigramLanguageModel* self,
                                       KkcLanguageModelEntry* pentry,
                                       KkcLanguageModelEntry* entry)
{
	KkcBigramLanguageModelIface* _iface_;
	g_return_val_if_fail (self != NULL, -1.0);
	_iface_ = KKC_BIGRAM_LANGUAGE_MODEL_GET_INTERFACE (self);
	if (_iface_->bigram_cost) {
		return _iface_->bigram_cost (self, pentry, entry);
	}
	return -1.0;
}

gdouble
kkc_bigram_language_model_bigram_backoff (KkcBigramLanguageModel* self,
                                          KkcLanguageModelEntry* pentry,
                                          KkcLanguageModelEntry* entry)
{
	KkcBigramLanguageModelIface* _iface_;
	g_return_val_if_fail (self != NULL, -1.0);
	_iface_ = KKC_BIGRAM_LANGUAGE_MODEL_GET_INTERFACE (self);
	if (_iface_->bigram_backoff) {
		return _iface_->bigram_backoff (self, pentry, entry);
	}
	return -1.0;
}

gdouble
kkc_bigram_language_model_bigram_backoff_cost (KkcBigramLanguageModel* self,
                                               KkcLanguageModelEntry* pentry,
                                               KkcLanguageModelEntry* entry)
{
	KkcLanguageModelEntry _tmp0_;
	KkcLanguageModelEntry _tmp1_;
	gdouble backoff = 0.0;
	KkcLanguageModelEntry _tmp4_;
	gdouble cost = 0.0;
	KkcLanguageModelEntry _tmp5_;
	gdouble result;
	g_return_val_if_fail (pentry != NULL, -1.0);
	g_return_val_if_fail (entry != NULL, -1.0);
	_tmp0_ = *pentry;
	_tmp1_ = *entry;
	if (kkc_bigram_language_model_has_bigram (self, &_tmp0_, &_tmp1_)) {
		KkcLanguageModelEntry _tmp2_;
		KkcLanguageModelEntry _tmp3_;
		_tmp2_ = *pentry;
		_tmp3_ = *entry;
		result = kkc_bigram_language_model_bigram_cost (self, &_tmp2_, &_tmp3_);
		return result;
	}
	_tmp4_ = *pentry;
	backoff = kkc_unigram_language_model_unigram_backoff ((KkcUnigramLanguageModel*) self, &_tmp4_);
	_tmp5_ = *entry;
	cost = kkc_unigram_language_model_unigram_cost ((KkcUnigramLanguageModel*) self, &_tmp5_);
	result = backoff + cost;
	return result;
}

static void
kkc_bigram_language_model_default_init (KkcBigramLanguageModelIface * iface,
                                        gpointer iface_data)
{
}

static GType
kkc_bigram_language_model_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (KkcBigramLanguageModelIface), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) kkc_bigram_language_model_default_init, (GClassFinalizeFunc) NULL, NULL, 0, 0, (GInstanceInitFunc) NULL, NULL };
	GType kkc_bigram_language_model_type_id;
	kkc_bigram_language_model_type_id = g_type_register_static (G_TYPE_INTERFACE, "KkcBigramLanguageModel", &g_define_type_info, 0);
	g_type_interface_add_prerequisite (kkc_bigram_language_model_type_id, KKC_TYPE_UNIGRAM_LANGUAGE_MODEL);
	return kkc_bigram_language_model_type_id;
}

GType
kkc_bigram_language_model_get_type (void)
{
	static volatile gsize kkc_bigram_language_model_type_id__once = 0;
	if (g_once_init_enter (&kkc_bigram_language_model_type_id__once)) {
		GType kkc_bigram_language_model_type_id;
		kkc_bigram_language_model_type_id = kkc_bigram_language_model_get_type_once ();
		g_once_init_leave (&kkc_bigram_language_model_type_id__once, kkc_bigram_language_model_type_id);
	}
	return kkc_bigram_language_model_type_id__once;
}

gboolean
kkc_trigram_language_model_has_trigram (KkcTrigramLanguageModel* self,
                                        KkcLanguageModelEntry* ppentry,
                                        KkcLanguageModelEntry* pentry,
                                        KkcLanguageModelEntry* entry)
{
	KkcTrigramLanguageModelIface* _iface_;
	g_return_val_if_fail (self != NULL, FALSE);
	_iface_ = KKC_TRIGRAM_LANGUAGE_MODEL_GET_INTERFACE (self);
	if (_iface_->has_trigram) {
		return _iface_->has_trigram (self, ppentry, pentry, entry);
	}
	return FALSE;
}

gdouble
kkc_trigram_language_model_trigram_cost (KkcTrigramLanguageModel* self,
                                         KkcLanguageModelEntry* ppentry,
                                         KkcLanguageModelEntry* pentry,
                                         KkcLanguageModelEntry* entry)
{
	KkcTrigramLanguageModelIface* _iface_;
	g_return_val_if_fail (self != NULL, -1.0);
	_iface_ = KKC_TRIGRAM_LANGUAGE_MODEL_GET_INTERFACE (self);
	if (_iface_->trigram_cost) {
		return _iface_->trigram_cost (self, ppentry, pentry, entry);
	}
	return -1.0;
}

gdouble
kkc_trigram_language_model_trigram_backoff_cost (KkcTrigramLanguageModel* self,
                                                 KkcLanguageModelEntry* ppentry,
                                                 KkcLanguageModelEntry* pentry,
                                                 KkcLanguageModelEntry* entry)
{
	KkcLanguageModelEntry _tmp0_;
	KkcLanguageModelEntry _tmp1_;
	KkcLanguageModelEntry _tmp2_;
	gdouble backoff = 0.0;
	KkcLanguageModelEntry _tmp6_;
	KkcLanguageModelEntry _tmp7_;
	gdouble cost = 0.0;
	KkcLanguageModelEntry _tmp8_;
	KkcLanguageModelEntry _tmp9_;
	gdouble result;
	g_return_val_if_fail (ppentry != NULL, -1.0);
	g_return_val_if_fail (pentry != NULL, -1.0);
	g_return_val_if_fail (entry != NULL, -1.0);
	_tmp0_ = *ppentry;
	_tmp1_ = *pentry;
	_tmp2_ = *entry;
	if (kkc_trigram_language_model_has_trigram (self, &_tmp0_, &_tmp1_, &_tmp2_)) {
		KkcLanguageModelEntry _tmp3_;
		KkcLanguageModelEntry _tmp4_;
		KkcLanguageModelEntry _tmp5_;
		_tmp3_ = *ppentry;
		_tmp4_ = *pentry;
		_tmp5_ = *entry;
		result = kkc_trigram_language_model_trigram_cost (self, &_tmp3_, &_tmp4_, &_tmp5_);
		return result;
	}
	_tmp6_ = *ppentry;
	_tmp7_ = *pentry;
	backoff = kkc_bigram_language_model_bigram_backoff ((KkcBigramLanguageModel*) self, &_tmp6_, &_tmp7_);
	_tmp8_ = *pentry;
	_tmp9_ = *entry;
	cost = kkc_bigram_language_model_bigram_backoff_cost ((KkcBigramLanguageModel*) self, &_tmp8_, &_tmp9_);
	result = backoff + cost;
	return result;
}

static void
kkc_trigram_language_model_default_init (KkcTrigramLanguageModelIface * iface,
                                         gpointer iface_data)
{
}

static GType
kkc_trigram_language_model_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (KkcTrigramLanguageModelIface), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) kkc_trigram_language_model_default_init, (GClassFinalizeFunc) NULL, NULL, 0, 0, (GInstanceInitFunc) NULL, NULL };
	GType kkc_trigram_language_model_type_id;
	kkc_trigram_language_model_type_id = g_type_register_static (G_TYPE_INTERFACE, "KkcTrigramLanguageModel", &g_define_type_info, 0);
	g_type_interface_add_prerequisite (kkc_trigram_language_model_type_id, KKC_TYPE_BIGRAM_LANGUAGE_MODEL);
	return kkc_trigram_language_model_type_id;
}

GType
kkc_trigram_language_model_get_type (void)
{
	static volatile gsize kkc_trigram_language_model_type_id__once = 0;
	if (g_once_init_enter (&kkc_trigram_language_model_type_id__once)) {
		GType kkc_trigram_language_model_type_id;
		kkc_trigram_language_model_type_id = kkc_trigram_language_model_get_type_once ();
		g_once_init_leave (&kkc_trigram_language_model_type_id__once, kkc_trigram_language_model_type_id);
	}
	return kkc_trigram_language_model_type_id__once;
}

static void
_vala_array_destroy (gpointer array,
                     gssize array_length,
                     GDestroyNotify destroy_func)
{
	if ((array != NULL) && (destroy_func != NULL)) {
		gssize i;
		for (i = 0; i < array_length; i = i + 1) {
			if (((gpointer*) array)[i] != NULL) {
				destroy_func (((gpointer*) array)[i]);
			}
		}
	}
}

static void
_vala_array_free (gpointer array,
                  gssize array_length,
                  GDestroyNotify destroy_func)
{
	_vala_array_destroy (array, array_length, destroy_func);
	g_free (array);
}

