/* user-segment-dictionary.c generated by valac 0.56.19, the Vala compiler
 * generated from user-segment-dictionary.vala, do not modify */

/*
 * Copyright (C) 2011-2014 Daiki Ueno <ueno@gnu.org>
 * Copyright (C) 2011-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 <gio/gio.h>
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <gee.h>
#include <glib-object.h>
#include <glib/gstdio.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_USER_SEGMENT_DICTIONARY_0_PROPERTY,
	KKC_USER_SEGMENT_DICTIONARY_NUM_PROPERTIES
};
static GParamSpec* kkc_user_segment_dictionary_properties[KKC_USER_SEGMENT_DICTIONARY_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 _KkcUserSegmentDictionaryPrivate {
	GFile* file;
	gchar* etag;
	GeeMap* okuri_ari_entries;
	GeeMap* okuri_nasi_entries;
	gboolean is_dirty;
};

static gint KkcUserSegmentDictionary_private_offset;
static gpointer kkc_user_segment_dictionary_parent_class = NULL;
static KkcDictionaryIface * kkc_user_segment_dictionary_kkc_dictionary_parent_iface = NULL;
static KkcSegmentDictionaryIface * kkc_user_segment_dictionary_kkc_segment_dictionary_parent_iface = NULL;

static void kkc_user_segment_dictionary_load (KkcUserSegmentDictionary* self,
                                       GError** error);
static guint8* _vala_array_dup3 (guint8* self,
                          gssize length);
VALA_EXTERN gchar* kkc_dictionary_utils_unescape (const gchar* input);
VALA_EXTERN KkcCandidate** kkc_dictionary_utils_split_candidates (const gchar* midasi,
                                                      gboolean okuri,
                                                      const gchar* line,
                                                      gint* result_length1);
static void kkc_user_segment_dictionary_real_reload (KkcDictionary* base,
                                              GError** error);
static gint kkc_user_segment_dictionary_compare_entry_asc (GeeMapEntry* a,
                                                    GeeMapEntry* b);
static gint kkc_user_segment_dictionary_compare_entry_dsc (GeeMapEntry* a,
                                                    GeeMapEntry* b);
static void kkc_user_segment_dictionary_write_entries (KkcUserSegmentDictionary* self,
                                                GString* builder,
                                                GeeList* entries);
VALA_EXTERN gchar* kkc_dictionary_utils_escape (const gchar* input);
VALA_EXTERN gchar* kkc_dictionary_utils_join_candidates (KkcCandidate** candidates,
                                             gint candidates_length1);
static void kkc_user_segment_dictionary_real_save (KkcDictionary* base,
                                            GError** error);
static gint _kkc_user_segment_dictionary_compare_entry_dsc_gcompare_data_func (gconstpointer a,
                                                                        gconstpointer b,
                                                                        gpointer self);
static gint _kkc_user_segment_dictionary_compare_entry_asc_gcompare_data_func (gconstpointer a,
                                                                        gconstpointer b,
                                                                        gpointer self);
static GeeMap* kkc_user_segment_dictionary_get_entries (KkcUserSegmentDictionary* self,
                                                 gboolean okuri);
static gboolean kkc_user_segment_dictionary_real_lookup_candidates (KkcSegmentDictionary* base,
                                                             const gchar* midasi,
                                                             gboolean okuri,
                                                             KkcCandidate*** candidates,
                                                             gint* candidates_length1);
static gchar** kkc_user_segment_dictionary_real_complete (KkcSegmentDictionary* base,
                                                   const gchar* midasi,
                                                   gint* result_length1);
static gboolean kkc_user_segment_dictionary_real_select_candidate (KkcSegmentDictionary* base,
                                                            KkcCandidate* candidate);
static gboolean kkc_user_segment_dictionary_real_purge_candidate (KkcSegmentDictionary* base,
                                                           KkcCandidate* candidate);
static void kkc_user_segment_dictionary_finalize (GObject * obj);
static GType kkc_user_segment_dictionary_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);
static gssize _vala_array_length (gpointer array);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static inline gpointer
kkc_user_segment_dictionary_get_instance_private (KkcUserSegmentDictionary* self)
{
	return G_STRUCT_MEMBER_P (self, KkcUserSegmentDictionary_private_offset);
}

static guint8*
_vala_array_dup3 (guint8* self,
                  gssize length)
{
	if (length > 0) {
		return _vala_memdup2 (self, length * sizeof (guint8));
	}
	return NULL;
}

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

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 void
kkc_user_segment_dictionary_load (KkcUserSegmentDictionary* self,
                                  GError** error)
{
	guint8* contents = NULL;
	gint contents_length1 = 0;
	gint _contents_size_ = 0;
	GFile* _tmp0_;
	guint8* _tmp1_ = NULL;
	gsize _tmp2_ = 0;
	gchar* _tmp3_ = NULL;
	GMemoryInputStream* memory = NULL;
	guint8* _tmp4_;
	gint _tmp4__length1;
	guint8* _tmp5_;
	gint _tmp5__length1;
	GDestroyNotify _tmp6_;
	GMemoryInputStream* _tmp7_;
	GDataInputStream* data = NULL;
	GMemoryInputStream* _tmp8_;
	GDataInputStream* _tmp9_;
	gchar* line = NULL;
	gsize length = 0UL;
	gchar* _tmp10_ = NULL;
	GDataInputStream* _tmp11_;
	gsize _tmp12_ = 0UL;
	gchar* _tmp13_;
	gchar* _tmp14_;
	const gchar* _tmp15_;
	GeeMap* entries = NULL;
	GeeMap* _tmp26_;
	gboolean okuri = FALSE;
	GError* _inner_error0_ = NULL;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->file;
	g_file_load_contents (_tmp0_, NULL, &_tmp1_, &_tmp2_, &_tmp3_, &_inner_error0_);
	contents = (g_free (contents), NULL);
	contents = _tmp1_;
	contents_length1 = _tmp2_;
	_contents_size_ = contents_length1;
	_g_free0 (self->priv->etag);
	self->priv->etag = _tmp3_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		contents = (g_free (contents), NULL);
		return;
	}
	_tmp4_ = contents;
	_tmp4__length1 = contents_length1;
	_tmp5_ = (_tmp4_ != NULL) ? _vala_array_dup3 (_tmp4_, _tmp4__length1) : _tmp4_;
	_tmp5__length1 = _tmp4__length1;
	_tmp6_ = g_free;
	_tmp7_ = (GMemoryInputStream*) g_memory_input_stream_new_from_data (_tmp5_, _tmp5__length1, _tmp6_);
	memory = _tmp7_;
	_tmp8_ = memory;
	_tmp9_ = g_data_input_stream_new ((GInputStream*) _tmp8_);
	data = _tmp9_;
	line = NULL;
	_tmp11_ = data;
	_tmp13_ = g_data_input_stream_read_line (_tmp11_, &_tmp12_, NULL, &_inner_error0_);
	length = _tmp12_;
	_tmp10_ = _tmp13_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_free0 (line);
		_g_object_unref0 (data);
		_g_object_unref0 (memory);
		contents = (g_free (contents), NULL);
		return;
	}
	_tmp14_ = _tmp10_;
	_tmp10_ = NULL;
	_g_free0 (line);
	line = _tmp14_;
	_tmp15_ = line;
	if (_tmp15_ == NULL) {
		_g_free0 (_tmp10_);
		_g_free0 (line);
		_g_object_unref0 (data);
		_g_object_unref0 (memory);
		contents = (g_free (contents), NULL);
		return;
	}
	entries = NULL;
	while (TRUE) {
		const gchar* _tmp16_;
		const gchar* _tmp17_;
		gchar* _tmp20_ = NULL;
		GDataInputStream* _tmp21_;
		gsize _tmp22_ = 0UL;
		gchar* _tmp23_;
		gchar* _tmp24_;
		const gchar* _tmp25_;
		_tmp16_ = line;
		if (!(_tmp16_ != NULL)) {
			break;
		}
		_tmp17_ = line;
		if (g_str_has_prefix (_tmp17_, ";; okuri-ari entries.")) {
			GeeMap* _tmp18_;
			GeeMap* _tmp19_;
			_tmp18_ = self->priv->okuri_ari_entries;
			_tmp19_ = _g_object_ref0 (_tmp18_);
			_g_object_unref0 (entries);
			entries = _tmp19_;
			break;
		}
		_tmp21_ = data;
		_tmp23_ = g_data_input_stream_read_line (_tmp21_, &_tmp22_, NULL, &_inner_error0_);
		length = _tmp22_;
		_tmp20_ = _tmp23_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (entries);
			_g_free0 (_tmp10_);
			_g_free0 (line);
			_g_object_unref0 (data);
			_g_object_unref0 (memory);
			contents = (g_free (contents), NULL);
			return;
		}
		_tmp24_ = _tmp20_;
		_tmp20_ = NULL;
		_g_free0 (line);
		line = _tmp24_;
		_tmp25_ = line;
		if (_tmp25_ == NULL) {
			_g_free0 (_tmp20_);
			break;
		}
		_g_free0 (_tmp20_);
	}
	_tmp26_ = entries;
	if (_tmp26_ == NULL) {
		GError* _tmp27_;
		_tmp27_ = g_error_new_literal (KKC_DICTIONARY_ERROR, KKC_DICTIONARY_ERROR_MALFORMED_INPUT, "no okuri-ari boundary");
		_inner_error0_ = _tmp27_;
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (entries);
		_g_free0 (_tmp10_);
		_g_free0 (line);
		_g_object_unref0 (data);
		_g_object_unref0 (memory);
		contents = (g_free (contents), NULL);
		return;
	}
	okuri = TRUE;
	while (TRUE) {
		const gchar* _tmp28_;
		gchar* _tmp29_ = NULL;
		GDataInputStream* _tmp30_;
		gsize _tmp31_ = 0UL;
		gchar* _tmp32_;
		gchar* _tmp33_;
		const gchar* _tmp34_;
		const gchar* _tmp35_;
		gchar** strv = NULL;
		const gchar* _tmp38_;
		gchar* _tmp39_;
		gchar* _tmp40_;
		gchar** _tmp41_;
		gchar** _tmp42_;
		gchar** _tmp43_;
		gint _tmp43__length1;
		gint strv_length1;
		gint _strv_size_;
		gchar** _tmp44_;
		gint _tmp44__length1;
		gchar* midasi = NULL;
		gchar** _tmp47_;
		gint _tmp47__length1;
		const gchar* _tmp48_;
		gchar* _tmp49_;
		gchar* candidates_str = NULL;
		gchar** _tmp50_;
		gint _tmp50__length1;
		const gchar* _tmp51_;
		gchar* _tmp52_;
		gboolean _tmp53_ = FALSE;
		const gchar* _tmp54_;
		KkcCandidate** candidates = NULL;
		const gchar* _tmp58_;
		const gchar* _tmp59_;
		gint _tmp60_ = 0;
		KkcCandidate** _tmp61_;
		gint candidates_length1;
		gint _candidates_size_;
		GeeArrayList* list = NULL;
		GeeArrayList* _tmp62_;
		KkcCandidate** _tmp63_;
		gint _tmp63__length1;
		GeeMap* _tmp67_;
		const gchar* _tmp68_;
		GeeArrayList* _tmp69_;
		_tmp28_ = line;
		if (!(_tmp28_ != NULL)) {
			break;
		}
		_tmp30_ = data;
		_tmp32_ = g_data_input_stream_read_line (_tmp30_, &_tmp31_, NULL, &_inner_error0_);
		length = _tmp31_;
		_tmp29_ = _tmp32_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (entries);
			_g_free0 (_tmp10_);
			_g_free0 (line);
			_g_object_unref0 (data);
			_g_object_unref0 (memory);
			contents = (g_free (contents), NULL);
			return;
		}
		_tmp33_ = _tmp29_;
		_tmp29_ = NULL;
		_g_free0 (line);
		line = _tmp33_;
		_tmp34_ = line;
		if (_tmp34_ == NULL) {
			_g_free0 (_tmp29_);
			break;
		}
		_tmp35_ = line;
		if (g_str_has_prefix (_tmp35_, ";; okuri-nasi entries.")) {
			GeeMap* _tmp36_;
			GeeMap* _tmp37_;
			_tmp36_ = self->priv->okuri_nasi_entries;
			_tmp37_ = _g_object_ref0 (_tmp36_);
			_g_object_unref0 (entries);
			entries = _tmp37_;
			okuri = FALSE;
			_g_free0 (_tmp29_);
			continue;
		}
		_tmp38_ = line;
		_tmp39_ = string_strip (_tmp38_);
		_tmp40_ = _tmp39_;
		_tmp42_ = _tmp41_ = g_strsplit_set (_tmp40_, " \t", 2);
		_tmp43_ = _tmp42_;
		_tmp43__length1 = _vala_array_length (_tmp41_);
		_g_free0 (_tmp40_);
		strv = _tmp43_;
		strv_length1 = _tmp43__length1;
		_strv_size_ = strv_length1;
		_tmp44_ = strv;
		_tmp44__length1 = strv_length1;
		if (_tmp44__length1 < 2) {
			const gchar* _tmp45_;
			GError* _tmp46_;
			_tmp45_ = line;
			_tmp46_ = g_error_new (KKC_DICTIONARY_ERROR, KKC_DICTIONARY_ERROR_MALFORMED_INPUT, "can't extract midasi from line %s", _tmp45_);
			_inner_error0_ = _tmp46_;
			g_propagate_error (error, _inner_error0_);
			strv = (_vala_array_free (strv, strv_length1, (GDestroyNotify) g_free), NULL);
			_g_free0 (_tmp29_);
			_g_object_unref0 (entries);
			_g_free0 (_tmp10_);
			_g_free0 (line);
			_g_object_unref0 (data);
			_g_object_unref0 (memory);
			contents = (g_free (contents), NULL);
			return;
		}
		_tmp47_ = strv;
		_tmp47__length1 = strv_length1;
		_tmp48_ = _tmp47_[0];
		_tmp49_ = kkc_dictionary_utils_unescape (_tmp48_);
		midasi = _tmp49_;
		_tmp50_ = strv;
		_tmp50__length1 = strv_length1;
		_tmp51_ = _tmp50_[1];
		_tmp52_ = g_strdup (_tmp51_);
		candidates_str = _tmp52_;
		_tmp54_ = candidates_str;
		if (!g_str_has_prefix (_tmp54_, "/")) {
			_tmp53_ = TRUE;
		} else {
			const gchar* _tmp55_;
			_tmp55_ = candidates_str;
			_tmp53_ = !g_str_has_suffix (_tmp55_, "/");
		}
		if (_tmp53_) {
			const gchar* _tmp56_;
			GError* _tmp57_;
			_tmp56_ = candidates_str;
			_tmp57_ = g_error_new (KKC_DICTIONARY_ERROR, KKC_DICTIONARY_ERROR_MALFORMED_INPUT, "can't parse candidates list %s", _tmp56_);
			_inner_error0_ = _tmp57_;
			g_propagate_error (error, _inner_error0_);
			_g_free0 (candidates_str);
			_g_free0 (midasi);
			strv = (_vala_array_free (strv, strv_length1, (GDestroyNotify) g_free), NULL);
			_g_free0 (_tmp29_);
			_g_object_unref0 (entries);
			_g_free0 (_tmp10_);
			_g_free0 (line);
			_g_object_unref0 (data);
			_g_object_unref0 (memory);
			contents = (g_free (contents), NULL);
			return;
		}
		_tmp58_ = midasi;
		_tmp59_ = candidates_str;
		_tmp61_ = kkc_dictionary_utils_split_candidates (_tmp58_, okuri, _tmp59_, &_tmp60_);
		candidates = _tmp61_;
		candidates_length1 = _tmp60_;
		_candidates_size_ = candidates_length1;
		_tmp62_ = gee_array_list_new (KKC_TYPE_CANDIDATE, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL);
		list = _tmp62_;
		_tmp63_ = candidates;
		_tmp63__length1 = candidates_length1;
		{
			KkcCandidate** c_collection = NULL;
			gint c_collection_length1 = 0;
			gint _c_collection_size_ = 0;
			gint c_it = 0;
			c_collection = _tmp63_;
			c_collection_length1 = _tmp63__length1;
			for (c_it = 0; c_it < c_collection_length1; c_it = c_it + 1) {
				KkcCandidate* _tmp64_;
				KkcCandidate* c = NULL;
				_tmp64_ = _g_object_ref0 (c_collection[c_it]);
				c = _tmp64_;
				{
					GeeArrayList* _tmp65_;
					KkcCandidate* _tmp66_;
					_tmp65_ = list;
					_tmp66_ = c;
					gee_abstract_collection_add ((GeeAbstractCollection*) _tmp65_, _tmp66_);
					_g_object_unref0 (c);
				}
			}
		}
		_tmp67_ = entries;
		_tmp68_ = midasi;
		_tmp69_ = list;
		gee_map_set (_tmp67_, _tmp68_, (GeeList*) _tmp69_);
		_g_object_unref0 (list);
		candidates = (_vala_array_free (candidates, candidates_length1, (GDestroyNotify) g_object_unref), NULL);
		_g_free0 (candidates_str);
		_g_free0 (midasi);
		strv = (_vala_array_free (strv, strv_length1, (GDestroyNotify) g_free), NULL);
		_g_free0 (_tmp29_);
	}
	_g_object_unref0 (entries);
	_g_free0 (_tmp10_);
	_g_free0 (line);
	_g_object_unref0 (data);
	_g_object_unref0 (memory);
	contents = (g_free (contents), NULL);
}

/**
         * {@inheritDoc}
         */
