/* user-sentence-dictionary.c generated by valac 0.56.19, the Vala compiler
 * generated from user-sentence-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_SENTENCE_DICTIONARY_0_PROPERTY,
	KKC_USER_SENTENCE_DICTIONARY_NUM_PROPERTIES
};
static GParamSpec* kkc_user_sentence_dictionary_properties[KKC_USER_SENTENCE_DICTIONARY_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
typedef enum  {
	KKC_USER_SENTENCE_DICTIONARY_USER_SENTENCE_STATE_NONE,
	KKC_USER_SENTENCE_DICTIONARY_USER_SENTENCE_STATE_CONSTRAINT,
	KKC_USER_SENTENCE_DICTIONARY_USER_SENTENCE_STATE_PHRASE
} KkcUserSentenceDictionaryUserSentenceState;

#define KKC_USER_SENTENCE_DICTIONARY_TYPE_USER_SENTENCE_STATE (kkc_user_sentence_dictionary_user_sentence_state_get_type ())
#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 _KkcUserSentenceDictionaryPrivate {
	GFile* file;
	gchar* etag;
	gboolean is_dirty;
	GeeMap* constraint_entries;
	GeeMap* phrase_entries;
};

static gint KkcUserSentenceDictionary_private_offset;
static gpointer kkc_user_sentence_dictionary_parent_class = NULL;
static KkcDictionaryIface * kkc_user_sentence_dictionary_kkc_dictionary_parent_iface = NULL;
static KkcSentenceDictionaryIface * kkc_user_sentence_dictionary_kkc_sentence_dictionary_parent_iface = NULL;

static GType kkc_user_sentence_dictionary_user_sentence_state_get_type (void) G_GNUC_CONST  G_GNUC_UNUSED ;
static void kkc_user_sentence_dictionary_load (KkcUserSentenceDictionary* self,
                                        GError** error);
static guint8* _vala_array_dup4 (guint8* self,
                          gssize length);
VALA_EXTERN gchar* kkc_dictionary_utils_unescape (const gchar* input);
static gint kkc_user_sentence_dictionary_compare_constraint_entry (GeeMapEntry* a,
                                                            GeeMapEntry* b);
static gint kkc_user_sentence_dictionary_compare_phrase_entry (GeeMapEntry* a,
                                                        GeeMapEntry* b);
static void kkc_user_sentence_dictionary_write_constraint_entries (KkcUserSentenceDictionary* self,
                                                            GString* builder,
                                                            GeeArrayList* entries);
static void kkc_user_sentence_dictionary_write_phrase_entries (KkcUserSentenceDictionary* self,
                                                        GString* builder,
                                                        GeeArrayList* entries);
VALA_EXTERN gchar* kkc_dictionary_utils_escape (const gchar* input);
static void kkc_user_sentence_dictionary_real_save (KkcDictionary* base,
                                             GError** error);
static gint _kkc_user_sentence_dictionary_compare_constraint_entry_gcompare_data_func (gconstpointer a,
                                                                                gconstpointer b,
                                                                                gpointer self);
static gint _kkc_user_sentence_dictionary_compare_phrase_entry_gcompare_data_func (gconstpointer a,
                                                                            gconstpointer b,
                                                                            gpointer self);
static void kkc_user_sentence_dictionary_real_reload (KkcDictionary* base,
                                               GError** error);
static gboolean kkc_user_sentence_dictionary_real_lookup_constraint (KkcSentenceDictionary* base,
                                                              const gchar* input,
                                                              gint** constraint,
                                                              gint* constraint_length1);
static gboolean kkc_user_sentence_dictionary_real_lookup_phrase (KkcSentenceDictionary* base,
                                                          gchar** input,
                                                          gint input_length1,
                                                          gchar*** phrase,
                                                          gint* phrase_length1);
static gboolean kkc_user_sentence_dictionary_real_select_segments (KkcSentenceDictionary* base,
                                                            KkcSegment** segments,
                                                            gint segments_length1);
static void kkc_user_sentence_dictionary_finalize (GObject * obj);
static GType kkc_user_sentence_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_sentence_dictionary_get_instance_private (KkcUserSentenceDictionary* self)
{
	return G_STRUCT_MEMBER_P (self, KkcUserSentenceDictionary_private_offset);
}

static GType
kkc_user_sentence_dictionary_user_sentence_state_get_type_once (void)
{
	static const GEnumValue values[] = {{KKC_USER_SENTENCE_DICTIONARY_USER_SENTENCE_STATE_NONE, "KKC_USER_SENTENCE_DICTIONARY_USER_SENTENCE_STATE_NONE", "none"}, {KKC_USER_SENTENCE_DICTIONARY_USER_SENTENCE_STATE_CONSTRAINT, "KKC_USER_SENTENCE_DICTIONARY_USER_SENTENCE_STATE_CONSTRAINT", "constraint"}, {KKC_USER_SENTENCE_DICTIONARY_USER_SENTENCE_STATE_PHRASE, "KKC_USER_SENTENCE_DICTIONARY_USER_SENTENCE_STATE_PHRASE", "phrase"}, {0, NULL, NULL}};
	GType kkc_user_sentence_dictionary_user_sentence_state_type_id;
	kkc_user_sentence_dictionary_user_sentence_state_type_id = g_enum_register_static ("KkcUserSentenceDictionaryUserSentenceState", values);
	return kkc_user_sentence_dictionary_user_sentence_state_type_id;
}

static GType
kkc_user_sentence_dictionary_user_sentence_state_get_type (void)
{
	static volatile gsize kkc_user_sentence_dictionary_user_sentence_state_type_id__once = 0;
	if (g_once_init_enter (&kkc_user_sentence_dictionary_user_sentence_state_type_id__once)) {
		GType kkc_user_sentence_dictionary_user_sentence_state_type_id;
		kkc_user_sentence_dictionary_user_sentence_state_type_id = kkc_user_sentence_dictionary_user_sentence_state_get_type_once ();
		g_once_init_leave (&kkc_user_sentence_dictionary_user_sentence_state_type_id__once, kkc_user_sentence_dictionary_user_sentence_state_type_id);
	}
	return kkc_user_sentence_dictionary_user_sentence_state_type_id__once;
}

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

static gint
string_index_of (const gchar* self,
                 const gchar* needle,
                 gint start_index)
{
	gchar* _result_ = NULL;
	gchar* _tmp0_;
	gchar* _tmp1_;
	gint result;
	g_return_val_if_fail (self != NULL, -1);
	g_return_val_if_fail (needle != NULL, -1);
	_tmp0_ = strstr (((gchar*) self) + start_index, (gchar*) needle);
	_result_ = _tmp0_;
	_tmp1_ = _result_;
	if (_tmp1_ != NULL) {
		gchar* _tmp2_;
		_tmp2_ = _result_;
		result = (gint) (_tmp2_ - ((gchar*) self));
		return result;
	} else {
		result = -1;
		return result;
	}
}

static gchar*
string_slice (const gchar* self,
              glong start,
              glong end)
{
	glong string_length = 0L;
	gint _tmp0_;
	gint _tmp1_;
	gboolean _tmp2_ = FALSE;
	gboolean _tmp3_ = FALSE;
	gchar* _tmp4_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = strlen (self);
	_tmp1_ = _tmp0_;
	string_length = (glong) _tmp1_;
	if (start < ((glong) 0)) {
		start = string_length + start;
	}
	if (end < ((glong) 0)) {
		end = string_length + end;
	}
	if (start >= ((glong) 0)) {
		_tmp2_ = start <= string_length;
	} else {
		_tmp2_ = FALSE;
	}
	g_return_val_if_fail (_tmp2_, NULL);
	if (end >= ((glong) 0)) {
		_tmp3_ = end <= string_length;
	} else {
		_tmp3_ = FALSE;
	}
	g_return_val_if_fail (_tmp3_, NULL);
	g_return_val_if_fail (start <= end, NULL);
	_tmp4_ = g_strndup (((gchar*) self) + start, (gsize) (end - start));
	result = _tmp4_;
	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 void
kkc_user_sentence_dictionary_load (KkcUserSentenceDictionary* 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_;
	KkcUserSentenceDictionaryUserSentenceState state = 0;
	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_dup4 (_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;
	}
	state = KKC_USER_SENTENCE_DICTIONARY_USER_SENTENCE_STATE_NONE;
	while (TRUE) {
		const gchar* _tmp16_;
		const gchar* _tmp17_;
		gchar* _tmp18_ = NULL;
		GDataInputStream* _tmp19_;
		gsize _tmp20_ = 0UL;
		gchar* _tmp21_;
		gchar* _tmp22_;
		const gchar* _tmp23_;
		_tmp16_ = line;
		if (!(_tmp16_ != NULL)) {
			break;
		}
		_tmp17_ = line;
		if (g_str_has_prefix (_tmp17_, ";; constraint entries.")) {
			state = KKC_USER_SENTENCE_DICTIONARY_USER_SENTENCE_STATE_CONSTRAINT;
			break;
		}
		_tmp19_ = data;
		_tmp21_ = g_data_input_stream_read_line (_tmp19_, &_tmp20_, NULL, &_inner_error0_);
		length = _tmp20_;
		_tmp18_ = _tmp21_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_free0 (_tmp10_);
			_g_free0 (line);
			_g_object_unref0 (data);
			_g_object_unref0 (memory);
			contents = (g_free (contents), NULL);
			return;
		}
		_tmp22_ = _tmp18_;
		_tmp18_ = NULL;
		_g_free0 (line);
		line = _tmp22_;
		_tmp23_ = line;
		if (_tmp23_ == NULL) {
			_g_free0 (_tmp18_);
			break;
		}
		_g_free0 (_tmp18_);
	}
	if (state == KKC_USER_SENTENCE_DICTIONARY_USER_SENTENCE_STATE_NONE) {
		GError* _tmp24_;
		_tmp24_ = g_error_new_literal (KKC_DICTIONARY_ERROR, KKC_DICTIONARY_ERROR_MALFORMED_INPUT, "no constraints boundary");
		_inner_error0_ = _tmp24_;
		g_propagate_error (error, _inner_error0_);
		_g_free0 (_tmp10_);
		_g_free0 (line);
		_g_object_unref0 (data);
		_g_object_unref0 (memory);
		contents = (g_free (contents), NULL);
		return;
	}
	while (TRUE) {
		const gchar* _tmp25_;
		gchar* _tmp26_ = NULL;
		GDataInputStream* _tmp27_;
		gsize _tmp28_ = 0UL;
		gchar* _tmp29_;
		gchar* _tmp30_;
		const gchar* _tmp31_;
		const gchar* _tmp32_;
		gint index = 0;
		const gchar* _tmp33_;
		gchar* midasi = NULL;
		const gchar* _tmp36_;
		gchar* _tmp37_;
		gchar* _tmp38_;
		gchar* _tmp39_;
		gchar* _tmp40_;
		gchar* candidates_str = NULL;
		const gchar* _tmp41_;
		const gchar* _tmp42_;
		gint _tmp43_;
		gint _tmp44_;
		gchar* _tmp45_;
		gchar* _tmp46_;
		gchar* _tmp47_;
		gchar* _tmp48_;
		gboolean _tmp49_ = FALSE;
		const gchar* _tmp50_;
		_tmp25_ = line;
		if (!(_tmp25_ != NULL)) {
			break;
		}
		_tmp27_ = data;
		_tmp29_ = g_data_input_stream_read_line (_tmp27_, &_tmp28_, NULL, &_inner_error0_);
		length = _tmp28_;
		_tmp26_ = _tmp29_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_free0 (_tmp10_);
			_g_free0 (line);
			_g_object_unref0 (data);
			_g_object_unref0 (memory);
			contents = (g_free (contents), NULL);
			return;
		}
		_tmp30_ = _tmp26_;
		_tmp26_ = NULL;
		_g_free0 (line);
		line = _tmp30_;
		_tmp31_ = line;
		if (_tmp31_ == NULL) {
			_g_free0 (_tmp26_);
			break;
		}
		_tmp32_ = line;
		if (g_str_has_prefix (_tmp32_, ";; phrase entries.")) {
			state = KKC_USER_SENTENCE_DICTIONARY_USER_SENTENCE_STATE_PHRASE;
			_g_free0 (_tmp26_);
			continue;
		}
		_tmp33_ = line;
		index = string_index_of (_tmp33_, "/", 0);
		if (index < 2) {
			const gchar* _tmp34_;
			GError* _tmp35_;
			_tmp34_ = line;
			_tmp35_ = g_error_new (KKC_DICTIONARY_ERROR, KKC_DICTIONARY_ERROR_MALFORMED_INPUT, "can't extract midasi from line %s", _tmp34_);
			_inner_error0_ = _tmp35_;
			g_propagate_error (error, _inner_error0_);
			_g_free0 (_tmp26_);
			_g_free0 (_tmp10_);
			_g_free0 (line);
			_g_object_unref0 (data);
			_g_object_unref0 (memory);
			contents = (g_free (contents), NULL);
			return;
		}
		_tmp36_ = line;
		_tmp37_ = string_slice (_tmp36_, (glong) 0, (glong) index);
		_tmp38_ = _tmp37_;
		_tmp39_ = string_strip (_tmp38_);
		_tmp40_ = _tmp39_;
		_g_free0 (_tmp38_);
		midasi = _tmp40_;
		_tmp41_ = line;
		_tmp42_ = line;
		_tmp43_ = strlen (_tmp42_);
		_tmp44_ = _tmp43_;
		_tmp45_ = string_slice (_tmp41_, (glong) index, (glong) _tmp44_);
		_tmp46_ = _tmp45_;
		_tmp47_ = string_strip (_tmp46_);
		_tmp48_ = _tmp47_;
		_g_free0 (_tmp46_);
		candidates_str = _tmp48_;
		_tmp50_ = candidates_str;
		if (!g_str_has_prefix (_tmp50_, "/")) {
			_tmp49_ = TRUE;
		} else {
			const gchar* _tmp51_;
			_tmp51_ = candidates_str;
			_tmp49_ = !g_str_has_suffix (_tmp51_, "/");
		}
		if (_tmp49_) {
			const gchar* _tmp52_;
			GError* _tmp53_;
			_tmp52_ = candidates_str;
			_tmp53_ = g_error_new (KKC_DICTIONARY_ERROR, KKC_DICTIONARY_ERROR_MALFORMED_INPUT, "can't parse candidates list %s", _tmp52_);
			_inner_error0_ = _tmp53_;
			g_propagate_error (error, _inner_error0_);
			_g_free0 (candidates_str);
			_g_free0 (midasi);
			_g_free0 (_tmp26_);
			_g_free0 (_tmp10_);
			_g_free0 (line);
			_g_object_unref0 (data);
			_g_object_unref0 (memory);
			contents = (g_free (contents), NULL);
			return;
		}
		switch (state) {
			case KKC_USER_SENTENCE_DICTIONARY_USER_SENTENCE_STATE_CONSTRAINT:
			{
				GeeArrayList* numbers = NULL;
				GeeArrayList* _tmp54_;
				gchar** strv = NULL;
				const gchar* _tmp55_;
				gchar* _tmp56_;
				gchar* _tmp57_;
				gchar** _tmp58_;
				gchar** _tmp59_;
				gchar** _tmp60_;
				gint _tmp60__length1;
				gint strv_length1;
				gint _strv_size_;
				gchar** _tmp61_;
				gint _tmp61__length1;
				GeeMap* _tmp65_;
				const gchar* _tmp66_;
				GeeArrayList* _tmp67_;
				_tmp54_ = gee_array_list_new (G_TYPE_INT, NULL, NULL, NULL, NULL, NULL);
				numbers = _tmp54_;
				_tmp55_ = candidates_str;
				_tmp56_ = string_slice (_tmp55_, (glong) 1, (glong) -1);
				_tmp57_ = _tmp56_;
				_tmp59_ = _tmp58_ = g_strsplit (_tmp57_, ",", 0);
				_tmp60_ = _tmp59_;
				_tmp60__length1 = _vala_array_length (_tmp58_);
				_g_free0 (_tmp57_);
				strv = _tmp60_;
				strv_length1 = _tmp60__length1;
				_strv_size_ = strv_length1;
				_tmp61_ = strv;
				_tmp61__length1 = strv_length1;
				{
					gchar** str_collection = NULL;
					gint str_collection_length1 = 0;
					gint _str_collection_size_ = 0;
					gint str_it = 0;
					str_collection = _tmp61_;
					str_collection_length1 = _tmp61__length1;
					for (str_it = 0; str_it < str_collection_length1; str_it = str_it + 1) {
						gchar* _tmp62_;
						gchar* str = NULL;
						_tmp62_ = g_strdup (str_collection[str_it]);
						str = _tmp62_;
						{
							GeeArrayList* _tmp63_;
							const gchar* _tmp64_;
							_tmp63_ = numbers;
							_tmp64_ = str;
							gee_abstract_collection_add ((GeeAbstractCollection*) _tmp63_, (gpointer) ((gintptr) atoi (_tmp64_)));
							_g_free0 (str);
						}
					}
				}
				_tmp65_ = self->priv->constraint_entries;
				_tmp66_ = midasi;
				_tmp67_ = numbers;
				gee_map_set (_tmp65_, _tmp66_, (GeeList*) _tmp67_);
				strv = (_vala_array_free (strv, strv_length1, (GDestroyNotify) g_free), NULL);
				_g_object_unref0 (numbers);
				break;
			}
			case KKC_USER_SENTENCE_DICTIONARY_USER_SENTENCE_STATE_PHRASE:
			{
				GeeArrayList* segments = NULL;
				GeeArrayList* _tmp68_;
				gchar** strv = NULL;
				const gchar* _tmp69_;
				gchar* _tmp70_;
				gchar* _tmp71_;
				gchar** _tmp72_;
				gchar** _tmp73_;
				gchar** _tmp74_;
				gint _tmp74__length1;
				gint strv_length1;
				gint _strv_size_;
				gchar** _tmp75_;
				gint _tmp75__length1;
				GeeMap* _tmp81_;
				const gchar* _tmp82_;
				GeeArrayList* _tmp83_;
				_tmp68_ = gee_array_list_new (G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, NULL, NULL, NULL);
				segments = _tmp68_;
				_tmp69_ = candidates_str;
				_tmp70_ = string_slice (_tmp69_, (glong) 1, (glong) -1);
				_tmp71_ = _tmp70_;
				_tmp73_ = _tmp72_ = g_strsplit (_tmp71_, "/", 0);
				_tmp74_ = _tmp73_;
				_tmp74__length1 = _vala_array_length (_tmp72_);
				_g_free0 (_tmp71_);
				strv = _tmp74_;
				strv_length1 = _tmp74__length1;
				_strv_size_ = strv_length1;
				_tmp75_ = strv;
				_tmp75__length1 = strv_length1;
				{
					gchar** str_collection = NULL;
					gint str_collection_length1 = 0;
					gint _str_collection_size_ = 0;
					gint str_it = 0;
					str_collection = _tmp75_;
					str_collection_length1 = _tmp75__length1;
					for (str_it = 0; str_it < str_collection_length1; str_it = str_it + 1) {
						gchar* _tmp76_;
						gchar* str = NULL;
						_tmp76_ = g_strdup (str_collection[str_it]);
						str = _tmp76_;
						{
							GeeArrayList* _tmp77_;
							const gchar* _tmp78_;
							gchar* _tmp79_;
							gchar* _tmp80_;
							_tmp77_ = segments;
							_tmp78_ = str;
							_tmp79_ = kkc_dictionary_utils_unescape (_tmp78_);
							_tmp80_ = _tmp79_;
							gee_abstract_collection_add ((GeeAbstractCollection*) _tmp77_, _tmp80_);
							_g_free0 (_tmp80_);
							_g_free0 (str);
						}
					}
				}
				_tmp81_ = self->priv->phrase_entries;
				_tmp82_ = midasi;
				_tmp83_ = segments;
				gee_map_set (_tmp81_, _tmp82_, (GeeList*) _tmp83_);
				strv = (_vala_array_free (strv, strv_length1, (GDestroyNotify) g_free), NULL);
				_g_object_unref0 (segments);
				break;
			}
			default:
			break;
		}
		_g_free0 (candidates_str);
		_g_free0 (midasi);
		_g_free0 (_tmp26_);
	}
	_g_free0 (_tmp10_);
	_g_free0 (line);
	_g_object_unref0 (data);
	_g_object_unref0 (memory);
	contents = (g_free (contents), NULL);
}

static gint
kkc_user_sentence_dictionary_compare_constraint_entry (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_sentence_dictionary_compare_phrase_entry (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 gchar*
_vala_g_strjoinv (const gchar* separator,
                  gchar** str_array,
                  gint str_array_length1)
{
	gboolean _tmp0_ = FALSE;
	gchar* result;
	if (separator == NULL) {
		separator = "";
	}
	if (str_array != NULL) {
		gboolean _tmp1_ = FALSE;
		if (str_array_length1 > 0) {
			_tmp1_ = TRUE;
		} else {
			gboolean _tmp2_ = FALSE;
			if (str_array_length1 == -1) {
				const gchar* _tmp3_;
				_tmp3_ = str_array[0];
				_tmp2_ = _tmp3_ != NULL;
			} else {
				_tmp2_ = FALSE;
			}
			_tmp1_ = _tmp2_;
		}
		_tmp0_ = _tmp1_;
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		gint i = 0;
		gsize len = 0UL;
		gint _tmp16_;
		gint _tmp17_;
		const gchar* res = NULL;
		void* _tmp18_;
		const gchar* _tmp19_ = NULL;
		const gchar* _tmp20_;
		void* ptr = NULL;
		const gchar* _tmp22_;
		void* _tmp23_;
		const gchar* _tmp33_;
		len = (gsize) 1;
		{
			gboolean _tmp4_ = FALSE;
			i = 0;
			_tmp4_ = TRUE;
			while (TRUE) {
				gboolean _tmp6_ = FALSE;
				gboolean _tmp7_ = FALSE;
				gint _tmp10_ = 0;
				const gchar* _tmp11_;
				if (!_tmp4_) {
					gint _tmp5_;
					_tmp5_ = i;
					i = _tmp5_ + 1;
				}
				_tmp4_ = FALSE;
				if (str_array_length1 != -1) {
					_tmp7_ = i < str_array_length1;
				} else {
					_tmp7_ = FALSE;
				}
				if (_tmp7_) {
					_tmp6_ = TRUE;
				} else {
					gboolean _tmp8_ = FALSE;
					if (str_array_length1 == -1) {
						const gchar* _tmp9_;
						_tmp9_ = str_array[i];
						_tmp8_ = _tmp9_ != NULL;
					} else {
						_tmp8_ = FALSE;
					}
					_tmp6_ = _tmp8_;
				}
				if (!_tmp6_) {
					break;
				}
				_tmp11_ = str_array[i];
				if (_tmp11_ != NULL) {
					const gchar* _tmp12_;
					gint _tmp13_;
					gint _tmp14_;
					_tmp12_ = str_array[i];
					_tmp13_ = strlen ((const gchar*) _tmp12_);
					_tmp14_ = _tmp13_;
					_tmp10_ = _tmp14_;
				} else {
					_tmp10_ = 0;
				}
				len += (gsize) _tmp10_;
			}
		}
		if (i == 0) {
			gchar* _tmp15_;
			_tmp15_ = g_strdup ("");
			result = _tmp15_;
			return result;
		}
		str_array_length1 = i;
		_tmp16_ = strlen ((const gchar*) separator);
		_tmp17_ = _tmp16_;
		len += (gsize) (_tmp17_ * (i - 1));
		_tmp18_ = g_malloc (len);
		res = _tmp18_;
		_tmp20_ = str_array[0];
		if (_tmp20_ != NULL) {
			const gchar* _tmp21_;
			_tmp21_ = str_array[0];
			_tmp19_ = (const gchar*) _tmp21_;
		} else {
			_tmp19_ = "";
		}
		_tmp22_ = res;
		_tmp23_ = g_stpcpy ((void*) _tmp22_, _tmp19_);
		ptr = _tmp23_;
		{
			gboolean _tmp24_ = FALSE;
			i = 1;
			_tmp24_ = TRUE;
			while (TRUE) {
				void* _tmp26_;
				void* _tmp27_;
				const gchar* _tmp28_ = NULL;
				const gchar* _tmp29_;
				void* _tmp31_;
				void* _tmp32_;
				if (!_tmp24_) {
					gint _tmp25_;
					_tmp25_ = i;
					i = _tmp25_ + 1;
				}
				_tmp24_ = FALSE;
				if (!(i < str_array_length1)) {
					break;
				}
				_tmp26_ = ptr;
				_tmp27_ = g_stpcpy (_tmp26_, (const gchar*) separator);
				ptr = _tmp27_;
				_tmp29_ = str_array[i];
				if (_tmp29_ != NULL) {
					const gchar* _tmp30_;
					_tmp30_ = str_array[i];
					_tmp28_ = (const gchar*) _tmp30_;
				} else {
					_tmp28_ = "";
				}
				_tmp31_ = ptr;
				_tmp32_ = g_stpcpy (_tmp31_, _tmp28_);
				ptr = _tmp32_;
			}
		}
		_tmp33_ = res;
		res = NULL;
		result = (gchar*) _tmp33_;
		return result;
	} else {
		gchar* _tmp34_;
		_tmp34_ = g_strdup ("");
		result = _tmp34_;
		return result;
	}
}

static void
kkc_user_sentence_dictionary_write_constraint_entries (KkcUserSentenceDictionary* self,
                                                       GString* builder,
                                                       GeeArrayList* 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_abstract_collection_iterator ((GeeAbstractCollection*) entries);
	iter = _tmp0_;
	while (TRUE) {
		GeeIterator* _tmp1_;
		GeeMapEntry* entry = NULL;
		GeeIterator* _tmp2_;
		gpointer _tmp3_;
		gchar** strv = NULL;
		GeeMapEntry* _tmp4_;
		gconstpointer _tmp5_;
		gconstpointer _tmp6_;
		gint _tmp7_;
		gint _tmp8_;
		gchar** _tmp9_;
		gint strv_length1;
		gint _strv_size_;
		gchar* line = NULL;
		GeeMapEntry* _tmp19_;
		gconstpointer _tmp20_;
		gconstpointer _tmp21_;
		gchar** _tmp22_;
		gint _tmp22__length1;
		gchar* _tmp23_;
		gchar* _tmp24_;
		gchar* _tmp25_;
		gchar* _tmp26_;
		const gchar* _tmp27_;
		_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_value (_tmp4_);
		_tmp6_ = _tmp5_;
		_tmp7_ = gee_collection_get_size ((GeeCollection*) ((GeeList*) _tmp6_));
		_tmp8_ = _tmp7_;
		_tmp9_ = g_new0 (gchar*, _tmp8_ + 1);
		strv = _tmp9_;
		strv_length1 = _tmp8_;
		_strv_size_ = strv_length1;
		{
			gint i = 0;
			i = 0;
			{
				gboolean _tmp10_ = FALSE;
				_tmp10_ = TRUE;
				while (TRUE) {
					gchar** _tmp12_;
					gint _tmp12__length1;
					gchar** _tmp13_;
					gint _tmp13__length1;
					GeeMapEntry* _tmp14_;
					gconstpointer _tmp15_;
					gconstpointer _tmp16_;
					gpointer _tmp17_;
					gchar* _tmp18_;
					if (!_tmp10_) {
						gint _tmp11_;
						_tmp11_ = i;
						i = _tmp11_ + 1;
					}
					_tmp10_ = FALSE;
					_tmp12_ = strv;
					_tmp12__length1 = strv_length1;
					if (!(i < _tmp12__length1)) {
						break;
					}
					_tmp13_ = strv;
					_tmp13__length1 = strv_length1;
					_tmp14_ = entry;
					_tmp15_ = gee_map_entry_get_value (_tmp14_);
					_tmp16_ = _tmp15_;
					_tmp17_ = gee_list_get ((GeeList*) _tmp16_, i);
					_tmp18_ = g_strdup_printf ("%i", (gint) ((gintptr) _tmp17_));
					_g_free0 (_tmp13_[i]);
					_tmp13_[i] = _tmp18_;
				}
			}
		}
		_tmp19_ = entry;
		_tmp20_ = gee_map_entry_get_key (_tmp19_);
		_tmp21_ = _tmp20_;
		_tmp22_ = strv;
		_tmp22__length1 = strv_length1;
		_tmp23_ = _vala_g_strjoinv (",", _tmp22_, (gint) _tmp22__length1);
		_tmp24_ = _tmp23_;
		_tmp25_ = g_strdup_printf ("%s /%s/\n", (const gchar*) _tmp21_, _tmp24_);
		_tmp26_ = _tmp25_;
		_g_free0 (_tmp24_);
		line = _tmp26_;
		_tmp27_ = line;
		g_string_append (builder, _tmp27_);
		_g_free0 (line);
		strv = (_vala_array_free (strv, strv_length1, (GDestroyNotify) g_free), NULL);
		_g_object_unref0 (entry);
	}
	_g_object_unref0 (iter);
}

static void
kkc_user_sentence_dictionary_write_phrase_entries (KkcUserSentenceDictionary* self,
                                                   GString* builder,
                                                   GeeArrayList* 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_abstract_collection_iterator ((GeeAbstractCollection*) entries);
	iter = _tmp0_;
	while (TRUE) {
		GeeIterator* _tmp1_;
		GeeMapEntry* entry = NULL;
		GeeIterator* _tmp2_;
		gpointer _tmp3_;
		gchar** strv = NULL;
		GeeMapEntry* _tmp4_;
		gconstpointer _tmp5_;
		gconstpointer _tmp6_;
		gint _tmp7_;
		gint _tmp8_;
		gchar** _tmp9_;
		gint strv_length1;
		gint _strv_size_;
		gchar* line = NULL;
		GeeMapEntry* _tmp20_;
		gconstpointer _tmp21_;
		gconstpointer _tmp22_;
		gchar** _tmp23_;
		gint _tmp23__length1;
		gchar* _tmp24_;
		gchar* _tmp25_;
		gchar* _tmp26_;
		gchar* _tmp27_;
		const gchar* _tmp28_;
		_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_value (_tmp4_);
		_tmp6_ = _tmp5_;
		_tmp7_ = gee_collection_get_size ((GeeCollection*) ((GeeList*) _tmp6_));
		_tmp8_ = _tmp7_;
		_tmp9_ = g_new0 (gchar*, _tmp8_ + 1);
		strv = _tmp9_;
		strv_length1 = _tmp8_;
		_strv_size_ = strv_length1;
		{
			gint i = 0;
			i = 0;
			{
				gboolean _tmp10_ = FALSE;
				_tmp10_ = TRUE;
				while (TRUE) {
					gchar** _tmp12_;
					gint _tmp12__length1;
					gchar** _tmp13_;
					gint _tmp13__length1;
					GeeMapEntry* _tmp14_;
					gconstpointer _tmp15_;
					gconstpointer _tmp16_;
					gpointer _tmp17_;
					gchar* _tmp18_;
					gchar* _tmp19_;
					if (!_tmp10_) {
						gint _tmp11_;
						_tmp11_ = i;
						i = _tmp11_ + 1;
					}
					_tmp10_ = FALSE;
					_tmp12_ = strv;
					_tmp12__length1 = strv_length1;
					if (!(i < _tmp12__length1)) {
						break;
					}
					_tmp13_ = strv;
					_tmp13__length1 = strv_length1;
					_tmp14_ = entry;
					_tmp15_ = gee_map_entry_get_value (_tmp14_);
					_tmp16_ = _tmp15_;
					_tmp17_ = gee_list_get ((GeeList*) _tmp16_, i);
					_tmp18_ = (gchar*) _tmp17_;
					_tmp19_ = kkc_dictionary_utils_escape (_tmp18_);
					_g_free0 (_tmp13_[i]);
					_tmp13_[i] = _tmp19_;
					_g_free0 (_tmp18_);
				}
			}
		}
		_tmp20_ = entry;
		_tmp21_ = gee_map_entry_get_key (_tmp20_);
		_tmp22_ = _tmp21_;
		_tmp23_ = strv;
		_tmp23__length1 = strv_length1;
		_tmp24_ = _vala_g_strjoinv ("/", _tmp23_, (gint) _tmp23__length1);
		_tmp25_ = _tmp24_;
		_tmp26_ = g_strdup_printf ("%s /%s/\n", (const gchar*) _tmp22_, _tmp25_);
		_tmp27_ = _tmp26_;
		_g_free0 (_tmp25_);
		line = _tmp27_;
		_tmp28_ = line;
		g_string_append (builder, _tmp28_);
		_g_free0 (line);
		strv = (_vala_array_free (strv, strv_length1, (GDestroyNotify) g_free), NULL);
		_g_object_unref0 (entry);
	}
	_g_object_unref0 (iter);
}

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

static gint
_kkc_user_sentence_dictionary_compare_phrase_entry_gcompare_data_func (gconstpointer a,
                                                                       gconstpointer b,
                                                                       gpointer self)
{
	gint result;
	result = kkc_user_sentence_dictionary_compare_phrase_entry ((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_sentence_dictionary_real_save (KkcDictionary* base,
                                        GError** error)
{
	KkcUserSentenceDictionary * self;
	GString* builder = NULL;
	GString* _tmp0_;
	GString* _tmp1_;
	GeeArrayList* _constraint_entries = NULL;
	GeeArrayList* _tmp2_;
	GeeArrayList* _tmp3_;
	GeeMap* _tmp4_;
	GeeSet* _tmp5_;
	GeeSet* _tmp6_;
	GeeSet* _tmp7_;
	GeeArrayList* _tmp8_;
	GString* _tmp9_;
	GeeArrayList* _tmp10_;
	GString* _tmp11_;
	GeeArrayList* _phrase_entries = NULL;
	GeeArrayList* _tmp12_;
	GeeArrayList* _tmp13_;
	GeeMap* _tmp14_;
	GeeSet* _tmp15_;
	GeeSet* _tmp16_;
	GeeSet* _tmp17_;
	GeeArrayList* _tmp18_;
	GString* _tmp19_;
	GeeArrayList* _tmp20_;
	GFile* _tmp21_;
	gchar* _tmp22_;
	gchar* _tmp23_;
	gchar* _tmp24_;
	gchar* _tmp25_;
	gchar* contents = NULL;
	GString* _tmp26_;
	const gchar* _tmp27_;
	gchar* _tmp28_;
	GFile* _tmp29_;
	const gchar* _tmp30_;
	guint8* _tmp31_;
	gint _tmp31__length1;
	gint _tmp32_ = 0;
	guint8* _tmp33_;
	gint _tmp33__length1;
	const gchar* _tmp34_;
	gchar* _tmp35_ = NULL;
	GError* _inner_error0_ = NULL;
	self = (KkcUserSentenceDictionary*) base;
	if (!self->priv->is_dirty) {
		return;
	}
	_tmp0_ = g_string_new ("");
	builder = _tmp0_;
	_tmp1_ = builder;
	g_string_append (_tmp1_, ";; constraint entries.\n");
	_tmp2_ = gee_array_list_new (GEE_MAP_TYPE_ENTRY, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL);
	_constraint_entries = _tmp2_;
	_tmp3_ = _constraint_entries;
	_tmp4_ = self->priv->constraint_entries;
	_tmp5_ = gee_map_get_entries (_tmp4_);
	_tmp6_ = _tmp5_;
	_tmp7_ = _tmp6_;
	gee_array_list_add_all (_tmp3_, (GeeCollection*) _tmp7_);
	_g_object_unref0 (_tmp7_);
	_tmp8_ = _constraint_entries;
	gee_list_sort ((GeeList*) _tmp8_, _kkc_user_sentence_dictionary_compare_constraint_entry_gcompare_data_func, NULL, NULL);
	_tmp9_ = builder;
	_tmp10_ = _constraint_entries;
	kkc_user_sentence_dictionary_write_constraint_entries (self, _tmp9_, _tmp10_);
	_tmp11_ = builder;
	g_string_append (_tmp11_, ";; phrase entries.\n");
	_tmp12_ = gee_array_list_new (GEE_MAP_TYPE_ENTRY, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL);
	_phrase_entries = _tmp12_;
	_tmp13_ = _phrase_entries;
	_tmp14_ = self->priv->phrase_entries;
	_tmp15_ = gee_map_get_entries (_tmp14_);
	_tmp16_ = _tmp15_;
	_tmp17_ = _tmp16_;
	gee_array_list_add_all (_tmp13_, (GeeCollection*) _tmp17_);
	_g_object_unref0 (_tmp17_);
	_tmp18_ = _phrase_entries;
	gee_list_sort ((GeeList*) _tmp18_, _kkc_user_sentence_dictionary_compare_phrase_entry_gcompare_data_func, NULL, NULL);
	_tmp19_ = builder;
	_tmp20_ = _phrase_entries;
	kkc_user_sentence_dictionary_write_phrase_entries (self, _tmp19_, _tmp20_);
	_tmp21_ = self->priv->file;
	_tmp22_ = g_file_get_path (_tmp21_);
	_tmp23_ = _tmp22_;
	_tmp24_ = g_path_get_dirname (_tmp23_);
	_tmp25_ = _tmp24_;
	g_mkdir_with_parents (_tmp25_, 448);
	_g_free0 (_tmp25_);
	_g_free0 (_tmp23_);
	_tmp26_ = builder;
	_tmp27_ = _tmp26_->str;
	_tmp28_ = g_strdup (_tmp27_);
	contents = _tmp28_;
	_tmp29_ = self->priv->file;
	_tmp30_ = contents;
	_tmp31_ = string_get_data (_tmp30_, &_tmp32_);
	_tmp31__length1 = _tmp32_;
	_tmp33_ = _tmp31_;
	_tmp33__length1 = _tmp31__length1;
	_tmp34_ = self->priv->etag;
	g_file_replace_contents (_tmp29_, (const char*) _tmp33_, (gsize) _tmp33__length1, _tmp34_, FALSE, G_FILE_CREATE_PRIVATE, &_tmp35_, NULL, &_inner_error0_);
	_g_free0 (self->priv->etag);
	self->priv->etag = _tmp35_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_free0 (contents);
		_g_object_unref0 (_phrase_entries);
		_g_object_unref0 (_constraint_entries);
		_g_string_free0 (builder);
		return;
	}
	self->priv->is_dirty = FALSE;
	_g_free0 (contents);
	_g_object_unref0 (_phrase_entries);
	_g_object_unref0 (_constraint_entries);
	_g_string_free0 (builder);
}

/**
         * {@inheritDoc}
         */
