<commit_before>:- module(
  chr_ext,
  [
    chr_closure/3, % +Set:ordset
                   % -Closure:ordset
                   % +Module:atom
    chr_closure/5 % +Set:ordset
                  % -Closure:ordset
                  % +Module:atom
                  % +Topic:compound
                  % :Dcg_3
  ]
).
:- reexport(library(chr)).

/** <module> Constraint Handling Rules

@author <NAME>
@version 2015/10
*/

:- use_module(library(aggregate)).
:- use_module(library(apply)).
:- use_module(library(dcg/dcg_call)).
:- use_module(library(dcg/dcg_debug)).
:- use_module(library(dcg/dcg_pl_term)).

:- meta_predicate(chr_closure(+,-,+,+,3)).
:- meta_predicate(chr_debug(+,3,+)).





%! chr_closure(+Set:ordset, -Closure:ordset, +Module:atom) is det.
% Wrapper around chr_closure/5 that used the default debug tools.

chr_closure(S1, S2, Mod):-
  chr_closure(S1, S2, Mod, chr, pl_term).


%! chr_closure(
%!   +Set:ordset,
%!   +Topic:compound,
%!   +Module:atom,
%!   :Dcg_3,
%!   -Closure:ordset
%! ) is det.

chr_closure(S1, S2, Mod, Topic, Dcg_3):-
  maplist(call_on_module(Mod), S1),
  aggregate(
    set(Fact),
    (
      Mod:find_chr_constraint(Fact),
      chr_debug(Topic, Dcg_3, Fact)
    ),
    S2
  ), !.





% HELPERS %

%! call_on_module(+Module:atom, :Goal_0) is det.

call_on_module(Mod, Goal_0):-
  call(Mod:Goal_0).



%! chr_debug(+Topic:compound, :Dcg_3, +Fact) is det.

chr_debug(Topic, Dcg_3, Fact):-
  dcg_debug(Topic, dcg_call(Dcg_3, Fact)).<commit_msg>FIXED: Allow empty result set in `chr_closure/[3,5]'.<commit_after>:- module(
  chr_ext,
  [
    chr_closure/3, % +Set:ordset
                   % -Closure:ordset
                   % +Module:atom
    chr_closure/5 % +Set:ordset
                  % -Closure:ordset
                  % +Module:atom
                  % +Topic:compound
                  % :Dcg_3
  ]
).
:- reexport(library(chr)).

/** <module> Constraint Handling Rules

@author <NAME>
@version 2015/10
*/

:- use_module(library(aggregate)).
:- use_module(library(apply)).
:- use_module(library(dcg/dcg_call)).
:- use_module(library(dcg/dcg_debug)).
:- use_module(library(dcg/dcg_pl_term)).

:- meta_predicate(chr_closure(+,-,+,+,3)).
:- meta_predicate(chr_debug(+,3,+)).





%! chr_closure(+Set:ordset, -Closure:ordset, +Module:atom) is det.
% Wrapper around chr_closure/5 that used the default debug tools.

chr_closure(S1, S2, Mod):-
  chr_closure(S1, S2, Mod, chr, pl_term).


%! chr_closure(
%!   +Set:ordset,
%!   +Topic:compound,
%!   +Module:atom,
%!   :Dcg_3,
%!   -Closure:ordset
%! ) is det.

chr_closure(S1, S2, Mod, Topic, Dcg_3):-
  maplist(call_on_module(Mod), S1),
  aggregate_all(
    set(Fact),
    (
      Mod:find_chr_constraint(Fact),
      chr_debug(Topic, Dcg_3, Fact)
    ),
    S2
  ), !.





% HELPERS %

%! call_on_module(+Module:atom, :Goal_0) is det.

call_on_module(Mod, Goal_0):-
  call(Mod:Goal_0).



%! chr_debug(+Topic:compound, :Dcg_3, +Fact) is det.

chr_debug(Topic, Dcg_3, Fact):-
  dcg_debug(Topic, dcg_call(Dcg_3, Fact)).
{'fraction_non_alphanumeric': 0.17252820172528202, 'fraction_numerical': 0.019907100199071003, 'mean_word_length': 2.993377483443709, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '575364', 'n_tokens_mistral': 1287, 'n_tokens_neox': 1209, 'n_words': 189}