static void
kkc_user_segment_dictionary_real_reload (KkcDictionary* base,
                                         GError** error)
{
	KkcUserSegmentDictionary * self;
	gchar* attributes = NULL;
	gchar* _tmp0_;
	GFileInfo* info = NULL;
	GFile* _tmp1_;
	const gchar* _tmp2_;
	GFileInfo* _tmp3_;
	GFileInfo* _tmp4_;
	const gchar* _tmp5_;
	const gchar* _tmp6_;
	GError* _inner_error0_ = NULL;
	self = (KkcUserSegmentDictionary*) base;
	_tmp0_ = g_strdup (G_FILE_ATTRIBUTE_ETAG_VALUE);
	attributes = _tmp0_;
	_tmp1_ = self->priv->file;
	_tmp2_ = attributes;
	_tmp3_ = g_file_query_info (_tmp1_, _tmp2_, G_FILE_QUERY_INFO_NONE, NULL, &_inner_error0_);
	info = _tmp3_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_free0 (attributes);
		return;
	}
	_tmp4_ = info;
	_tmp5_ = g_file_info_get_etag (_tmp4_);
	_tmp6_ = self->priv->etag;
	if (g_strcmp0 (_tmp5_, _tmp6_) != 0) {
		GeeMap* _tmp7_;
		GeeMap* _tmp8_;
		_tmp7_ = self->priv->okuri_ari_entries;
		gee_map_clear (_tmp7_);
		_tmp8_ = self->priv->okuri_nasi_entries;
		gee_map_clear (_tmp8_);
		kkc_user_segment_dictionary_load (self, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (info);
			_g_free0 (attributes);
			return;
		}
	}
	self->priv->is_dirty = FALSE;
	_g_object_unref0 (info);
	_g_free0 (attributes);
}

