<commit_before>%%% @doc Main **internal** module for sumo.
%%%      Use this one from your own applications.
%%%
%%% Copyright 2012 Inaka &lt;<EMAIL>&gt;
%%%
%%% Licensed under the Apache License, Version 2.0 (the "License");
%%% you may not use this file except in compliance with the License.
%%% You may obtain a copy of the License at
%%%
%%%     http://www.apache.org/licenses/LICENSE-2.0
%%%
%%% Unless required by applicable law or agreed to in writing, software
%%% distributed under the License is distributed on an "AS IS" BASIS,
%%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
%%% See the License for the specific language governing permissions and
%%% limitations under the License.
%%% @end
%%% @copyright Inaka <<EMAIL>>
%%%
-module(sumo_internal).
-author("<NAME> <<EMAIL>>").
-author("<NAME> <<EMAIL>>").
-github("https://github.com/inaka").
-license("Apache License 2.0").

%%% API for doc/schema manipulation.
-export([new_schema/2, new_field/3]).

%%% API for opaqueness
-export([
  schema_name/1,
  schema_fields/1,
  doc_name/1,
  doc_fields/1,
  wakeup/1,
  new_doc/1,
  new_doc/2
]).

%%% API for schema fields manipulation.
-export([
  get_schema/1,
  field_name/1,
  field_type/1,
  field_attrs/1,
  field_is/2,
  get_field/2,
  set_field/3,
  id_field_name/1,
  id_field_type/1
]).

%%% API for conditional logic.
-export([check_operator/1]).

-export([report_overrun/1]).

%%%===================================================================
%%% Types definitions
%%%===================================================================

-opaque schema() :: #{
  name   => atom(),
  fields => [field()]
}.

-opaque doc() :: #{
  name   => atom(),
  module => module(),
  fields => sumo:model()
}.

-opaque field()  :: #{
  name  => atom(),
  type  => atom(),
  attrs => sumo:field_attrs()
}.

-export_type([schema/0, doc/0, field/0]).

%%%===================================================================
%%% API
%%%===================================================================

%% @doc Returns a new schema.
-spec new_schema(sumo:schema_name(), [field()]) -> schema().
new_schema(Name, Fields) ->
  #{name => Name, fields => Fields}.

%% @doc Returns a new field of the given type and attributes.
-spec new_field(
  sumo:field_name(), sumo:field_type(), sumo:field_attrs()
) -> field().
new_field(Name, Type, Attributes) ->
  #{name => Name, type => Type, attrs => Attributes}.

%% @doc Returns the name of the schema
-spec schema_name(schema()) -> sumo:schema_name().<commit_msg>Enforce that schema has at least a field with at least `id` attribute<commit_after>%%% @doc Main **internal** module for sumo.
%%%      Use this one from your own applications.
%%%
%%% Copyright 2012 Inaka &lt;<EMAIL>&gt;
%%%
%%% Licensed under the Apache License, Version 2.0 (the "License");
%%% you may not use this file except in compliance with the License.
%%% You may obtain a copy of the License at
%%%
%%%     http://www.apache.org/licenses/LICENSE-2.0
%%%
%%% Unless required by applicable law or agreed to in writing, software
%%% distributed under the License is distributed on an "AS IS" BASIS,
%%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
%%% See the License for the specific language governing permissions and
%%% limitations under the License.
%%% @end
%%% @copyright Inaka <<EMAIL>>
%%%
-module(sumo_internal).
-author("<NAME> <<EMAIL>>").
-author("<NAME> <<EMAIL>>").
-github("https://github.com/inaka").
-license("Apache License 2.0").

%%% API for doc/schema manipulation.
-export([new_schema/2, new_field/3]).

%%% API for opaqueness
-export([
  schema_name/1,
  schema_fields/1,
  doc_name/1,
  doc_fields/1,
  wakeup/1,
  new_doc/1,
  new_doc/2
]).

%%% API for schema fields manipulation.
-export([
  get_schema/1,
  field_name/1,
  field_type/1,
  field_attrs/1,
  field_is/2,
  get_field/2,
  set_field/3,
  id_field_name/1,
  id_field_type/1
]).

%%% API for conditional logic.
-export([check_operator/1]).

-export([report_overrun/1]).

%%%===================================================================
%%% Types definitions
%%%===================================================================

-opaque schema() :: #{
  name   => atom(),
  fields => [field()]
}.

-opaque doc() :: #{
  name   => atom(),
  module => module(),
  fields => sumo:model()
}.

-opaque field()  :: #{
  name  => atom(),
  type  => atom(),
  attrs => sumo:field_attrs()
}.

-export_type([schema/0, doc/0, field/0]).

%%%===================================================================
%%% API
%%%===================================================================

%% @doc Returns a new schema.
-spec new_schema(sumo:schema_name(), [field()]) -> schema().
new_schema(Name, Fields) ->
  S = #{name => Name, fields => Fields},
  _ = get_id_field(S),
  S.

%% @doc Returns a new field of the given type and attributes.
-spec new_field(
  sumo:field_name(), sumo:field_type(), sumo:field_attrs()
) -> field().
new_field(Name, Type, Attributes) ->
  #{name => Name, type => Type, attrs => Attributes}.

%% @doc Returns the name of the schema
-spec schema_name(schema()) -> sumo:schema_name().
{'fraction_non_alphanumeric': 0.2657396678254152, 'fraction_numerical': 0.012746234067207415, 'mean_word_length': 4.503719447396387, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 57, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6680236', 'n_tokens_mistral': 1664, 'n_tokens_neox': 1624, 'n_words': 466}