<commit_before>/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
/*
 * GData Client
 * Copyright (C) 2014 <NAME> <<EMAIL>>
 *
 * GData Client is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * GData Client 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with GData Client.  If not, see <http://www.gnu.org/licenses/>.
 */

/**
 * SECTION:gdata-freebase-topic-result
 * @short_description: GData Freebase topic result object
 * @stability: Unstable
 * @include: gdata/services/freebase/gdata-freebase-topic-result.h
 *
 * #GDataFreebaseTopicResult is a subclass of #GDataFreebaseResult that contains all or a subset of the information
 * contained in Freebase about the Freebase ID given to the #GDataFreebaseTopicQuery.
 *
 * For more details of Google Freebase API, see the <ulink type="http" url="https://developers.google.com/freebase/v1/">
 * online documentation</ulink>.
 *
 * Since: UNRELEASED
 */

typedef struct _GDataFreebaseTopicValueArray GDataFreebaseTopicValueArray;

#include <config.h>
#include <glib.h>
#include <glib/gi18n-lib.h>
#include <string.h>

#include "gdata-freebase-topic-result.h"
#include "gdata-download-stream.h"
#include "gdata-private.h"
#include "gdata-types.h"

typedef enum {
	TYPE_NONE,
	TYPE_BOOL,
	TYPE_INT,
	TYPE_DOUBLE,
	TYPE_STRING,
	TYPE_DATETIME,
	TYPE_COMPOUND,
	TYPE_OBJECT,
	TYPE_KEY,
	TYPE_URI
} TopicValueType;

/* Wraps a compound object, either the main object returned by the result, or a
 * complex object within the result values (events are at least composed of
 * location and time at least, for example).
 */
struct _GDataFreebaseTopicObject {
	gchar *id;
	GHashTable *values; /* Hashtable of property->GDataFreebaseTopicValueArray */
	volatile gint ref_count;
};

/* Wraps an array of values, single-valued properties will contain an array with a single value here */
struct _GDataFreebaseTopicValueArray {
	TopicValueType type;
	GPtrArray *values;
	guint64 hits; /* Total number of hits, as opposed to values->len */
};

/* Wraps a single value in the topic result, may be either simple (numbers, strings, Freebase IDs...),
 * or nested compound types (contained by a GDataFreebaseTopicObject, which is what the value would
 * contain in that case).
 */
struct _GDataFreebaseTopicValue {
	gchar *property;
	gchar *text;
	gchar *lang;
	gchar *creator;
	gint64 timestamp;
	GValue value;
	gint ref_count;
};

struct _GDataFreebaseTopicResultPrivate {
	GDataFreebaseTopicObject *object;
};

static void gdata_freebase_topic_result_finalize (GObject *self);
static gboolean parse_json (GDataParsable *parsable, JsonReader *reader, gpointer user_data, GError **error);
static GDataFreebaseTopicObject *object_new (const gchar *id);
static void value_free (GDataFreebaseTopicValue *object);
static gboolean reader_get_properties (JsonReader *reader, GDataFreebaseTopicObject *object, GError **error);

G_DEFINE_BOXED_TYPE (GDataFreebaseTopicObject, gdata_freebase_topic_object, gdata_freebase_topic_object_ref, gdata_freebase_topic_object_unref)
G_DEFINE_BOXED_TYPE (GDataFreebaseTopicValue, gdata_freebase_topic_value, gdata_freebase_topic_value_ref, gdata_freebase_topic_value_unref)
G_DEFINE_TYPE (GDataFreebaseTopicResult, gdata_freebase_topic_result, GDATA_TYPE_FREEBASE_RESULT)