static gint
kkc_user_segment_dictionary_compare_entry_asc (GeeMapEntry* a,
                                               GeeMapEntry* b)
{
	GCompareFunc _tmp0_;
	gconstpointer _tmp1_;
	gconstpointer _tmp2_;
	gconstpointer _tmp3_;
	gconstpointer _tmp4_;
	gint result;
	g_return_val_if_fail (a != NULL, -1);
	g_return_val_if_fail (b != NULL, -1);
	_tmp0_ = ((GCompareFunc) g_strcmp0);
	_tmp1_ = gee_map_entry_get_key (a);
	_tmp2_ = _tmp1_;
	_tmp3_ = gee_map_entry_get_key (b);
	_tmp4_ = _tmp3_;
	result = _tmp0_ ((const gchar*) _tmp2_, (const gchar*) _tmp4_);
	return result;
}

static gint
kkc_user_segment_dictionary_compare_entry_dsc (GeeMapEntry* a,
                                               GeeMapEntry* b)
{
	GCompareFunc _tmp0_;
	gconstpointer _tmp1_;
	gconstpointer _tmp2_;
	gconstpointer _tmp3_;
	gconstpointer _tmp4_;
	gint result;
	g_return_val_if_fail (a != NULL, -1);
	g_return_val_if_fail (b != NULL, -1);
	_tmp0_ = ((GCompareFunc) g_strcmp0);
	_tmp1_ = gee_map_entry_get_key (b);
	_tmp2_ = _tmp1_;
	_tmp3_ = gee_map_entry_get_key (a);
	_tmp4_ = _tmp3_;
	result = _tmp0_ ((const gchar*) _tmp2_, (const gchar*) _tmp4_);
	return result;
}