static void
kkc_user_sentence_dictionary_real_reload (KkcDictionary* base,
                                          GError** error)
{
	KkcUserSentenceDictionary * 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 = (KkcUserSentenceDictionary*) 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->constraint_entries;
		gee_map_clear (_tmp7_);
		_tmp8_ = self->priv->phrase_entries;
		gee_map_clear (_tmp8_);
		kkc_user_sentence_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);
}

/**
         * {@inheritDoc}
         */
static gboolean
kkc_user_sentence_dictionary_real_lookup_constraint (KkcSentenceDictionary* base,
                                                     const gchar* input,
                                                     gint** constraint,
                                                     gint* constraint_length1)
{
	KkcUserSentenceDictionary * self;
	gint* _vala_constraint = NULL;
	gint _vala_constraint_length1 = 0;
	GeeList* entry = NULL;
	GeeMap* _tmp0_;
	gpointer _tmp1_;
	GeeList* _tmp2_;
	GeeList* _tmp4_;
	gint _tmp5_ = 0;
	gpointer* _tmp6_;
	gboolean result;
	self = (KkcUserSentenceDictionary*) base;
	g_return_val_if_fail (input != NULL, FALSE);
	_tmp0_ = self->priv->constraint_entries;
	_tmp1_ = gee_map_get (_tmp0_, input);
	entry = (GeeList*) _tmp1_;
	_tmp2_ = entry;
	if (_tmp2_ == NULL) {
		gint* _tmp3_;
		_tmp3_ = g_new0 (gint, 0);
		_vala_constraint = (g_free (_vala_constraint), NULL);
		_vala_constraint = _tmp3_;
		_vala_constraint_length1 = 0;
		result = FALSE;
		_g_object_unref0 (entry);
		if (constraint) {
			*constraint = _vala_constraint;
		} else {
			_vala_constraint = (g_free (_vala_constraint), NULL);
		}
		if (constraint_length1) {
			*constraint_length1 = _vala_constraint_length1;
		}
		return result;
	}
	_tmp4_ = entry;
	_tmp6_ = gee_collection_to_array ((GeeCollection*) _tmp4_, &_tmp5_);
	_vala_constraint = (g_free (_vala_constraint), NULL);
	_vala_constraint = _tmp6_;
	_vala_constraint_length1 = _tmp5_;
	result = TRUE;
	_g_object_unref0 (entry);
	if (constraint) {
		*constraint = _vala_constraint;
	} else {
		_vala_constraint = (g_free (_vala_constraint), NULL);
	}
	if (constraint_length1) {
		*constraint_length1 = _vala_constraint_length1;
	}
	return result;
}