static void
gdata_freebase_topic_result_class_init (GDataFreebaseTopicResultClass *klass)
{
	GDataParsableClass *parsable_class = GDATA_PARSABLE_CLASS (klass);<commit_msg>freebase: Add missing volatile hint on refcount counter<commit_after>/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
/*
 * GData Client
 * Copyright (C) 2014 <NAME> <<EMAIL>>
 *
 * GData Client is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * GData Client 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with GData Client.  If not, see <http://www.gnu.org/licenses/>.
 */

/**
 * SECTION:gdata-freebase-topic-result
 * @short_description: GData Freebase topic result object
 * @stability: Unstable
 * @include: gdata/services/freebase/gdata-freebase-topic-result.h
 *
 * #GDataFreebaseTopicResult is a subclass of #GDataFreebaseResult that contains all or a subset of the information
 * contained in Freebase about the Freebase ID given to the #GDataFreebaseTopicQuery.
 *
 * For more details of Google Freebase API, see the <ulink type="http" url="https://developers.google.com/freebase/v1/">
 * online documentation</ulink>.
 *
 * Since: UNRELEASED
 */

typedef struct _GDataFreebaseTopicValueArray GDataFreebaseTopicValueArray;

#include <config.h>
#include <glib.h>
#include <glib/gi18n-lib.h>
#include <string.h>

#include "gdata-freebase-topic-result.h"
#include "gdata-download-stream.h"
#include "gdata-private.h"
#include "gdata-types.h"

typedef enum {
	TYPE_NONE,
	TYPE_BOOL,
	TYPE_INT,
	TYPE_DOUBLE,
	TYPE_STRING,
	TYPE_DATETIME,
	TYPE_COMPOUND,
	TYPE_OBJECT,
	TYPE_KEY,
	TYPE_URI
} TopicValueType;

/* Wraps a compound object, either the main object returned by the result, or a
 * complex object within the result values (events are at least composed of
 * location and time at least, for example).
 */
struct _GDataFreebaseTopicObject {
	gchar *id;
	GHashTable *values; /* Hashtable of property->GDataFreebaseTopicValueArray */
	volatile gint ref_count;
};

/* Wraps an array of values, single-valued properties will contain an array with a single value here */
struct _GDataFreebaseTopicValueArray {
	TopicValueType type;
	GPtrArray *values;
	guint64 hits; /* Total number of hits, as opposed to values->len */
};

/* Wraps a single value in the topic result, may be either simple (numbers, strings, Freebase IDs...),
 * or nested compound types (contained by a GDataFreebaseTopicObject, which is what the value would
 * contain in that case).
 */
struct _GDataFreebaseTopicValue {
	gchar *property;
	gchar *text;
	gchar *lang;
	gchar *creator;
	gint64 timestamp;
	GValue value;
	volatile gint ref_count;
};

struct _GDataFreebaseTopicResultPrivate {
	GDataFreebaseTopicObject *object;
};

static void gdata_freebase_topic_result_finalize (GObject *self);
static gboolean parse_json (GDataParsable *parsable, JsonReader *reader, gpointer user_data, GError **error);
static GDataFreebaseTopicObject *object_new (const gchar *id);
static void value_free (GDataFreebaseTopicValue *object);
static gboolean reader_get_properties (JsonReader *reader, GDataFreebaseTopicObject *object, GError **error);

G_DEFINE_BOXED_TYPE (GDataFreebaseTopicObject, gdata_freebase_topic_object, gdata_freebase_topic_object_ref, gdata_freebase_topic_object_unref)
G_DEFINE_BOXED_TYPE (GDataFreebaseTopicValue, gdata_freebase_topic_value, gdata_freebase_topic_value_ref, gdata_freebase_topic_value_unref)
G_DEFINE_TYPE (GDataFreebaseTopicResult, gdata_freebase_topic_result, GDATA_TYPE_FREEBASE_RESULT)

static void
gdata_freebase_topic_result_class_init (GDataFreebaseTopicResultClass *klass)
{
	GDataParsableClass *parsable_class = GDATA_PARSABLE_CLASS (klass);
{'fraction_non_alphanumeric': 0.08368253968253968, 'fraction_numerical': 0.0038095238095238095, 'mean_word_length': 5.40846216436127, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 27, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5895963', 'n_tokens_mistral': 2489, 'n_tokens_neox': 2443, 'n_words': 795}