static void
kkc_user_segment_dictionary_write_entries (KkcUserSegmentDictionary* self,
                                           GString* builder,
                                           GeeList* entries)
{
	GeeIterator* iter = NULL;
	GeeIterator* _tmp0_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (builder != NULL);
	g_return_if_fail (entries != NULL);
	_tmp0_ = gee_iterable_iterator ((GeeIterable*) entries);
	iter = _tmp0_;
	while (TRUE) {
		GeeIterator* _tmp1_;
		GeeMapEntry* entry = NULL;
		GeeIterator* _tmp2_;
		gpointer _tmp3_;
		gchar* line = NULL;
		GeeMapEntry* _tmp4_;
		gconstpointer _tmp5_;
		gconstpointer _tmp6_;
		gchar* _tmp7_;
		gchar* _tmp8_;
		GeeMapEntry* _tmp9_;
		gconstpointer _tmp10_;
		gconstpointer _tmp11_;
		gint _tmp12_ = 0;
		gpointer* _tmp13_;
		KkcCandidate** _tmp14_;
		gint _tmp14__length1;
		gchar* _tmp15_;
		gchar* _tmp16_;
		gchar* _tmp17_;
		gchar* _tmp18_;
		const gchar* _tmp19_;
		_tmp1_ = iter;
		if (!gee_iterator_next (_tmp1_)) {
			break;
		}
		_tmp2_ = iter;
		_tmp3_ = gee_iterator_get (_tmp2_);
		entry = (GeeMapEntry*) _tmp3_;
		_tmp4_ = entry;
		_tmp5_ = gee_map_entry_get_key (_tmp4_);
		_tmp6_ = _tmp5_;
		_tmp7_ = kkc_dictionary_utils_escape ((const gchar*) _tmp6_);
		_tmp8_ = _tmp7_;
		_tmp9_ = entry;
		_tmp10_ = gee_map_entry_get_value (_tmp9_);
		_tmp11_ = _tmp10_;
		_tmp13_ = gee_collection_to_array ((GeeCollection*) ((GeeList*) _tmp11_), &_tmp12_);
		_tmp14_ = _tmp13_;
		_tmp14__length1 = _tmp12_;
		_tmp15_ = kkc_dictionary_utils_join_candidates (_tmp14_, (gint) _tmp12_);
		_tmp16_ = _tmp15_;
		_tmp17_ = g_strdup_printf ("%s %s\n", _tmp8_, _tmp16_);
		_tmp18_ = _tmp17_;
		_g_free0 (_tmp16_);
		_tmp14_ = (_vala_array_free (_tmp14_, _tmp14__length1, (GDestroyNotify) g_object_unref), NULL);
		_g_free0 (_tmp8_);
		line = _tmp18_;
		_tmp19_ = line;
		g_string_append (builder, _tmp19_);
		_g_free0 (line);
		_g_object_unref0 (entry);
	}
	_g_object_unref0 (iter);
}

/**
         * {@inheritDoc}
         */
static gint
_kkc_user_segment_dictionary_compare_entry_dsc_gcompare_data_func (gconstpointer a,
                                                                   gconstpointer b,
                                                                   gpointer self)
{
	gint result;
	result = kkc_user_segment_dictionary_compare_entry_dsc ((GeeMapEntry*) a, (GeeMapEntry*) b);
	return result;
}

static gint
_kkc_user_segment_dictionary_compare_entry_asc_gcompare_data_func (gconstpointer a,
                                                                   gconstpointer b,
                                                                   gpointer self)
{
	gint result;
	result = kkc_user_segment_dictionary_compare_entry_asc ((GeeMapEntry*) a, (GeeMapEntry*) b);
	return result;
}

static guint8*
string_get_data (const gchar* self,
                 gint* result_length1)
{
	guint8* result;
	guint8* res = NULL;
	gint res_length1;
	gint _res_size_;
	gint _tmp0_;
	gint _tmp1_;
	guint8* _tmp2_;
	gint _tmp2__length1;
	g_return_val_if_fail (self != NULL, NULL);
	res = (guint8*) self;
	res_length1 = -1;
	_res_size_ = res_length1;
	_tmp0_ = strlen (self);
	_tmp1_ = _tmp0_;
	res_length1 = (gint) _tmp1_;
	_tmp2_ = res;
	_tmp2__length1 = res_length1;
	if (result_length1) {
		*result_length1 = _tmp2__length1;
	}
	result = _tmp2_;
	return result;
}