/**
         * {@inheritDoc}
         */
static gboolean
kkc_user_sentence_dictionary_real_lookup_phrase (KkcSentenceDictionary* base,
                                                 gchar** input,
                                                 gint input_length1,
                                                 gchar*** phrase,
                                                 gint* phrase_length1)
{
	KkcUserSentenceDictionary * self;
	gchar** _vala_phrase = NULL;
	gint _vala_phrase_length1 = 0;
	gchar* _input = NULL;
	gchar* _tmp0_;
	GeeList* entry = NULL;
	GeeMap* _tmp1_;
	const gchar* _tmp2_;
	gpointer _tmp3_;
	GeeList* _tmp4_;
	GeeList* _tmp6_;
	gint _tmp7_ = 0;
	gpointer* _tmp8_;
	gboolean result;
	self = (KkcUserSentenceDictionary*) base;
	_tmp0_ = _vala_g_strjoinv (" ", input, (gint) input_length1);
	_input = _tmp0_;
	_tmp1_ = self->priv->phrase_entries;
	_tmp2_ = _input;
	_tmp3_ = gee_map_get (_tmp1_, _tmp2_);
	entry = (GeeList*) _tmp3_;
	_tmp4_ = entry;
	if (_tmp4_ == NULL) {
		gchar** _tmp5_;
		_tmp5_ = g_new0 (gchar*, 0 + 1);
		_vala_phrase = (_vala_array_free (_vala_phrase, _vala_phrase_length1, (GDestroyNotify) g_free), NULL);
		_vala_phrase = _tmp5_;
		_vala_phrase_length1 = 0;
		result = FALSE;
		_g_object_unref0 (entry);
		_g_free0 (_input);
		if (phrase) {
			*phrase = _vala_phrase;
		} else {
			_vala_phrase = (_vala_array_free (_vala_phrase, _vala_phrase_length1, (GDestroyNotify) g_free), NULL);
		}
		if (phrase_length1) {
			*phrase_length1 = _vala_phrase_length1;
		}
		return result;
	}
	_tmp6_ = entry;
	_tmp8_ = gee_collection_to_array ((GeeCollection*) _tmp6_, &_tmp7_);
	_vala_phrase = (_vala_array_free (_vala_phrase, _vala_phrase_length1, (GDestroyNotify) g_free), NULL);
	_vala_phrase = _tmp8_;
	_vala_phrase_length1 = _tmp7_;
	result = TRUE;
	_g_object_unref0 (entry);
	_g_free0 (_input);
	if (phrase) {
		*phrase = _vala_phrase;
	} else {
		_vala_phrase = (_vala_array_free (_vala_phrase, _vala_phrase_length1, (GDestroyNotify) g_free), NULL);
	}
	if (phrase_length1) {
		*phrase_length1 = _vala_phrase_length1;
	}
	return result;
}

