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

enum  {
	KKC_TEXT_TRIGRAM_LANGUAGE_MODEL_0_PROPERTY,
	KKC_TEXT_TRIGRAM_LANGUAGE_MODEL_NUM_PROPERTIES
};
static GParamSpec* kkc_text_trigram_language_model_properties[KKC_TEXT_TRIGRAM_LANGUAGE_MODEL_NUM_PROPERTIES];
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

static gpointer kkc_text_trigram_language_model_parent_class = NULL;
static KkcTrigramLanguageModelIface * kkc_text_trigram_language_model_kkc_trigram_language_model_parent_iface = NULL;

static gboolean kkc_text_trigram_language_model_real_has_trigram (KkcTrigramLanguageModel* base,
                                                           KkcLanguageModelEntry* ppentry,
                                                           KkcLanguageModelEntry* pentry,
                                                           KkcLanguageModelEntry* entry);
static gdouble kkc_text_trigram_language_model_real_trigram_cost (KkcTrigramLanguageModel* base,
                                                           KkcLanguageModelEntry* ppentry,
                                                           KkcLanguageModelEntry* pentry,
                                                           KkcLanguageModelEntry* entry);
static GType kkc_text_trigram_language_model_get_type_once (void);

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

static gdouble
kkc_text_trigram_language_model_real_trigram_cost (KkcTrigramLanguageModel* base,
                                                   KkcLanguageModelEntry* ppentry,
                                                   KkcLanguageModelEntry* pentry,
                                                   KkcLanguageModelEntry* entry)
{
	KkcTextTrigramLanguageModel * self;
	gchar* key = NULL;
	KkcLanguageModelEntry _tmp0_;
	KkcLanguageModelEntry _tmp1_;
	KkcLanguageModelEntry _tmp2_;
	guint* _tmp3_;
	guint* _tmp4_;
	gint _tmp4__length1;
	gchar* _tmp5_;
	gchar* _tmp6_;
	GeeMap* _tmp7_;
	const gchar* _tmp8_;
	gdouble result;
	self = (KkcTextTrigramLanguageModel*) base;
	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;
	_tmp3_ = g_new0 (guint, 3);
	_tmp3_[0] = _tmp0_.id;
	_tmp3_[1] = _tmp1_.id;
	_tmp3_[2] = _tmp2_.id;
	_tmp4_ = _tmp3_;
	_tmp4__length1 = 3;
	_tmp5_ = kkc_text_bigram_language_model_get_key ((KkcTextBigramLanguageModel*) self, _tmp4_, (gint) 3);
	_tmp6_ = _tmp5_;
	_tmp4_ = (g_free (_tmp4_), NULL);
	key = _tmp6_;
	_tmp7_ = ((KkcTextBigramLanguageModel*) self)->cost_map;
	_tmp8_ = key;
	if (gee_map_has_key (_tmp7_, _tmp8_)) {
		GeeMap* _tmp9_;
		const gchar* _tmp10_;
		gpointer _tmp11_;
		gdouble* _tmp12_;
		gdouble _tmp13_;
		_tmp9_ = ((KkcTextBigramLanguageModel*) self)->cost_map;
		_tmp10_ = key;
		_tmp11_ = gee_map_get (_tmp9_, _tmp10_);
		_tmp12_ = (gdouble*) _tmp11_;
		_tmp13_ = *_tmp12_;
		_g_free0 (_tmp12_);
		result = _tmp13_;
		_g_free0 (key);
		return result;
	}
	result = (gdouble) 0;
	_g_free0 (key);
	return result;
}

KkcTextTrigramLanguageModel*
kkc_text_trigram_language_model_construct (GType object_type,
                                           KkcLanguageModelMetadata* metadata,
                                           GError** error)
{
	KkcTextTrigramLanguageModel * self = NULL;
	GError* _inner_error0_ = NULL;
	g_return_val_if_fail (metadata != NULL, NULL);
	self = (KkcTextTrigramLanguageModel*) kkc_text_bigram_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;
}

KkcTextTrigramLanguageModel*
kkc_text_trigram_language_model_new (KkcLanguageModelMetadata* metadata,
                                     GError** error)
{
	return kkc_text_trigram_language_model_construct (KKC_TYPE_TEXT_TRIGRAM_LANGUAGE_MODEL, metadata, error);
}

static void
kkc_text_trigram_language_model_class_init (KkcTextTrigramLanguageModelClass * klass,
                                            gpointer klass_data)
{
	kkc_text_trigram_language_model_parent_class = g_type_class_peek_parent (klass);
}

static void
kkc_text_trigram_language_model_kkc_trigram_language_model_interface_init (KkcTrigramLanguageModelIface * iface,
                                                                           gpointer iface_data)
{
	kkc_text_trigram_language_model_kkc_trigram_language_model_parent_iface = g_type_interface_peek_parent (iface);
	iface->has_trigram = (gboolean (*) (KkcTrigramLanguageModel*, KkcLanguageModelEntry*, KkcLanguageModelEntry*, KkcLanguageModelEntry*)) kkc_text_trigram_language_model_real_has_trigram;
	iface->trigram_cost = (gdouble (*) (KkcTrigramLanguageModel*, KkcLanguageModelEntry*, KkcLanguageModelEntry*, KkcLanguageModelEntry*)) kkc_text_trigram_language_model_real_trigram_cost;
}

static void
kkc_text_trigram_language_model_instance_init (KkcTextTrigramLanguageModel * self,
                                               gpointer klass)
{
}

static GType
kkc_text_trigram_language_model_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (KkcTextTrigramLanguageModelClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) kkc_text_trigram_language_model_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (KkcTextTrigramLanguageModel), 0, (GInstanceInitFunc) kkc_text_trigram_language_model_instance_init, NULL };
	static const GInterfaceInfo kkc_trigram_language_model_info = { (GInterfaceInitFunc) kkc_text_trigram_language_model_kkc_trigram_language_model_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
	GType kkc_text_trigram_language_model_type_id;
	kkc_text_trigram_language_model_type_id = g_type_register_static (KKC_TYPE_TEXT_BIGRAM_LANGUAGE_MODEL, "KkcTextTrigramLanguageModel", &g_define_type_info, 0);
	g_type_add_interface_static (kkc_text_trigram_language_model_type_id, KKC_TYPE_TRIGRAM_LANGUAGE_MODEL, &kkc_trigram_language_model_info);
	return kkc_text_trigram_language_model_type_id;
}

GType
kkc_text_trigram_language_model_get_type (void)
{
	static volatile gsize kkc_text_trigram_language_model_type_id__once = 0;
	if (g_once_init_enter (&kkc_text_trigram_language_model_type_id__once)) {
		GType kkc_text_trigram_language_model_type_id;
		kkc_text_trigram_language_model_type_id = kkc_text_trigram_language_model_get_type_once ();
		g_once_init_leave (&kkc_text_trigram_language_model_type_id__once, kkc_text_trigram_language_model_type_id);
	}
	return kkc_text_trigram_language_model_type_id__once;
}