static void
kkc_user_segment_dictionary_real_save (KkcDictionary* base,
                                       GError** error)
{
	KkcUserSegmentDictionary * self;
	GString* builder = NULL;
	GString* _tmp0_;
	GString* _tmp1_;
	GeeArrayList* entries = NULL;
	GeeArrayList* _tmp2_;
	GeeArrayList* _tmp3_;
	GeeMap* _tmp4_;
	GeeSet* _tmp5_;
	GeeSet* _tmp6_;
	GeeSet* _tmp7_;
	GeeArrayList* _tmp8_;
	GString* _tmp9_;
	GeeArrayList* _tmp10_;
	GeeArrayList* _tmp11_;
	GString* _tmp12_;
	GeeArrayList* _tmp13_;
	GeeMap* _tmp14_;
	GeeSet* _tmp15_;
	GeeSet* _tmp16_;
	GeeSet* _tmp17_;
	GeeArrayList* _tmp18_;
	GString* _tmp19_;
	GeeArrayList* _tmp20_;
	GeeArrayList* _tmp21_;
	GFile* _tmp22_;
	gchar* _tmp23_;
	gchar* _tmp24_;
	gchar* _tmp25_;
	gchar* _tmp26_;
	GFile* _tmp27_;
	GString* _tmp28_;
	const gchar* _tmp29_;
	guint8* _tmp30_;
	gint _tmp30__length1;
	gint _tmp31_ = 0;
	guint8* _tmp32_;
	gint _tmp32__length1;
	const gchar* _tmp33_;
	gchar* _tmp34_ = NULL;
	GError* _inner_error0_ = NULL;
	self = (KkcUserSegmentDictionary*) base;
	if (!self->priv->is_dirty) {
		return;
	}
	_tmp0_ = g_string_new ("");
	builder = _tmp0_;
	_tmp1_ = builder;
	g_string_append (_tmp1_, ";; okuri-ari entries.\n");
	_tmp2_ = gee_array_list_new (GEE_MAP_TYPE_ENTRY, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL);
	entries = _tmp2_;
	_tmp3_ = entries;
	_tmp4_ = self->priv->okuri_ari_entries;
	_tmp5_ = gee_map_get_entries (_tmp4_);
	_tmp6_ = _tmp5_;
	_tmp7_ = _tmp6_;
	gee_array_list_add_all (_tmp3_, (GeeCollection*) _tmp7_);
	_g_object_unref0 (_tmp7_);
	_tmp8_ = entries;
	gee_list_sort ((GeeList*) _tmp8_, _kkc_user_segment_dictionary_compare_entry_dsc_gcompare_data_func, NULL, NULL);
	_tmp9_ = builder;
	_tmp10_ = entries;
	kkc_user_segment_dictionary_write_entries (self, _tmp9_, (GeeList*) _tmp10_);
	_tmp11_ = entries;
	gee_abstract_collection_clear ((GeeAbstractCollection*) _tmp11_);
	_tmp12_ = builder;
	g_string_append (_tmp12_, ";; okuri-nasi entries.\n");
	_tmp13_ = entries;
	_tmp14_ = self->priv->okuri_nasi_entries;
	_tmp15_ = gee_map_get_entries (_tmp14_);
	_tmp16_ = _tmp15_;
	_tmp17_ = _tmp16_;
	gee_array_list_add_all (_tmp13_, (GeeCollection*) _tmp17_);
	_g_object_unref0 (_tmp17_);
	_tmp18_ = entries;
	gee_list_sort ((GeeList*) _tmp18_, _kkc_user_segment_dictionary_compare_entry_asc_gcompare_data_func, NULL, NULL);
	_tmp19_ = builder;
	_tmp20_ = entries;
	kkc_user_segment_dictionary_write_entries (self, _tmp19_, (GeeList*) _tmp20_);
	_tmp21_ = entries;
	gee_abstract_collection_clear ((GeeAbstractCollection*) _tmp21_);
	_tmp22_ = self->priv->file;
	_tmp23_ = g_file_get_path (_tmp22_);
	_tmp24_ = _tmp23_;
	_tmp25_ = g_path_get_dirname (_tmp24_);
	_tmp26_ = _tmp25_;
	g_mkdir_with_parents (_tmp26_, 448);
	_g_free0 (_tmp26_);
	_g_free0 (_tmp24_);
	_tmp27_ = self->priv->file;
	_tmp28_ = builder;
	_tmp29_ = _tmp28_->str;
	_tmp30_ = string_get_data (_tmp29_, &_tmp31_);
	_tmp30__length1 = _tmp31_;
	_tmp32_ = _tmp30_;
	_tmp32__length1 = _tmp30__length1;
	_tmp33_ = self->priv->etag;
	g_file_replace_contents (_tmp27_, (const char*) _tmp32_, (gsize) _tmp32__length1, _tmp33_, FALSE, G_FILE_CREATE_PRIVATE, &_tmp34_, NULL, &_inner_error0_);
	_g_free0 (self->priv->etag);
	self->priv->etag = _tmp34_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (entries);
		_g_string_free0 (builder);
		return;
	}
	self->priv->is_dirty = FALSE;
	_g_object_unref0 (entries);
	_g_string_free0 (builder);
}

static GeeMap*
kkc_user_segment_dictionary_get_entries (KkcUserSegmentDictionary* self,
                                         gboolean okuri)
{
	GeeMap* result;
	g_return_val_if_fail (self != NULL, NULL);
	if (okuri) {
		GeeMap* _tmp0_;
		GeeMap* _tmp1_;
		_tmp0_ = self->priv->okuri_ari_entries;
		_tmp1_ = _g_object_ref0 (_tmp0_);
		result = _tmp1_;
		return result;
	} else {
		GeeMap* _tmp2_;
		GeeMap* _tmp3_;
		_tmp2_ = self->priv->okuri_nasi_entries;
		_tmp3_ = _g_object_ref0 (_tmp2_);
		result = _tmp3_;
		return result;
	}
}

/**
         * {@inheritDoc}
         */
static gboolean
kkc_user_segment_dictionary_real_lookup_candidates (KkcSegmentDictionary* base,
                                                    const gchar* midasi,
                                                    gboolean okuri,
                                                    KkcCandidate*** candidates,
                                                    gint* candidates_length1)
{
	KkcUserSegmentDictionary * self;
	KkcCandidate** _vala_candidates = NULL;
	gint _vala_candidates_length1 = 0;
	GeeMap* entries = NULL;
	GeeMap* _tmp0_;
	GeeMap* _tmp1_;
	gboolean result;
	self = (KkcUserSegmentDictionary*) base;
	g_return_val_if_fail (midasi != NULL, FALSE);
	_tmp0_ = kkc_user_segment_dictionary_get_entries (self, okuri);
	entries = _tmp0_;
	_tmp1_ = entries;
	if (gee_map_has_key (_tmp1_, midasi)) {
		GeeMap* _tmp2_;
		gpointer _tmp3_;
		GeeList* _tmp4_;
		gint _tmp5_ = 0;
		gpointer* _tmp6_;
		_tmp2_ = entries;
		_tmp3_ = gee_map_get (_tmp2_, midasi);
		_tmp4_ = (GeeList*) _tmp3_;
		_tmp6_ = gee_collection_to_array ((GeeCollection*) _tmp4_, &_tmp5_);
		_vala_candidates = (_vala_array_free (_vala_candidates, _vala_candidates_length1, (GDestroyNotify) g_object_unref), NULL);
		_vala_candidates = _tmp6_;
		_vala_candidates_length1 = _tmp5_;
		_g_object_unref0 (_tmp4_);
		result = TRUE;
		_g_object_unref0 (entries);
		if (candidates) {
			*candidates = _vala_candidates;
		} else {
			_vala_candidates = (_vala_array_free (_vala_candidates, _vala_candidates_length1, (GDestroyNotify) g_object_unref), NULL);
		}
		if (candidates_length1) {
			*candidates_length1 = _vala_candidates_length1;
		}
		return result;
	} else {
		KkcCandidate** _tmp7_;
		_tmp7_ = g_new0 (KkcCandidate*, 0 + 1);
		_vala_candidates = (_vala_array_free (_vala_candidates, _vala_candidates_length1, (GDestroyNotify) g_object_unref), NULL);
		_vala_candidates = _tmp7_;
		_vala_candidates_length1 = 0;
		result = FALSE;
		_g_object_unref0 (entries);
		if (candidates) {
			*candidates = _vala_candidates;
		} else {
			_vala_candidates = (_vala_array_free (_vala_candidates, _vala_candidates_length1, (GDestroyNotify) g_object_unref), NULL);
		}
		if (candidates_length1) {
			*candidates_length1 = _vala_candidates_length1;
		}
		return result;
	}
}

/**
         * {@inheritDoc}
         */