/**
         * {@inheritDoc}
         */
static gpointer
_g_object_ref0 (gpointer self)
{
	return self ? g_object_ref (self) : NULL;
}

static gboolean
kkc_user_sentence_dictionary_real_select_segments (KkcSentenceDictionary* base,
                                                   KkcSegment** segments,
                                                   gint segments_length1)
{
	KkcUserSentenceDictionary * self;
	gint offset = 0;
	GeeArrayList* input = NULL;
	GeeArrayList* _tmp0_;
	GeeArrayList* constraint = NULL;
	GeeArrayList* _tmp1_;
	GeeArrayList* phrase = NULL;
	GeeArrayList* _tmp2_;
	GeeArrayList* _tmp16_;
	gchar** array = NULL;
	GeeArrayList* _tmp17_;
	gint _tmp18_ = 0;
	gpointer* _tmp19_;
	gint array_length1;
	gint _array_size_;
	GeeMap* _tmp20_;
	gchar** _tmp21_;
	gint _tmp21__length1;
	gchar* _tmp22_;
	gchar* _tmp23_;
	GeeArrayList* _tmp24_;
	GeeMap* _tmp25_;
	gchar** _tmp26_;
	gint _tmp26__length1;
	gchar* _tmp27_;
	gchar* _tmp28_;
	GeeArrayList* _tmp29_;
	gboolean result;
	self = (KkcUserSentenceDictionary*) base;
	offset = 0;
	_tmp0_ = gee_array_list_new (G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, NULL, NULL, NULL);
	input = _tmp0_;
	_tmp1_ = gee_array_list_new (G_TYPE_INT, NULL, NULL, NULL, NULL, NULL);
	constraint = _tmp1_;
	_tmp2_ = gee_array_list_new (G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, NULL, NULL, NULL);
	phrase = _tmp2_;
	{
		KkcSegment** segment_collection = NULL;
		gint segment_collection_length1 = 0;
		gint _segment_collection_size_ = 0;
		gint segment_it = 0;
		segment_collection = segments;
		segment_collection_length1 = segments_length1;
		for (segment_it = 0; segment_it < segment_collection_length1; segment_it = segment_it + 1) {
			KkcSegment* _tmp3_;
			KkcSegment* segment = NULL;
			_tmp3_ = _g_object_ref0 (segment_collection[segment_it]);
			segment = _tmp3_;
			{
				gint count = 0;
				KkcSegment* _tmp4_;
				const gchar* _tmp5_;
				const gchar* _tmp6_;
				GeeArrayList* _tmp7_;
				GeeArrayList* _tmp8_;
				KkcSegment* _tmp9_;
				const gchar* _tmp10_;
				const gchar* _tmp11_;
				GeeArrayList* _tmp12_;
				KkcSegment* _tmp13_;
				const gchar* _tmp14_;
				const gchar* _tmp15_;
				_tmp4_ = segment;
				_tmp5_ = kkc_segment_get_input (_tmp4_);
				_tmp6_ = _tmp5_;
				count = g_utf8_strlen (_tmp6_, (gssize) -1);
				offset += count;
				_tmp7_ = constraint;
				gee_abstract_collection_add ((GeeAbstractCollection*) _tmp7_, (gpointer) ((gintptr) offset));
				_tmp8_ = phrase;
				_tmp9_ = segment;
				_tmp10_ = kkc_segment_get_output (_tmp9_);
				_tmp11_ = _tmp10_;
				gee_abstract_collection_add ((GeeAbstractCollection*) _tmp8_, _tmp11_);
				_tmp12_ = input;
				_tmp13_ = segment;
				_tmp14_ = kkc_segment_get_input (_tmp13_);
				_tmp15_ = _tmp14_;
				gee_abstract_collection_add ((GeeAbstractCollection*) _tmp12_, _tmp15_);
				_g_object_unref0 (segment);
			}
		}
	}
	if (offset < 3) {
		result = FALSE;
		_g_object_unref0 (phrase);
		_g_object_unref0 (constraint);
		_g_object_unref0 (input);
		return result;
	}
	_tmp16_ = input;
	gee_abstract_collection_add ((GeeAbstractCollection*) _tmp16_, NULL);
	_tmp17_ = input;
	_tmp19_ = gee_collection_to_array ((GeeCollection*) _tmp17_, &_tmp18_);
	array = _tmp19_;
	array_length1 = _tmp18_;
	_array_size_ = array_length1;
	array_length1 = -1;
	_tmp20_ = self->priv->constraint_entries;
	_tmp21_ = array;
	_tmp21__length1 = array_length1;
	_tmp22_ = _vala_g_strjoinv ("", _tmp21_, (gint) _tmp21__length1);
	_tmp23_ = _tmp22_;
	_tmp24_ = constraint;
	gee_map_set (_tmp20_, _tmp23_, (GeeList*) _tmp24_);
	_g_free0 (_tmp23_);
	_tmp25_ = self->priv->phrase_entries;
	_tmp26_ = array;
	_tmp26__length1 = array_length1;
	_tmp27_ = _vala_g_strjoinv (" ", _tmp26_, (gint) _tmp26__length1);
	_tmp28_ = _tmp27_;
	_tmp29_ = phrase;
	gee_map_set (_tmp25_, _tmp28_, (GeeList*) _tmp29_);
	_g_free0 (_tmp28_);
	self->priv->is_dirty = TRUE;
	result = TRUE;
	array = (_vala_array_free (array, array_length1, (GDestroyNotify) g_free), NULL);
	_g_object_unref0 (phrase);
	_g_object_unref0 (constraint);
	_g_object_unref0 (input);
	return result;
}

