/* text-bigram-language-model.c generated by valac 0.56.19, the Vala compiler
 * generated from text-bigram-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 <gee.h>
#include <glib-object.h>
#include <float.h>
#include <math.h>
#include <gio/gio.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

enum  {
	KKC_TEXT_BIGRAM_LANGUAGE_MODEL_0_PROPERTY,
	KKC_TEXT_BIGRAM_LANGUAGE_MODEL_BOS_PROPERTY,
	KKC_TEXT_BIGRAM_LANGUAGE_MODEL_EOS_PROPERTY,
	KKC_TEXT_BIGRAM_LANGUAGE_MODEL_NUM_PROPERTIES
};
static GParamSpec* kkc_text_bigram_language_model_properties[KKC_TEXT_BIGRAM_LANGUAGE_MODEL_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_string_free0(var) ((var == NULL) ? NULL : (var = (g_string_free (var, TRUE), NULL)))

struct _KkcTextBigramLanguageModelPrivate {
	KkcLanguageModelEntry _bos;
	KkcLanguageModelEntry _eos;
};

static gint KkcTextBigramLanguageModel_private_offset;
static gpointer kkc_text_bigram_language_model_parent_class = NULL;
static KkcUnigramLanguageModelIface * kkc_text_bigram_language_model_kkc_unigram_language_model_parent_iface = NULL;
static KkcBigramLanguageModelIface * kkc_text_bigram_language_model_kkc_bigram_language_model_parent_iface = NULL;

static gdouble* _double_dup (gdouble* self);
static GeeCollection* kkc_text_bigram_language_model_real_unigram_entries (KkcLanguageModel* base,
                                                                    const gchar* input);
static GeeCollection* kkc_text_bigram_language_model_real_entries (KkcLanguageModel* base,
                                                            const gchar* input);
static KkcLanguageModelEntry* kkc_text_bigram_language_model_real_get (KkcLanguageModel* base,
                                                                const gchar* input,
                                                                const gchar* output);
static gboolean kkc_text_bigram_language_model_real_has_bigram (KkcBigramLanguageModel* base,
                                                         KkcLanguageModelEntry* pentry,
                                                         KkcLanguageModelEntry* entry);
static gdouble kkc_text_bigram_language_model_real_unigram_cost (KkcUnigramLanguageModel* base,
                                                          KkcLanguageModelEntry* entry);
static gdouble kkc_text_bigram_language_model_real_unigram_backoff (KkcUnigramLanguageModel* base,
                                                             KkcLanguageModelEntry* entry);
static gdouble kkc_text_bigram_language_model_real_bigram_cost (KkcBigramLanguageModel* base,
                                                         KkcLanguageModelEntry* pentry,
                                                         KkcLanguageModelEntry* entry);
static gdouble kkc_text_bigram_language_model_real_bigram_backoff (KkcBigramLanguageModel* base,
                                                            KkcLanguageModelEntry* pentry,
                                                            KkcLanguageModelEntry* entry);
static void _vala_array_add1 (guint* * array,
                       gint* length,
                       gint* size,
                       guint value);
static gboolean kkc_text_bigram_language_model_real_parse (KkcLanguageModel* base,
                                                    GError** error);
static void kkc_text_bigram_language_model_finalize (GObject * obj);
static GType kkc_text_bigram_language_model_get_type_once (void);
static void _vala_kkc_text_bigram_language_model_get_property (GObject * object,
                                                        guint property_id,
                                                        GValue * value,
                                                        GParamSpec * pspec);
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);
static gssize _vala_array_length (gpointer array);

static inline gpointer
kkc_text_bigram_language_model_get_instance_private (KkcTextBigramLanguageModel* self)
{
	return G_STRUCT_MEMBER_P (self, KkcTextBigramLanguageModel_private_offset);
}

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

static GeeCollection*
kkc_text_bigram_language_model_real_unigram_entries (KkcLanguageModel* base,
                                                     const gchar* input)
{
	KkcTextBigramLanguageModel * self;
	GeeMap* _tmp0_;
	gpointer _tmp1_;
	GeeCollection* result;
	self = (KkcTextBigramLanguageModel*) base;
	g_return_val_if_fail (input != NULL, NULL);
	_tmp0_ = self->input_map;
	_tmp1_ = gee_map_get (_tmp0_, input);
	result = (GeeCollection*) ((GeeArrayList*) _tmp1_);
	return result;
}

static gint
string_index_of_nth_char (const gchar* self,
                          glong c)
{
	gchar* _tmp0_;
	gint result;
	g_return_val_if_fail (self != NULL, -1);
	_tmp0_ = g_utf8_offset_to_pointer (self, c);
	result = (gint) (_tmp0_ - ((gchar*) self));
	return result;
}

static glong
string_strnlen (gchar* str,
                glong maxlen)
{
	gchar* end = NULL;
	gchar* _tmp0_;
	gchar* _tmp1_;
	glong result;
	_tmp0_ = memchr (str, 0, (gsize) maxlen);
	end = _tmp0_;
	_tmp1_ = end;
	if (_tmp1_ == NULL) {
		result = maxlen;
		return result;
	} else {
		gchar* _tmp2_;
		_tmp2_ = end;
		result = (glong) (_tmp2_ - str);
		return result;
	}
}

static gchar*
string_substring (const gchar* self,
                  glong offset,
                  glong len)
{
	glong string_length = 0L;
	gboolean _tmp0_ = FALSE;
	gchar* _tmp3_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	if (offset >= ((glong) 0)) {
		_tmp0_ = len >= ((glong) 0);
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		string_length = string_strnlen ((gchar*) self, offset + len);
	} else {
		gint _tmp1_;
		gint _tmp2_;
		_tmp1_ = strlen (self);
		_tmp2_ = _tmp1_;
		string_length = (glong) _tmp2_;
	}
	if (offset < ((glong) 0)) {
		offset = string_length + offset;
		g_return_val_if_fail (offset >= ((glong) 0), NULL);
	} else {
		g_return_val_if_fail (offset <= string_length, NULL);
	}
	if (len < ((glong) 0)) {
		len = string_length - offset;
	}
	g_return_val_if_fail ((offset + len) <= string_length, NULL);
	_tmp3_ = g_strndup (((gchar*) self) + offset, (gsize) len);
	result = _tmp3_;
	return result;
}

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

static GeeCollection*
kkc_text_bigram_language_model_real_entries (KkcLanguageModel* base,
                                             const gchar* input)
{
	KkcTextBigramLanguageModel * self;
	GeeArrayList* entries = NULL;
	GeeArrayList* _tmp0_;
	GeeArrayList* _tmp11_;
	GeeCollection* _tmp12_;
	GeeCollection* result;
	self = (KkcTextBigramLanguageModel*) base;
	g_return_val_if_fail (input != NULL, NULL);
	_tmp0_ = gee_array_list_new (KKC_TYPE_LANGUAGE_MODEL_ENTRY, (GBoxedCopyFunc) kkc_language_model_entry_dup, (GDestroyNotify) kkc_language_model_entry_free, NULL, NULL, NULL);
	entries = _tmp0_;
	{
		gint i = 0;
		i = 1;
		{
			gboolean _tmp1_ = FALSE;
			_tmp1_ = TRUE;
			while (TRUE) {
				glong byte_offset = 0L;
				gchar* str = NULL;
				gchar* _tmp3_;
				GeeMap* _tmp4_;
				const gchar* _tmp5_;
				if (!_tmp1_) {
					gint _tmp2_;
					_tmp2_ = i;
					i = _tmp2_ + 1;
				}
				_tmp1_ = FALSE;
				if (!(i < (g_utf8_strlen (input, (gssize) -1) + 1))) {
					break;
				}
				byte_offset = (glong) string_index_of_nth_char (input, (glong) i);
				_tmp3_ = string_substring (input, (glong) 0, byte_offset);
				str = _tmp3_;
				_tmp4_ = self->input_map;
				_tmp5_ = str;
				if (gee_map_has_key (_tmp4_, _tmp5_)) {
					GeeArrayList* _tmp6_;
					GeeMap* _tmp7_;
					const gchar* _tmp8_;
					gpointer _tmp9_;
					GeeArrayList* _tmp10_;
					_tmp6_ = entries;
					_tmp7_ = self->input_map;
					_tmp8_ = str;
					_tmp9_ = gee_map_get (_tmp7_, _tmp8_);
					_tmp10_ = (GeeArrayList*) _tmp9_;
					gee_array_list_add_all (_tmp6_, (GeeCollection*) _tmp10_);
					_g_object_unref0 (_tmp10_);
				}
				_g_free0 (str);
			}
		}
	}
	_tmp11_ = entries;
	_tmp12_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_tmp11_, GEE_TYPE_COLLECTION, GeeCollection));
	result = _tmp12_;
	_g_object_unref0 (entries);
	return result;
}

static KkcLanguageModelEntry*
kkc_text_bigram_language_model_real_get (KkcLanguageModel* base,
                                         const gchar* input,
                                         const gchar* output)
{
	KkcTextBigramLanguageModel * self;
	KkcLanguageModelEntry* result;
	self = (KkcTextBigramLanguageModel*) base;
	g_return_val_if_fail (input != NULL, NULL);
	g_return_val_if_fail (output != NULL, NULL);
	result = NULL;
	return result;
}

gchar*
kkc_text_bigram_language_model_get_key (KkcTextBigramLanguageModel* self,
                                        guint* ids,
                                        gint ids_length1)
{
	GString* builder = NULL;
	GString* _tmp0_;
	GString* _tmp2_;
	const gchar* _tmp3_;
	gchar* _tmp4_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = g_string_new ("");
	builder = _tmp0_;
	{
		guint* id_collection = NULL;
		gint id_collection_length1 = 0;
		gint _id_collection_size_ = 0;
		gint id_it = 0;
		id_collection = ids;
		id_collection_length1 = ids_length1;
		for (id_it = 0; id_it < id_collection_length1; id_it = id_it + 1) {
			guint id = 0U;
			id = id_collection[id_it];
			{
				GString* _tmp1_;
				_tmp1_ = builder;
				g_string_append_printf (_tmp1_, "%08X", id);
			}
		}
	}
	_tmp2_ = builder;
	_tmp3_ = _tmp2_->str;
	_tmp4_ = g_strdup (_tmp3_);
	result = _tmp4_;
	_g_string_free0 (builder);
	return result;
}

static gboolean
kkc_text_bigram_language_model_real_has_bigram (KkcBigramLanguageModel* base,
                                                KkcLanguageModelEntry* pentry,
                                                KkcLanguageModelEntry* entry)
{
	KkcTextBigramLanguageModel * self;
	gchar* key = NULL;
	KkcLanguageModelEntry _tmp0_;
	KkcLanguageModelEntry _tmp1_;
	guint* _tmp2_;
	guint* _tmp3_;
	gint _tmp3__length1;
	gchar* _tmp4_;
	gchar* _tmp5_;
	GeeMap* _tmp6_;
	gboolean result;
	self = (KkcTextBigramLanguageModel*) base;
	g_return_val_if_fail (pentry != NULL, FALSE);
	g_return_val_if_fail (entry != NULL, FALSE);
	_tmp0_ = *pentry;
	_tmp1_ = *entry;
	_tmp2_ = g_new0 (guint, 2);
	_tmp2_[0] = _tmp0_.id;
	_tmp2_[1] = _tmp1_.id;
	_tmp3_ = _tmp2_;
	_tmp3__length1 = 2;
	_tmp4_ = kkc_text_bigram_language_model_get_key (self, _tmp3_, (gint) 2);
	_tmp5_ = _tmp4_;
	_tmp3_ = (g_free (_tmp3_), NULL);
	key = _tmp5_;
	_tmp6_ = self->cost_map;
	result = gee_map_has_key (_tmp6_, (const gchar*) key);
	_g_free0 (key);
	return result;
}

static gdouble
kkc_text_bigram_language_model_real_unigram_cost (KkcUnigramLanguageModel* base,
                                                  KkcLanguageModelEntry* entry)
{
	KkcTextBigramLanguageModel * self;
	gchar* key = NULL;
	KkcLanguageModelEntry _tmp0_;
	guint* _tmp1_;
	guint* _tmp2_;
	gint _tmp2__length1;
	gchar* _tmp3_;
	gchar* _tmp4_;
	GeeMap* _tmp5_;
	const gchar* _tmp6_;
	gdouble result;
	self = (KkcTextBigramLanguageModel*) base;
	g_return_val_if_fail (entry != NULL, -1.0);
	_tmp0_ = *entry;
	_tmp1_ = g_new0 (guint, 1);
	_tmp1_[0] = _tmp0_.id;
	_tmp2_ = _tmp1_;
	_tmp2__length1 = 1;
	_tmp3_ = kkc_text_bigram_language_model_get_key (self, _tmp2_, (gint) 1);
	_tmp4_ = _tmp3_;
	_tmp2_ = (g_free (_tmp2_), NULL);
	key = _tmp4_;
	_tmp5_ = self->cost_map;
	_tmp6_ = key;
	if (gee_map_has_key (_tmp5_, _tmp6_)) {
		GeeMap* _tmp7_;
		const gchar* _tmp8_;
		gpointer _tmp9_;
		gdouble* _tmp10_;
		gdouble _tmp11_;
		_tmp7_ = self->cost_map;
		_tmp8_ = key;
		_tmp9_ = gee_map_get (_tmp7_, _tmp8_);
		_tmp10_ = (gdouble*) _tmp9_;
		_tmp11_ = *_tmp10_;
		_g_free0 (_tmp10_);
		result = _tmp11_;
		_g_free0 (key);
		return result;
	}
	result = (gdouble) 0;
	_g_free0 (key);
	return result;
}

static gdouble
kkc_text_bigram_language_model_real_unigram_backoff (KkcUnigramLanguageModel* base,
                                                     KkcLanguageModelEntry* entry)
{
	KkcTextBigramLanguageModel * self;
	gchar* key = NULL;
	KkcLanguageModelEntry _tmp0_;
	guint* _tmp1_;
	guint* _tmp2_;
	gint _tmp2__length1;
	gchar* _tmp3_;
	gchar* _tmp4_;
	GeeMap* _tmp5_;
	const gchar* _tmp6_;
	gdouble result;
	self = (KkcTextBigramLanguageModel*) base;
	g_return_val_if_fail (entry != NULL, -1.0);
	_tmp0_ = *entry;
	_tmp1_ = g_new0 (guint, 1);
	_tmp1_[0] = _tmp0_.id;
	_tmp2_ = _tmp1_;
	_tmp2__length1 = 1;
	_tmp3_ = kkc_text_bigram_language_model_get_key (self, _tmp2_, (gint) 1);
	_tmp4_ = _tmp3_;
	_tmp2_ = (g_free (_tmp2_), NULL);
	key = _tmp4_;
	_tmp5_ = self->backoff_map;
	_tmp6_ = key;
	if (gee_map_has_key (_tmp5_, _tmp6_)) {
		GeeMap* _tmp7_;
		const gchar* _tmp8_;
		gpointer _tmp9_;
		gdouble* _tmp10_;
		gdouble _tmp11_;
		_tmp7_ = self->backoff_map;
		_tmp8_ = key;
		_tmp9_ = gee_map_get (_tmp7_, _tmp8_);
		_tmp10_ = (gdouble*) _tmp9_;
		_tmp11_ = *_tmp10_;
		_g_free0 (_tmp10_);
		result = _tmp11_;
		_g_free0 (key);
		return result;
	}
	result = (gdouble) 0;
	_g_free0 (key);
	return result;
}

static gdouble
kkc_text_bigram_language_model_real_bigram_cost (KkcBigramLanguageModel* base,
                                                 KkcLanguageModelEntry* pentry,
                                                 KkcLanguageModelEntry* entry)
{
	KkcTextBigramLanguageModel * self;
	gchar* key = NULL;
	KkcLanguageModelEntry _tmp0_;
	KkcLanguageModelEntry _tmp1_;
	guint* _tmp2_;
	guint* _tmp3_;
	gint _tmp3__length1;
	gchar* _tmp4_;
	gchar* _tmp5_;
	GeeMap* _tmp6_;
	const gchar* _tmp7_;
	gdouble result;
	self = (KkcTextBigramLanguageModel*) base;
	g_return_val_if_fail (pentry != NULL, -1.0);
	g_return_val_if_fail (entry != NULL, -1.0);
	_tmp0_ = *pentry;
	_tmp1_ = *entry;
	_tmp2_ = g_new0 (guint, 2);
	_tmp2_[0] = _tmp0_.id;
	_tmp2_[1] = _tmp1_.id;
	_tmp3_ = _tmp2_;
	_tmp3__length1 = 2;
	_tmp4_ = kkc_text_bigram_language_model_get_key (self, _tmp3_, (gint) 2);
	_tmp5_ = _tmp4_;
	_tmp3_ = (g_free (_tmp3_), NULL);
	key = _tmp5_;
	_tmp6_ = self->cost_map;
	_tmp7_ = key;
	if (gee_map_has_key (_tmp6_, _tmp7_)) {
		GeeMap* _tmp8_;
		const gchar* _tmp9_;
		gpointer _tmp10_;
		gdouble* _tmp11_;
		gdouble _tmp12_;
		_tmp8_ = self->cost_map;
		_tmp9_ = key;
		_tmp10_ = gee_map_get (_tmp8_, _tmp9_);
		_tmp11_ = (gdouble*) _tmp10_;
		_tmp12_ = *_tmp11_;
		_g_free0 (_tmp11_);
		result = _tmp12_;
		_g_free0 (key);
		return result;
	}
	result = (gdouble) 0;
	_g_free0 (key);
	return result;
}

static gdouble
kkc_text_bigram_language_model_real_bigram_backoff (KkcBigramLanguageModel* base,
                                                    KkcLanguageModelEntry* pentry,
                                                    KkcLanguageModelEntry* entry)
{
	KkcTextBigramLanguageModel * self;
	gchar* key = NULL;
	KkcLanguageModelEntry _tmp0_;
	KkcLanguageModelEntry _tmp1_;
	guint* _tmp2_;
	guint* _tmp3_;
	gint _tmp3__length1;
	gchar* _tmp4_;
	gchar* _tmp5_;
	GeeMap* _tmp6_;
	const gchar* _tmp7_;
	gdouble result;
	self = (KkcTextBigramLanguageModel*) base;
	g_return_val_if_fail (pentry != NULL, -1.0);
	g_return_val_if_fail (entry != NULL, -1.0);
	_tmp0_ = *pentry;
	_tmp1_ = *entry;
	_tmp2_ = g_new0 (guint, 2);
	_tmp2_[0] = _tmp0_.id;
	_tmp2_[1] = _tmp1_.id;
	_tmp3_ = _tmp2_;
	_tmp3__length1 = 2;
	_tmp4_ = kkc_text_bigram_language_model_get_key (self, _tmp3_, (gint) 2);
	_tmp5_ = _tmp4_;
	_tmp3_ = (g_free (_tmp3_), NULL);
	key = _tmp5_;
	_tmp6_ = self->backoff_map;
	_tmp7_ = key;
	if (gee_map_has_key (_tmp6_, _tmp7_)) {
		GeeMap* _tmp8_;
		const gchar* _tmp9_;
		gpointer _tmp10_;
		gdouble* _tmp11_;
		gdouble _tmp12_;
		_tmp8_ = self->backoff_map;
		_tmp9_ = key;
		_tmp10_ = gee_map_get (_tmp8_, _tmp9_);
		_tmp11_ = (gdouble*) _tmp10_;
		_tmp12_ = *_tmp11_;
		_g_free0 (_tmp11_);
		result = _tmp12_;
		_g_free0 (key);
		return result;
	}
	result = (gdouble) 0;
	_g_free0 (key);
	return result;
}

static gchar*
string_strip (const gchar* self)
{
	gchar* _result_ = NULL;
	gchar* _tmp0_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = g_strdup (self);
	_result_ = _tmp0_;
	g_strstrip (_result_);
	result = _result_;
	return result;
}

static gboolean
string_contains (const gchar* self,
                 const gchar* needle)
{
	gchar* _tmp0_;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (needle != NULL, FALSE);
	_tmp0_ = strstr ((gchar*) self, (gchar*) needle);
	result = _tmp0_ != NULL;
	return result;
}

static gdouble
double_parse (const gchar* str)
{
	gdouble result;
	g_return_val_if_fail (str != NULL, -1.0);
	result = g_ascii_strtod (str, NULL);
	return result;
}

static void
_vala_array_add1 (guint* * array,
                  gint* length,
                  gint* size,
                  guint value)
{
	if ((*length) == (*size)) {
		*size = (*size) ? (2 * (*size)) : 4;
		*array = g_renew (guint, *array, *size);
	}
	(*array)[(*length)++] = value;
}

void
kkc_text_bigram_language_model_parse_lm (KkcTextBigramLanguageModel* self,
                                         const gchar* input,
                                         GError** error)
{
	GFile* lm_file = NULL;
	GFile* _tmp0_;
	GFileInputStream* _tmp1_ = NULL;
	GFile* _tmp2_;
	GFileInputStream* _tmp3_;
	GDataInputStream* lm_data = NULL;
	GDataInputStream* _tmp4_;
	guint id = 0U;
	GError* _inner_error0_ = NULL;
	g_return_if_fail (self != NULL);
	g_return_if_fail (input != NULL);
	_tmp0_ = g_file_new_for_path (input);
	lm_file = _tmp0_;
	_tmp2_ = lm_file;
	_tmp3_ = g_file_read (_tmp2_, NULL, &_inner_error0_);
	_tmp1_ = _tmp3_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (lm_file);
		return;
	}
	_tmp4_ = g_data_input_stream_new ((GInputStream*) _tmp1_);
	lm_data = _tmp4_;
	while (TRUE) {
		gsize length = 0UL;
		gchar* line = NULL;
		GDataInputStream* _tmp5_;
		gsize _tmp6_ = 0UL;
		gchar* _tmp7_;
		const gchar* _tmp8_;
		const gchar* _tmp9_;
		gchar* _tmp10_;
		const gchar* _tmp11_;
		const gchar* _tmp12_;
		_tmp5_ = lm_data;
		_tmp7_ = g_data_input_stream_read_line (_tmp5_, &_tmp6_, NULL, &_inner_error0_);
		length = _tmp6_;
		line = _tmp7_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (lm_data);
			_g_object_unref0 (_tmp1_);
			_g_object_unref0 (lm_file);
			return;
		}
		_tmp8_ = line;
		if (_tmp8_ == NULL) {
			_g_free0 (line);
			break;
		}
		_tmp9_ = line;
		_tmp10_ = string_strip (_tmp9_);
		_g_free0 (line);
		line = _tmp10_;
		_tmp11_ = line;
		if (g_strcmp0 (_tmp11_, "") == 0) {
			_g_free0 (line);
			continue;
		}
		_tmp12_ = line;
		if (g_str_has_prefix (_tmp12_, "\\1-grams:")) {
			_g_free0 (line);
			break;
		}
		_g_free0 (line);
	}
	id = (guint) 0;
	while (TRUE) {
		gsize length = 0UL;
		gchar* line = NULL;
		GDataInputStream* _tmp13_;
		gsize _tmp14_ = 0UL;
		gchar* _tmp15_;
		const gchar* _tmp16_;
		const gchar* _tmp17_;
		gchar* _tmp18_;
		gboolean _tmp19_ = FALSE;
		const gchar* _tmp20_;
		gchar** strv = NULL;
		const gchar* _tmp22_;
		gchar** _tmp23_;
		gchar** _tmp24_;
		gint strv_length1;
		gint _strv_size_;
		gchar** _tmp25_;
		gint _tmp25__length1;
		const gchar* _tmp26_;
		gdouble cost = 0.0;
		gchar** _tmp79_;
		gint _tmp79__length1;
		const gchar* _tmp80_;
		gdouble backoff = 0.0;
		gchar** _tmp81_;
		gint _tmp81__length1;
		gchar** words = NULL;
		gchar** _tmp84_;
		gint _tmp84__length1;
		const gchar* _tmp85_;
		gchar** _tmp86_;
		gchar** _tmp87_;
		gint words_length1;
		gint _words_size_;
		guint* ids = NULL;
		guint* _tmp88_;
		gint ids_length1;
		gint _ids_size_;
		gchar** _tmp89_;
		gint _tmp89__length1;
		gchar* key = NULL;
		guint* _tmp94_;
		gint _tmp94__length1;
		gchar* _tmp95_;
		GeeMap* _tmp96_;
		const gchar* _tmp97_;
		GeeMap* _tmp98_;
		const gchar* _tmp99_;
		_tmp13_ = lm_data;
		_tmp15_ = g_data_input_stream_read_line (_tmp13_, &_tmp14_, NULL, &_inner_error0_);
		length = _tmp14_;
		line = _tmp15_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (lm_data);
			_g_object_unref0 (_tmp1_);
			_g_object_unref0 (lm_file);
			return;
		}
		_tmp16_ = line;
		if (_tmp16_ == NULL) {
			_g_free0 (line);
			break;
		}
		_tmp17_ = line;
		_tmp18_ = string_strip (_tmp17_);
		_g_free0 (line);
		line = _tmp18_;
		_tmp20_ = line;
		if (g_strcmp0 (_tmp20_, "") == 0) {
			_tmp19_ = TRUE;
		} else {
			const gchar* _tmp21_;
			_tmp21_ = line;
			_tmp19_ = g_str_has_prefix (_tmp21_, "\\");
		}
		if (_tmp19_) {
			_g_free0 (line);
			continue;
		}
		_tmp22_ = line;
		_tmp24_ = _tmp23_ = g_strsplit (_tmp22_, "\t", 0);
		strv = _tmp24_;
		strv_length1 = _vala_array_length (_tmp23_);
		_strv_size_ = strv_length1;
		_tmp25_ = strv;
		_tmp25__length1 = strv_length1;
		_tmp26_ = _tmp25_[1];
		if (!string_contains (_tmp26_, " ")) {
			GeeMap* _tmp27_;
			gchar** _tmp28_;
			gint _tmp28__length1;
			const gchar* _tmp29_;
			gchar** input_output = NULL;
			gint input_output_length1 = 0;
			gint _input_output_size_ = 0;
			gboolean _tmp30_ = FALSE;
			gboolean _tmp31_ = FALSE;
			gchar** _tmp32_;
			gint _tmp32__length1;
			const gchar* _tmp33_;
			KkcLanguageModelEntry entry = {0};
			gchar** _tmp47_;
			gint _tmp47__length1;
			const gchar* _tmp48_;
			gchar* _tmp49_;
			gchar** _tmp50_;
			gint _tmp50__length1;
			const gchar* _tmp51_;
			gchar* _tmp52_;
			guint _tmp53_;
			KkcLanguageModelEntry _tmp54_ = {0};
			gchar** _tmp55_;
			gint _tmp55__length1;
			const gchar* _tmp56_;
			GeeMap* _tmp65_;
			gchar** _tmp66_;
			gint _tmp66__length1;
			const gchar* _tmp67_;
			GeeMap* _tmp73_;
			gchar** _tmp74_;
			gint _tmp74__length1;
			const gchar* _tmp75_;
			gpointer _tmp76_;
			GeeArrayList* _tmp77_;
			KkcLanguageModelEntry _tmp78_;
			_tmp27_ = self->id_map;
			_tmp28_ = strv;
			_tmp28__length1 = strv_length1;
			_tmp29_ = _tmp28_[1];
			gee_map_set (_tmp27_, _tmp29_, (gpointer) ((guintptr) id));
			_tmp32_ = strv;
			_tmp32__length1 = strv_length1;
			_tmp33_ = _tmp32_[1];
			if (g_strcmp0 (_tmp33_, "<s>") == 0) {
				_tmp31_ = TRUE;
			} else {
				gchar** _tmp34_;
				gint _tmp34__length1;
				const gchar* _tmp35_;
				_tmp34_ = strv;
				_tmp34__length1 = strv_length1;
				_tmp35_ = _tmp34_[1];
				_tmp31_ = g_strcmp0 (_tmp35_, "</s>") == 0;
			}
			if (_tmp31_) {
				_tmp30_ = TRUE;
			} else {
				gchar** _tmp36_;
				gint _tmp36__length1;
				const gchar* _tmp37_;
				_tmp36_ = strv;
				_tmp36__length1 = strv_length1;
				_tmp37_ = _tmp36_[1];
				_tmp30_ = g_strcmp0 (_tmp37_, "<UNK>") == 0;
			}
			if (_tmp30_) {
				gchar* _tmp38_;
				gchar** _tmp39_;
				gint _tmp39__length1;
				const gchar* _tmp40_;
				gchar* _tmp41_;
				gchar** _tmp42_;
				_tmp38_ = g_strdup (" ");
				_tmp39_ = strv;
				_tmp39__length1 = strv_length1;
				_tmp40_ = _tmp39_[1];
				_tmp41_ = g_strdup (_tmp40_);
				_tmp42_ = g_new0 (gchar*, 2 + 1);
				_tmp42_[0] = _tmp38_;
				_tmp42_[1] = _tmp41_;
				input_output = (_vala_array_free (input_output, input_output_length1, (GDestroyNotify) g_free), NULL);
				input_output = _tmp42_;
				input_output_length1 = 2;
				_input_output_size_ = input_output_length1;
			} else {
				gchar** _tmp43_;
				gint _tmp43__length1;
				const gchar* _tmp44_;
				gchar** _tmp45_;
				gchar** _tmp46_;
				_tmp43_ = strv;
				_tmp43__length1 = strv_length1;
				_tmp44_ = _tmp43_[1];
				_tmp46_ = _tmp45_ = g_strsplit (_tmp44_, "/", 0);
				input_output = (_vala_array_free (input_output, input_output_length1, (GDestroyNotify) g_free), NULL);
				input_output = _tmp46_;
				input_output_length1 = _vala_array_length (_tmp45_);
				_input_output_size_ = input_output_length1;
			}
			_tmp47_ = input_output;
			_tmp47__length1 = input_output_length1;
			_tmp48_ = _tmp47_[0];
			_tmp49_ = g_strdup (_tmp48_);
			_tmp50_ = input_output;
			_tmp50__length1 = input_output_length1;
			_tmp51_ = _tmp50_[1];
			_tmp52_ = g_strdup (_tmp51_);
			_tmp53_ = id;
			id = _tmp53_ + 1;
			_g_free0 (_tmp54_.input);
			_tmp54_.input = _tmp49_;
			_g_free0 (_tmp54_.output);
			_tmp54_.output = _tmp52_;
			_tmp54_.id = _tmp53_;
			entry = _tmp54_;
			_tmp55_ = strv;
			_tmp55__length1 = strv_length1;
			_tmp56_ = _tmp55_[1];
			if (g_strcmp0 (_tmp56_, "<s>") == 0) {
				KkcLanguageModelEntry _tmp57_;
				KkcLanguageModelEntry _tmp58_;
				KkcLanguageModelEntry _tmp59_ = {0};
				_tmp57_ = entry;
				_tmp58_ = _tmp57_;
				kkc_language_model_entry_copy (&_tmp58_, &_tmp59_);
				kkc_language_model_entry_destroy (&self->priv->_bos);
				self->priv->_bos = _tmp59_;
			} else {
				gchar** _tmp60_;
				gint _tmp60__length1;
				const gchar* _tmp61_;
				_tmp60_ = strv;
				_tmp60__length1 = strv_length1;
				_tmp61_ = _tmp60_[1];
				if (g_strcmp0 (_tmp61_, "</s>") == 0) {
					KkcLanguageModelEntry _tmp62_;
					KkcLanguageModelEntry _tmp63_;
					KkcLanguageModelEntry _tmp64_ = {0};
					_tmp62_ = entry;
					_tmp63_ = _tmp62_;
					kkc_language_model_entry_copy (&_tmp63_, &_tmp64_);
					kkc_language_model_entry_destroy (&self->priv->_eos);
					self->priv->_eos = _tmp64_;
				}
			}
			_tmp65_ = self->input_map;
			_tmp66_ = input_output;
			_tmp66__length1 = input_output_length1;
			_tmp67_ = _tmp66_[0];
			if (!gee_map_has_key (_tmp65_, _tmp67_)) {
				GeeMap* _tmp68_;
				gchar** _tmp69_;
				gint _tmp69__length1;
				const gchar* _tmp70_;
				GeeArrayList* _tmp71_;
				GeeArrayList* _tmp72_;
				_tmp68_ = self->input_map;
				_tmp69_ = input_output;
				_tmp69__length1 = input_output_length1;
				_tmp70_ = _tmp69_[0];
				_tmp71_ = gee_array_list_new (KKC_TYPE_LANGUAGE_MODEL_ENTRY, (GBoxedCopyFunc) kkc_language_model_entry_dup, (GDestroyNotify) kkc_language_model_entry_free, NULL, NULL, NULL);
				_tmp72_ = _tmp71_;
				gee_map_set (_tmp68_, _tmp70_, _tmp72_);
				_g_object_unref0 (_tmp72_);
			}
			_tmp73_ = self->input_map;
			_tmp74_ = input_output;
			_tmp74__length1 = input_output_length1;
			_tmp75_ = _tmp74_[0];
			_tmp76_ = gee_map_get (_tmp73_, _tmp75_);
			_tmp77_ = (GeeArrayList*) _tmp76_;
			_tmp78_ = entry;
			gee_abstract_collection_add ((GeeAbstractCollection*) _tmp77_, &_tmp78_);
			_g_object_unref0 (_tmp77_);
			kkc_language_model_entry_destroy (&entry);
			input_output = (_vala_array_free (input_output, input_output_length1, (GDestroyNotify) g_free), NULL);
		}
		_tmp79_ = strv;
		_tmp79__length1 = strv_length1;
		_tmp80_ = _tmp79_[0];
		cost = double_parse (_tmp80_);
		backoff = 0.0;
		_tmp81_ = strv;
		_tmp81__length1 = strv_length1;
		if (_tmp81__length1 > 2) {
			gchar** _tmp82_;
			gint _tmp82__length1;
			const gchar* _tmp83_;
			_tmp82_ = strv;
			_tmp82__length1 = strv_length1;
			_tmp83_ = _tmp82_[2];
			backoff = double_parse (_tmp83_);
		}
		_tmp84_ = strv;
		_tmp84__length1 = strv_length1;
		_tmp85_ = _tmp84_[1];
		_tmp87_ = _tmp86_ = g_strsplit (_tmp85_, " ", 0);
		words = _tmp87_;
		words_length1 = _vala_array_length (_tmp86_);
		_words_size_ = words_length1;
		_tmp88_ = g_new0 (guint, 0);
		ids = _tmp88_;
		ids_length1 = 0;
		_ids_size_ = ids_length1;
		_tmp89_ = words;
		_tmp89__length1 = words_length1;
		{
			gchar** word_collection = NULL;
			gint word_collection_length1 = 0;
			gint _word_collection_size_ = 0;
			gint word_it = 0;
			word_collection = _tmp89_;
			word_collection_length1 = _tmp89__length1;
			for (word_it = 0; word_it < word_collection_length1; word_it = word_it + 1) {
				gchar* _tmp90_;
				gchar* word = NULL;
				_tmp90_ = g_strdup (word_collection[word_it]);
				word = _tmp90_;
				{
					GeeMap* _tmp91_;
					const gchar* _tmp92_;
					gpointer _tmp93_;
					_tmp91_ = self->id_map;
					_tmp92_ = word;
					_tmp93_ = gee_map_get (_tmp91_, _tmp92_);
					_vala_array_add1 (&ids, &ids_length1, &_ids_size_, (guint) ((guintptr) _tmp93_));
					_g_free0 (word);
				}
			}
		}
		_tmp94_ = ids;
		_tmp94__length1 = ids_length1;
		_tmp95_ = kkc_text_bigram_language_model_get_key (self, _tmp94_, (gint) _tmp94__length1);
		key = _tmp95_;
		_tmp96_ = self->cost_map;
		_tmp97_ = key;
		gee_map_set (_tmp96_, _tmp97_, &cost);
		_tmp98_ = self->backoff_map;
		_tmp99_ = key;
		gee_map_set (_tmp98_, _tmp99_, &backoff);
		_g_free0 (key);
		ids = (g_free (ids), NULL);
		words = (_vala_array_free (words, words_length1, (GDestroyNotify) g_free), NULL);
		strv = (_vala_array_free (strv, strv_length1, (GDestroyNotify) g_free), NULL);
		_g_free0 (line);
	}
	_g_object_unref0 (lm_data);
	_g_object_unref0 (_tmp1_);
	_g_object_unref0 (lm_file);
}

static gboolean
kkc_text_bigram_language_model_real_parse (KkcLanguageModel* base,
                                           GError** error)
{
	KkcTextBigramLanguageModel * self;
	gchar* prefix = NULL;
	KkcLanguageModelMetadata* _tmp0_;
	KkcLanguageModelMetadata* _tmp1_;
	const gchar* _tmp2_;
	const gchar* _tmp3_;
	gchar* _tmp4_;
	gchar* _tmp5_;
	gchar* _tmp6_;
	gchar* _tmp7_;
	gchar* _tmp8_;
	gchar* _tmp9_;
	GError* _inner_error0_ = NULL;
	gboolean result;
	self = (KkcTextBigramLanguageModel*) base;
	_tmp0_ = kkc_language_model_get_metadata ((KkcLanguageModel*) self);
	_tmp1_ = _tmp0_;
	_tmp2_ = kkc_metadata_file_get_filename ((KkcMetadataFile*) _tmp1_);
	_tmp3_ = _tmp2_;
	_tmp4_ = g_path_get_dirname (_tmp3_);
	_tmp5_ = _tmp4_;
	_tmp6_ = g_build_filename (_tmp5_, "data", NULL);
	_tmp7_ = _tmp6_;
	_g_free0 (_tmp5_);
	prefix = _tmp7_;
	_tmp8_ = g_strconcat (prefix, ".arpa", NULL);
	_tmp9_ = _tmp8_;
	kkc_text_bigram_language_model_parse_lm (self, _tmp9_, &_inner_error0_);
	_g_free0 (_tmp9_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		gboolean _tmp10_ = FALSE;
		g_propagate_error (error, _inner_error0_);
		_g_free0 (prefix);
		return _tmp10_;
	}
	result = TRUE;
	_g_free0 (prefix);
	return result;
}

KkcTextBigramLanguageModel*
kkc_text_bigram_language_model_construct (GType object_type,
                                          KkcLanguageModelMetadata* metadata,
                                          GError** error)
{
	KkcTextBigramLanguageModel * self = NULL;
	GError* _inner_error0_ = NULL;
	g_return_val_if_fail (metadata != NULL, NULL);
	self = (KkcTextBigramLanguageModel*) kkc_language_model_construct (object_type, metadata, &_inner_error0_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (self);
		return NULL;
	}
	return self;
}

KkcTextBigramLanguageModel*
kkc_text_bigram_language_model_new (KkcLanguageModelMetadata* metadata,
                                    GError** error)
{
	return kkc_text_bigram_language_model_construct (KKC_TYPE_TEXT_BIGRAM_LANGUAGE_MODEL, metadata, error);
}

static void
kkc_text_bigram_language_model_real_get_bos (KkcLanguageModel* base,
                                             KkcLanguageModelEntry * result)
{
	KkcTextBigramLanguageModel* self;
	KkcLanguageModelEntry _tmp0_;
	self = (KkcTextBigramLanguageModel*) base;
	_tmp0_ = self->priv->_bos;
	*result = _tmp0_;
	return;
}

static void
kkc_text_bigram_language_model_real_get_eos (KkcLanguageModel* base,
                                             KkcLanguageModelEntry * result)
{
	KkcTextBigramLanguageModel* self;
	KkcLanguageModelEntry _tmp0_;
	self = (KkcTextBigramLanguageModel*) base;
	_tmp0_ = self->priv->_eos;
	*result = _tmp0_;
	return;
}

static void
kkc_text_bigram_language_model_class_init (KkcTextBigramLanguageModelClass * klass,
                                           gpointer klass_data)
{
	kkc_text_bigram_language_model_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &KkcTextBigramLanguageModel_private_offset);
	((KkcLanguageModelClass *) klass)->unigram_entries = (GeeCollection* (*) (KkcLanguageModel*, const gchar*)) kkc_text_bigram_language_model_real_unigram_entries;
	((KkcLanguageModelClass *) klass)->entries = (GeeCollection* (*) (KkcLanguageModel*, const gchar*)) kkc_text_bigram_language_model_real_entries;
	((KkcLanguageModelClass *) klass)->get = (KkcLanguageModelEntry* (*) (KkcLanguageModel*, const gchar*, const gchar*)) kkc_text_bigram_language_model_real_get;
	((KkcLanguageModelClass *) klass)->parse = (gboolean (*) (KkcLanguageModel*, GError**)) kkc_text_bigram_language_model_real_parse;
	KKC_LANGUAGE_MODEL_CLASS (klass)->get_bos = (void (*) (KkcLanguageModel*, KkcLanguageModelEntry*)) kkc_text_bigram_language_model_real_get_bos;
	KKC_LANGUAGE_MODEL_CLASS (klass)->get_eos = (void (*) (KkcLanguageModel*, KkcLanguageModelEntry*)) kkc_text_bigram_language_model_real_get_eos;
	G_OBJECT_CLASS (klass)->get_property = _vala_kkc_text_bigram_language_model_get_property;
	G_OBJECT_CLASS (klass)->finalize = kkc_text_bigram_language_model_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), KKC_TEXT_BIGRAM_LANGUAGE_MODEL_BOS_PROPERTY, kkc_text_bigram_language_model_properties[KKC_TEXT_BIGRAM_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_TEXT_BIGRAM_LANGUAGE_MODEL_EOS_PROPERTY, kkc_text_bigram_language_model_properties[KKC_TEXT_BIGRAM_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_text_bigram_language_model_kkc_unigram_language_model_interface_init (KkcUnigramLanguageModelIface * iface,
                                                                          gpointer iface_data)
{
	kkc_text_bigram_language_model_kkc_unigram_language_model_parent_iface = g_type_interface_peek_parent (iface);
	iface->unigram_cost = (gdouble (*) (KkcUnigramLanguageModel*, KkcLanguageModelEntry*)) kkc_text_bigram_language_model_real_unigram_cost;
	iface->unigram_backoff = (gdouble (*) (KkcUnigramLanguageModel*, KkcLanguageModelEntry*)) kkc_text_bigram_language_model_real_unigram_backoff;
}

static void
kkc_text_bigram_language_model_kkc_bigram_language_model_interface_init (KkcBigramLanguageModelIface * iface,
                                                                         gpointer iface_data)
{
	kkc_text_bigram_language_model_kkc_bigram_language_model_parent_iface = g_type_interface_peek_parent (iface);
	iface->has_bigram = (gboolean (*) (KkcBigramLanguageModel*, KkcLanguageModelEntry*, KkcLanguageModelEntry*)) kkc_text_bigram_language_model_real_has_bigram;
	iface->bigram_cost = (gdouble (*) (KkcBigramLanguageModel*, KkcLanguageModelEntry*, KkcLanguageModelEntry*)) kkc_text_bigram_language_model_real_bigram_cost;
	iface->bigram_backoff = (gdouble (*) (KkcBigramLanguageModel*, KkcLanguageModelEntry*, KkcLanguageModelEntry*)) kkc_text_bigram_language_model_real_bigram_backoff;
}

static void
kkc_text_bigram_language_model_instance_init (KkcTextBigramLanguageModel * self,
                                              gpointer klass)
{
	GeeHashMap* _tmp0_;
	GeeHashMap* _tmp1_;
	GeeHashMap* _tmp2_;
	GeeHashMap* _tmp3_;
	self->priv = kkc_text_bigram_language_model_get_instance_private (self);
	_tmp0_ = gee_hash_map_new (G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, GEE_TYPE_ARRAY_LIST, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
	self->input_map = (GeeMap*) _tmp0_;
	_tmp1_ = gee_hash_map_new (G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, G_TYPE_DOUBLE, (GBoxedCopyFunc) _double_dup, (GDestroyNotify) g_free, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
	self->cost_map = (GeeMap*) _tmp1_;
	_tmp2_ = gee_hash_map_new (G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, G_TYPE_DOUBLE, (GBoxedCopyFunc) _double_dup, (GDestroyNotify) g_free, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
	self->backoff_map = (GeeMap*) _tmp2_;
	_tmp3_ = gee_hash_map_new (G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, G_TYPE_UINT, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
	self->id_map = (GeeMap*) _tmp3_;
}

static void
kkc_text_bigram_language_model_finalize (GObject * obj)
{
	KkcTextBigramLanguageModel * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, KKC_TYPE_TEXT_BIGRAM_LANGUAGE_MODEL, KkcTextBigramLanguageModel);
	kkc_language_model_entry_destroy (&self->priv->_bos);
	kkc_language_model_entry_destroy (&self->priv->_eos);
	_g_object_unref0 (self->input_map);
	_g_object_unref0 (self->cost_map);
	_g_object_unref0 (self->backoff_map);
	_g_object_unref0 (self->id_map);
	G_OBJECT_CLASS (kkc_text_bigram_language_model_parent_class)->finalize (obj);
}

static GType
kkc_text_bigram_language_model_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (KkcTextBigramLanguageModelClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) kkc_text_bigram_language_model_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (KkcTextBigramLanguageModel), 0, (GInstanceInitFunc) kkc_text_bigram_language_model_instance_init, NULL };
	static const GInterfaceInfo kkc_unigram_language_model_info = { (GInterfaceInitFunc) kkc_text_bigram_language_model_kkc_unigram_language_model_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
	static const GInterfaceInfo kkc_bigram_language_model_info = { (GInterfaceInitFunc) kkc_text_bigram_language_model_kkc_bigram_language_model_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
	GType kkc_text_bigram_language_model_type_id;
	kkc_text_bigram_language_model_type_id = g_type_register_static (KKC_TYPE_LANGUAGE_MODEL, "KkcTextBigramLanguageModel", &g_define_type_info, 0);
	g_type_add_interface_static (kkc_text_bigram_language_model_type_id, KKC_TYPE_UNIGRAM_LANGUAGE_MODEL, &kkc_unigram_language_model_info);
	g_type_add_interface_static (kkc_text_bigram_language_model_type_id, KKC_TYPE_BIGRAM_LANGUAGE_MODEL, &kkc_bigram_language_model_info);
	KkcTextBigramLanguageModel_private_offset = g_type_add_instance_private (kkc_text_bigram_language_model_type_id, sizeof (KkcTextBigramLanguageModelPrivate));
	return kkc_text_bigram_language_model_type_id;
}

GType
kkc_text_bigram_language_model_get_type (void)
{
	static volatile gsize kkc_text_bigram_language_model_type_id__once = 0;
	if (g_once_init_enter (&kkc_text_bigram_language_model_type_id__once)) {
		GType kkc_text_bigram_language_model_type_id;
		kkc_text_bigram_language_model_type_id = kkc_text_bigram_language_model_get_type_once ();
		g_once_init_leave (&kkc_text_bigram_language_model_type_id__once, kkc_text_bigram_language_model_type_id);
	}
	return kkc_text_bigram_language_model_type_id__once;
}

static void
_vala_kkc_text_bigram_language_model_get_property (GObject * object,
                                                   guint property_id,
                                                   GValue * value,
                                                   GParamSpec * pspec)
{
	KkcTextBigramLanguageModel * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, KKC_TYPE_TEXT_BIGRAM_LANGUAGE_MODEL, KkcTextBigramLanguageModel);
	switch (property_id) {
		case KKC_TEXT_BIGRAM_LANGUAGE_MODEL_BOS_PROPERTY:
		{
			KkcLanguageModelEntry boxed;
			kkc_language_model_get_bos ((KkcLanguageModel*) self, &boxed);
			g_value_set_boxed (value, &boxed);
		}
		break;
		case KKC_TEXT_BIGRAM_LANGUAGE_MODEL_EOS_PROPERTY:
		{
			KkcLanguageModelEntry boxed;
			kkc_language_model_get_eos ((KkcLanguageModel*) self, &boxed);
			g_value_set_boxed (value, &boxed);
		}
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

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);
}

static gssize
_vala_array_length (gpointer array)
{
	gssize length;
	length = 0;
	if (array) {
		while (((gpointer*) array)[length]) {
			length++;
		}
	}
	return length;
}