static gchar**
kkc_user_segment_dictionary_real_complete (KkcSegmentDictionary* base,
                                           const gchar* midasi,
                                           gint* result_length1)
{
	KkcUserSegmentDictionary * self;
	GeeList* completion = NULL;
	GeeArrayList* _tmp0_;
	GeeList* keys = NULL;
	GeeArrayList* _tmp1_;
	GeeList* _tmp2_;
	GeeMap* _tmp3_;
	GeeSet* _tmp4_;
	GeeSet* _tmp5_;
	GeeSet* _tmp6_;
	GeeList* _tmp7_;
	GeeIterator* iter = NULL;
	GeeList* _tmp8_;
	GeeIterator* _tmp9_;
	GeeList* _tmp24_;
	gint _tmp25_ = 0;
	gpointer* _tmp26_;
	gchar** _tmp27_;
	gint _tmp27__length1;
	gchar** result;
	self = (KkcUserSegmentDictionary*) base;
	g_return_val_if_fail (midasi != NULL, NULL);
	_tmp0_ = gee_array_list_new (G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, NULL, NULL, NULL);
	completion = (GeeList*) _tmp0_;
	_tmp1_ = gee_array_list_new (G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, NULL, NULL, NULL);
	keys = (GeeList*) _tmp1_;
	_tmp2_ = keys;
	_tmp3_ = self->priv->okuri_nasi_entries;
	_tmp4_ = gee_map_get_keys (_tmp3_);
	_tmp5_ = _tmp4_;
	_tmp6_ = _tmp5_;
	gee_collection_add_all ((GeeCollection*) _tmp2_, (GeeCollection*) _tmp6_);
	_g_object_unref0 (_tmp6_);
	_tmp7_ = keys;
	gee_list_sort (_tmp7_, NULL, NULL, NULL);
	_tmp8_ = keys;
	_tmp9_ = gee_iterable_iterator ((GeeIterable*) _tmp8_);
	iter = _tmp9_;
	while (TRUE) {
		GeeIterator* _tmp10_;
		gchar* key = NULL;
		GeeIterator* _tmp11_;
		gpointer _tmp12_;
		const gchar* _tmp13_;
		_tmp10_ = iter;
		if (!gee_iterator_next (_tmp10_)) {
			break;
		}
		_tmp11_ = iter;
		_tmp12_ = gee_iterator_get (_tmp11_);
		key = (gchar*) _tmp12_;
		_tmp13_ = key;
		if (g_str_has_prefix (_tmp13_, midasi)) {
			const gchar* _tmp14_;
			_tmp14_ = key;
			if (g_strcmp0 (_tmp14_, midasi) != 0) {
				GeeList* _tmp15_;
				const gchar* _tmp16_;
				_tmp15_ = completion;
				_tmp16_ = key;
				gee_collection_add ((GeeCollection*) _tmp15_, _tmp16_);
			}
			_g_free0 (key);
			break;
		}
		_g_free0 (key);
	}
	while (TRUE) {
		GeeIterator* _tmp17_;
		gchar* key = NULL;
		GeeIterator* _tmp18_;
		gpointer _tmp19_;
		const gchar* _tmp20_;
		const gchar* _tmp21_;
		_tmp17_ = iter;
		if (!gee_iterator_next (_tmp17_)) {
			break;
		}
		_tmp18_ = iter;
		_tmp19_ = gee_iterator_get (_tmp18_);
		key = (gchar*) _tmp19_;
		_tmp20_ = key;
		if (!g_str_has_prefix (_tmp20_, midasi)) {
			_g_free0 (key);
			break;
		}
		_tmp21_ = key;
		if (g_strcmp0 (_tmp21_, midasi) != 0) {
			GeeList* _tmp22_;
			const gchar* _tmp23_;
			_tmp22_ = completion;
			_tmp23_ = key;
			gee_collection_add ((GeeCollection*) _tmp22_, _tmp23_);
		}
		_g_free0 (key);
	}
	_tmp24_ = completion;
	_tmp26_ = gee_collection_to_array ((GeeCollection*) _tmp24_, &_tmp25_);
	_tmp27_ = _tmp26_;
	_tmp27__length1 = _tmp25_;
	if (result_length1) {
		*result_length1 = _tmp27__length1;
	}
	result = _tmp27_;
	_g_object_unref0 (iter);
	_g_object_unref0 (keys);
	_g_object_unref0 (completion);
	return result;
}

/**
         * {@inheritDoc}
         */
static gboolean
kkc_user_segment_dictionary_real_select_candidate (KkcSegmentDictionary* base,
                                                   KkcCandidate* candidate)
{
	KkcUserSegmentDictionary * self;
	GeeMap* entries = NULL;
	gboolean _tmp0_;
	gboolean _tmp1_;
	GeeMap* _tmp2_;
	GeeMap* _tmp3_;
	const gchar* _tmp4_;
	const gchar* _tmp5_;
	GeeList* candidates = NULL;
	GeeMap* _tmp11_;
	const gchar* _tmp12_;
	const gchar* _tmp13_;
	gpointer _tmp14_;
	gint index = 0;
	GeeList* _tmp15_;
	GeeList* _tmp19_;
	gboolean result;
	self = (KkcUserSegmentDictionary*) base;
	g_return_val_if_fail (candidate != NULL, FALSE);
	_tmp0_ = kkc_candidate_get_okuri (candidate);
	_tmp1_ = _tmp0_;
	_tmp2_ = kkc_user_segment_dictionary_get_entries (self, _tmp1_);
	entries = _tmp2_;
	_tmp3_ = entries;
	_tmp4_ = kkc_candidate_get_midasi (candidate);
	_tmp5_ = _tmp4_;
	if (!gee_map_has_key (_tmp3_, _tmp5_)) {
		GeeMap* _tmp6_;
		const gchar* _tmp7_;
		const gchar* _tmp8_;
		GeeArrayList* _tmp9_;
		GeeArrayList* _tmp10_;
		_tmp6_ = entries;
		_tmp7_ = kkc_candidate_get_midasi (candidate);
		_tmp8_ = _tmp7_;
		_tmp9_ = gee_array_list_new (KKC_TYPE_CANDIDATE, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL);
		_tmp10_ = _tmp9_;
		gee_map_set (_tmp6_, _tmp8_, (GeeList*) _tmp10_);
		_g_object_unref0 (_tmp10_);
	}
	_tmp11_ = entries;
	_tmp12_ = kkc_candidate_get_midasi (candidate);
	_tmp13_ = _tmp12_;
	_tmp14_ = gee_map_get (_tmp11_, _tmp13_);
	candidates = (GeeList*) _tmp14_;
	_tmp15_ = candidates;
	index = gee_list_index_of (_tmp15_, candidate);
	if (index == 0) {
		result = FALSE;
		_g_object_unref0 (candidates);
		_g_object_unref0 (entries);
		return result;
	}
	if (index > 0) {
		GeeList* _tmp16_;
		gpointer _tmp17_;
		KkcCandidate* _tmp18_;
		_tmp16_ = candidates;
		_tmp17_ = gee_list_remove_at (_tmp16_, index);
		_tmp18_ = (KkcCandidate*) _tmp17_;
		_g_object_unref0 (_tmp18_);
	}
	_tmp19_ = candidates;
	gee_list_insert (_tmp19_, 0, candidate);
	self->priv->is_dirty = TRUE;
	result = TRUE;
	_g_object_unref0 (candidates);
	_g_object_unref0 (entries);
	return result;
}