/**
         * Create a new UserSentenceDictionary.
         *
         * @param path a path to the file
         *
         * @return a new UserDictionary
         * @throws GLib.Error if opening the file is failed
         */
KkcUserSentenceDictionary*
kkc_user_sentence_dictionary_construct (GType object_type,
                                        const gchar* path,
                                        GError** error)
{
	KkcUserSentenceDictionary * self = NULL;
	GFile* _tmp0_;
	gchar* _tmp1_;
	GError* _inner_error0_ = NULL;
	g_return_val_if_fail (path != NULL, NULL);
	self = (KkcUserSentenceDictionary*) 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;
}

KkcUserSentenceDictionary*
kkc_user_sentence_dictionary_new (const gchar* path,
                                  GError** error)
{
	return kkc_user_sentence_dictionary_construct (KKC_TYPE_USER_SENTENCE_DICTIONARY, path, error);
}

static void
kkc_user_sentence_dictionary_class_init (KkcUserSentenceDictionaryClass * klass,
                                         gpointer klass_data)
{
	kkc_user_sentence_dictionary_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &KkcUserSentenceDictionary_private_offset);
	G_OBJECT_CLASS (klass)->finalize = kkc_user_sentence_dictionary_finalize;
}

static void
kkc_user_sentence_dictionary_kkc_dictionary_interface_init (KkcDictionaryIface * iface,
                                                            gpointer iface_data)
{
	kkc_user_sentence_dictionary_kkc_dictionary_parent_iface = g_type_interface_peek_parent (iface);
	iface->save = (void (*) (KkcDictionary*, GError**)) kkc_user_sentence_dictionary_real_save;
	iface->reload = (void (*) (KkcDictionary*, GError**)) kkc_user_sentence_dictionary_real_reload;
}