/**
         * {@inheritDoc}
         */
static gboolean
kkc_user_segment_dictionary_real_purge_candidate (KkcSegmentDictionary* base,
                                                  KkcCandidate* candidate)
{
	KkcUserSegmentDictionary * self;
	gboolean modified = FALSE;
	GeeMap* entries = NULL;
	gboolean _tmp0_;
	gboolean _tmp1_;
	GeeMap* _tmp2_;
	GeeMap* _tmp3_;
	const gchar* _tmp4_;
	const gchar* _tmp5_;
	gboolean result;
	self = (KkcUserSegmentDictionary*) base;
	g_return_val_if_fail (candidate != NULL, FALSE);
	modified = FALSE;
	_tmp0_ = kkc_candidate_get_okuri (candidate);
	_tmp1_ = _tmp0_;
	_tmp2_ = kkc_user_segment_dictionary_get_entries (self, _tmp1_);
	entries = _tmp2_;
	_tmp3_ = entries;
	_tmp4_ = kkc_candidate_get_midasi (candidate);
	_tmp5_ = _tmp4_;
	if (gee_map_has_key (_tmp3_, _tmp5_)) {
		GeeList* candidates = NULL;
		GeeMap* _tmp6_;
		const gchar* _tmp7_;
		const gchar* _tmp8_;
		gpointer _tmp9_;
		GeeList* _tmp10_;
		gint _tmp11_;
		gint _tmp12_;
		_tmp6_ = entries;
		_tmp7_ = kkc_candidate_get_midasi (candidate);
		_tmp8_ = _tmp7_;
		_tmp9_ = gee_map_get (_tmp6_, _tmp8_);
		candidates = (GeeList*) _tmp9_;
		_tmp10_ = candidates;
		_tmp11_ = gee_collection_get_size ((GeeCollection*) _tmp10_);
		_tmp12_ = _tmp11_;
		if (_tmp12_ > 0) {
			GeeIterator* iter = NULL;
			GeeList* _tmp13_;
			GeeIterator* _tmp14_;
			GeeList* _tmp24_;
			gint _tmp25_;
			gint _tmp26_;
			_tmp13_ = candidates;
			_tmp14_ = gee_iterable_iterator ((GeeIterable*) _tmp13_);
			iter = _tmp14_;
			while (TRUE) {
				GeeIterator* _tmp15_;
				KkcCandidate* c = NULL;
				GeeIterator* _tmp16_;
				gpointer _tmp17_;
				KkcCandidate* _tmp18_;
				const gchar* _tmp19_;
				const gchar* _tmp20_;
				const gchar* _tmp21_;
				const gchar* _tmp22_;
				_tmp15_ = iter;
				if (!gee_iterator_next (_tmp15_)) {
					break;
				}
				_tmp16_ = iter;
				_tmp17_ = gee_iterator_get (_tmp16_);
				c = (KkcCandidate*) _tmp17_;
				_tmp18_ = c;
				_tmp19_ = kkc_candidate_get_text (_tmp18_);
				_tmp20_ = _tmp19_;
				_tmp21_ = kkc_candidate_get_text (candidate);
				_tmp22_ = _tmp21_;
				if (g_strcmp0 (_tmp20_, _tmp22_) == 0) {
					GeeIterator* _tmp23_;
					_tmp23_ = iter;
					gee_iterator_remove (_tmp23_);
					modified = TRUE;
				}
				_g_object_unref0 (c);
			}
			_tmp24_ = candidates;
			_tmp25_ = gee_collection_get_size ((GeeCollection*) _tmp24_);
			_tmp26_ = _tmp25_;
			if (_tmp26_ == 0) {
				GeeMap* _tmp27_;
				const gchar* _tmp28_;
				const gchar* _tmp29_;
				_tmp27_ = entries;
				_tmp28_ = kkc_candidate_get_midasi (candidate);
				_tmp29_ = _tmp28_;
				gee_map_unset (_tmp27_, _tmp29_, NULL);
			}
			_g_object_unref0 (iter);
		}
		_g_object_unref0 (candidates);
	}
	if (modified) {
		self->priv->is_dirty = TRUE;
	}
	result = modified;
	_g_object_unref0 (entries);
	return result;
}

/**
         * Create a new UserSegmentDictionary.
         *
         * @param path a path to the file
         *
         * @return a new UserSegmentDictionary
         * @throws GLib.Error if opening the file is failed
         */
KkcUserSegmentDictionary*
kkc_user_segment_dictionary_construct (GType object_type,
                                       const gchar* path,
                                       GError** error)
{
	KkcUserSegmentDictionary * self = NULL;
	GFile* _tmp0_;
	gchar* _tmp1_;
	GError* _inner_error0_ = NULL;
	g_return_val_if_fail (path != NULL, NULL);
	self = (KkcUserSegmentDictionary*) g_object_new (object_type, NULL);
	_tmp0_ = g_file_new_for_path (path);
	_g_object_unref0 (self->priv->file);
	self->priv->file = _tmp0_;
	_tmp1_ = g_strdup ("");
	_g_free0 (self->priv->etag);
	self->priv->etag = _tmp1_;
	if (g_file_test (path, G_FILE_TEST_EXISTS)) {
		kkc_dictionary_reload ((KkcDictionary*) self, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (self);
			return NULL;
		}
	}
	return self;
}

KkcUserSegmentDictionary*
kkc_user_segment_dictionary_new (const gchar* path,
                                 GError** error)
{
	return kkc_user_segment_dictionary_construct (KKC_TYPE_USER_SEGMENT_DICTIONARY, path, error);
}

static void
kkc_user_segment_dictionary_class_init (KkcUserSegmentDictionaryClass * klass,
                                        gpointer klass_data)
{
	kkc_user_segment_dictionary_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &KkcUserSegmentDictionary_private_offset);
	G_OBJECT_CLASS (klass)->finalize = kkc_user_segment_dictionary_finalize;
}

static void
kkc_user_segment_dictionary_kkc_dictionary_interface_init (KkcDictionaryIface * iface,
                                                           gpointer iface_data)
{
	kkc_user_segment_dictionary_kkc_dictionary_parent_iface = g_type_interface_peek_parent (iface);
	iface->reload = (void (*) (KkcDictionary*, GError**)) kkc_user_segment_dictionary_real_reload;
	iface->save = (void (*) (KkcDictionary*, GError**)) kkc_user_segment_dictionary_real_save;
}

static void
kkc_user_segment_dictionary_kkc_segment_dictionary_interface_init (KkcSegmentDictionaryIface * iface,
                                                                   gpointer iface_data)
{
	kkc_user_segment_dictionary_kkc_segment_dictionary_parent_iface = g_type_interface_peek_parent (iface);
	iface->lookup_candidates = (gboolean (*) (KkcSegmentDictionary*, const gchar*, gboolean, KkcCandidate***, gint*)) kkc_user_segment_dictionary_real_lookup_candidates;
	iface->complete = (gchar** (*) (KkcSegmentDictionary*, const gchar*, gint*)) kkc_user_segment_dictionary_real_complete;
	iface->select_candidate = (gboolean (*) (KkcSegmentDictionary*, KkcCandidate*)) kkc_user_segment_dictionary_real_select_candidate;
	iface->purge_candidate = (gboolean (*) (KkcSegmentDictionary*, KkcCandidate*)) kkc_user_segment_dictionary_real_purge_candidate;
}

static void
kkc_user_segment_dictionary_instance_init (KkcUserSegmentDictionary * self,
                                           gpointer klass)
{
	GeeHashMap* _tmp0_;
	GeeHashMap* _tmp1_;
	self->priv = kkc_user_segment_dictionary_get_instance_private (self);
	_tmp0_ = gee_hash_map_new (G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, GEE_TYPE_LIST, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
	self->priv->okuri_ari_entries = (GeeMap*) _tmp0_;
	_tmp1_ = gee_hash_map_new (G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, GEE_TYPE_LIST, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
	self->priv->okuri_nasi_entries = (GeeMap*) _tmp1_;
}

static void
kkc_user_segment_dictionary_finalize (GObject * obj)
{
	KkcUserSegmentDictionary * self;
	GeeMapIterator* okuri_ari_iter = NULL;
	GeeMap* _tmp0_;
	GeeMapIterator* _tmp1_;
	GeeMap* _tmp6_;
	GeeMapIterator* okuri_nasi_iter = NULL;
	GeeMap* _tmp7_;
	GeeMapIterator* _tmp8_;
	GeeMap* _tmp13_;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, KKC_TYPE_USER_SEGMENT_DICTIONARY, KkcUserSegmentDictionary);
	_tmp0_ = self->priv->okuri_ari_entries;
	_tmp1_ = gee_map_map_iterator (_tmp0_);
	okuri_ari_iter = _tmp1_;
	while (TRUE) {
		GeeMapIterator* _tmp2_;
		GeeMapIterator* _tmp3_;
		gpointer _tmp4_;
		GeeList* _tmp5_;
		_tmp2_ = okuri_ari_iter;
		if (!gee_map_iterator_next (_tmp2_)) {
			break;
		}
		_tmp3_ = okuri_ari_iter;
		_tmp4_ = gee_map_iterator_get_value (_tmp3_);
		_tmp5_ = (GeeList*) _tmp4_;
		gee_collection_clear ((GeeCollection*) _tmp5_);
		_g_object_unref0 (_tmp5_);
	}
	_tmp6_ = self->priv->okuri_ari_entries;
	gee_map_clear (_tmp6_);
	_tmp7_ = self->priv->okuri_nasi_entries;
	_tmp8_ = gee_map_map_iterator (_tmp7_);
	okuri_nasi_iter = _tmp8_;
	while (TRUE) {
		GeeMapIterator* _tmp9_;
		GeeMapIterator* _tmp10_;
		gpointer _tmp11_;
		GeeList* _tmp12_;
		_tmp9_ = okuri_nasi_iter;
		if (!gee_map_iterator_next (_tmp9_)) {
			break;
		}
		_tmp10_ = okuri_nasi_iter;
		_tmp11_ = gee_map_iterator_get_value (_tmp10_);
		_tmp12_ = (GeeList*) _tmp11_;
		gee_collection_clear ((GeeCollection*) _tmp12_);
		_g_object_unref0 (_tmp12_);
	}
	_tmp13_ = self->priv->okuri_nasi_entries;
	gee_map_clear (_tmp13_);
	_g_object_unref0 (okuri_nasi_iter);
	_g_object_unref0 (okuri_ari_iter);
	_g_object_unref0 (self->priv->file);
	_g_free0 (self->priv->etag);
	_g_object_unref0 (self->priv->okuri_ari_entries);
	_g_object_unref0 (self->priv->okuri_nasi_entries);
	G_OBJECT_CLASS (kkc_user_segment_dictionary_parent_class)->finalize (obj);
}

/**
     * File based implementation of SegmentDictionary with write access.
     */
static GType
kkc_user_segment_dictionary_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (KkcUserSegmentDictionaryClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) kkc_user_segment_dictionary_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (KkcUserSegmentDictionary), 0, (GInstanceInitFunc) kkc_user_segment_dictionary_instance_init, NULL };
	static const GInterfaceInfo kkc_dictionary_info = { (GInterfaceInitFunc) kkc_user_segment_dictionary_kkc_dictionary_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
	static const GInterfaceInfo kkc_segment_dictionary_info = { (GInterfaceInitFunc) kkc_user_segment_dictionary_kkc_segment_dictionary_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
	GType kkc_user_segment_dictionary_type_id;
	kkc_user_segment_dictionary_type_id = g_type_register_static (G_TYPE_OBJECT, "KkcUserSegmentDictionary", &g_define_type_info, 0);
	g_type_add_interface_static (kkc_user_segment_dictionary_type_id, KKC_TYPE_DICTIONARY, &kkc_dictionary_info);
	g_type_add_interface_static (kkc_user_segment_dictionary_type_id, KKC_TYPE_SEGMENT_DICTIONARY, &kkc_segment_dictionary_info);
	KkcUserSegmentDictionary_private_offset = g_type_add_instance_private (kkc_user_segment_dictionary_type_id, sizeof (KkcUserSegmentDictionaryPrivate));
	return kkc_user_segment_dictionary_type_id;
}

GType
kkc_user_segment_dictionary_get_type (void)
{
	static volatile gsize kkc_user_segment_dictionary_type_id__once = 0;
	if (g_once_init_enter (&kkc_user_segment_dictionary_type_id__once)) {
		GType kkc_user_segment_dictionary_type_id;
		kkc_user_segment_dictionary_type_id = kkc_user_segment_dictionary_get_type_once ();
		g_once_init_leave (&kkc_user_segment_dictionary_type_id__once, kkc_user_segment_dictionary_type_id);
	}
	return kkc_user_segment_dictionary_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);
}

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

static inline gpointer
_vala_memdup2 (gconstpointer mem,
               gsize byte_size)
{
	gpointer new_mem;
	if (mem && byte_size != 0) {
		new_mem = g_malloc (byte_size);
		memcpy (new_mem, mem, byte_size);
	} else {
		new_mem = NULL;
	}
	return new_mem;
}