static void
kkc_user_sentence_dictionary_kkc_sentence_dictionary_interface_init (KkcSentenceDictionaryIface * iface,
                                                                     gpointer iface_data)
{
	kkc_user_sentence_dictionary_kkc_sentence_dictionary_parent_iface = g_type_interface_peek_parent (iface);
	iface->lookup_constraint = (gboolean (*) (KkcSentenceDictionary*, const gchar*, gint**, gint*)) kkc_user_sentence_dictionary_real_lookup_constraint;
	iface->lookup_phrase = (gboolean (*) (KkcSentenceDictionary*, gchar**, gint, gchar***, gint*)) kkc_user_sentence_dictionary_real_lookup_phrase;
	iface->select_segments = (gboolean (*) (KkcSentenceDictionary*, KkcSegment**, gint)) kkc_user_sentence_dictionary_real_select_segments;
}

static void
kkc_user_sentence_dictionary_instance_init (KkcUserSentenceDictionary * self,
                                            gpointer klass)
{
	GeeHashMap* _tmp0_;
	GeeHashMap* _tmp1_;
	self->priv = kkc_user_sentence_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->constraint_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->phrase_entries = (GeeMap*) _tmp1_;
}

static void
kkc_user_sentence_dictionary_finalize (GObject * obj)
{
	KkcUserSentenceDictionary * self;
	GeeMapIterator* constraint_iter = NULL;
	GeeMap* _tmp0_;
	GeeMapIterator* _tmp1_;
	GeeMap* _tmp6_;
	GeeMapIterator* phrase_iter = NULL;
	GeeMap* _tmp7_;
	GeeMapIterator* _tmp8_;
	GeeMap* _tmp13_;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, KKC_TYPE_USER_SENTENCE_DICTIONARY, KkcUserSentenceDictionary);
	_tmp0_ = self->priv->constraint_entries;
	_tmp1_ = gee_map_map_iterator (_tmp0_);
	constraint_iter = _tmp1_;
	while (TRUE) {
		GeeMapIterator* _tmp2_;
		GeeMapIterator* _tmp3_;
		gpointer _tmp4_;
		GeeList* _tmp5_;
		_tmp2_ = constraint_iter;
		if (!gee_map_iterator_next (_tmp2_)) {
			break;
		}
		_tmp3_ = constraint_iter;
		_tmp4_ = gee_map_iterator_get_value (_tmp3_);
		_tmp5_ = (GeeList*) _tmp4_;
		gee_collection_clear ((GeeCollection*) _tmp5_);
		_g_object_unref0 (_tmp5_);
	}
	_tmp6_ = self->priv->constraint_entries;
	gee_map_clear (_tmp6_);
	_tmp7_ = self->priv->phrase_entries;
	_tmp8_ = gee_map_map_iterator (_tmp7_);
	phrase_iter = _tmp8_;
	while (TRUE) {
		GeeMapIterator* _tmp9_;
		GeeMapIterator* _tmp10_;
		gpointer _tmp11_;
		GeeList* _tmp12_;
		_tmp9_ = phrase_iter;
		if (!gee_map_iterator_next (_tmp9_)) {
			break;
		}
		_tmp10_ = phrase_iter;
		_tmp11_ = gee_map_iterator_get_value (_tmp10_);
		_tmp12_ = (GeeList*) _tmp11_;
		gee_collection_clear ((GeeCollection*) _tmp12_);
		_g_object_unref0 (_tmp12_);
	}
	_tmp13_ = self->priv->phrase_entries;
	gee_map_clear (_tmp13_);
	_g_object_unref0 (phrase_iter);
	_g_object_unref0 (constraint_iter);
	_g_object_unref0 (self->priv->file);
	_g_free0 (self->priv->etag);
	_g_object_unref0 (self->priv->constraint_entries);
	_g_object_unref0 (self->priv->phrase_entries);
	G_OBJECT_CLASS (kkc_user_sentence_dictionary_parent_class)->finalize (obj);
}

/**
     * File based implementation of SentenceDictionary with write access.
     */
static GType
kkc_user_sentence_dictionary_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (KkcUserSentenceDictionaryClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) kkc_user_sentence_dictionary_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (KkcUserSentenceDictionary), 0, (GInstanceInitFunc) kkc_user_sentence_dictionary_instance_init, NULL };
	static const GInterfaceInfo kkc_dictionary_info = { (GInterfaceInitFunc) kkc_user_sentence_dictionary_kkc_dictionary_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
	static const GInterfaceInfo kkc_sentence_dictionary_info = { (GInterfaceInitFunc) kkc_user_sentence_dictionary_kkc_sentence_dictionary_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
	GType kkc_user_sentence_dictionary_type_id;
	kkc_user_sentence_dictionary_type_id = g_type_register_static (G_TYPE_OBJECT, "KkcUserSentenceDictionary", &g_define_type_info, 0);
	g_type_add_interface_static (kkc_user_sentence_dictionary_type_id, KKC_TYPE_DICTIONARY, &kkc_dictionary_info);
	g_type_add_interface_static (kkc_user_sentence_dictionary_type_id, KKC_TYPE_SENTENCE_DICTIONARY, &kkc_sentence_dictionary_info);
	KkcUserSentenceDictionary_private_offset = g_type_add_instance_private (kkc_user_sentence_dictionary_type_id, sizeof (KkcUserSentenceDictionaryPrivate));
	return kkc_user_sentence_dictionary_type_id;
}

GType
kkc_user_sentence_dictionary_get_type (void)
{
	static volatile gsize kkc_user_sentence_dictionary_type_id__once = 0;
	if (g_once_init_enter (&kkc_user_sentence_dictionary_type_id__once)) {
		GType kkc_user_sentence_dictionary_type_id;
		kkc_user_sentence_dictionary_type_id = kkc_user_sentence_dictionary_get_type_once ();
		g_once_init_leave (&kkc_user_sentence_dictionary_type_id__once, kkc_user_sentence_dictionary_type_id);
	}
	return kkc_user_sentence_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;
}

