<commit_before>-module(sheldon_suggestions_server).

-behaviour(gen_server).

%%% API
-export([ suggestions/2
        , add_suggestions/2
        ]).

%%% gen_server callbacks
-export([
  init/1,
  handle_call/3,
  handle_cast/2,
  handle_info/2,
  terminate/2,
  code_change/3
]).

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

-spec suggestions([sheldon_result:misspelled_word()], sheldon_dictionary:language()) ->
  [sheldon_result:misspelled_word()].
suggestions(MisspelledWords, Lang) ->
  try rpc:pmap({?MODULE, add_suggestions}, [Lang], MisspelledWords) of
    Result -> Result
  catch
    exit:badrpc:Stacktrace ->
      error_logger:error_msg( "~p:~p >> Error: badrpc~n\tStack: ~p"
                            , [?MODULE, ?LINE, Stacktrace]
                            ),
      MisspelledWords
  end.

-spec add_suggestions(sheldon_result:misspelled_word(), sheldon_dictionary:language()) ->
  sheldon_result:misspelled_word().
add_suggestions(#{word := Word} = MisspelledWord, Lang) ->
  Timeout = application:get_env(sheldon, suggestion_timeout, 15000),
  Candidates = wpool:call(suggestions_pool, {suggest, Word, Lang}, available_worker, Timeout),
  MisspelledWord#{candidates => Candidates}.

%%%=============================================================================
%%% gen_server callbacks
%%%=============================================================================

-spec init(no_args) -> {ok, map()}.
init(no_args) ->
  {ok, #{}}.<commit_msg>[#49] removing catch<commit_after>-module(sheldon_suggestions_server).

-behaviour(gen_server).

%%% API
-export([ suggestions/2
        , add_suggestions/2
        ]).

%%% gen_server callbacks
-export([
  init/1,
  handle_call/3,
  handle_cast/2,
  handle_info/2,
  terminate/2,
  code_change/3
]).

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

-spec suggestions([sheldon_result:misspelled_word()], sheldon_dictionary:language()) ->
  [sheldon_result:misspelled_word()].
suggestions(MisspelledWords, Lang) ->
  rpc:pmap({?MODULE, add_suggestions}, [Lang], MisspelledWords).

-spec add_suggestions(sheldon_result:misspelled_word(), sheldon_dictionary:language()) ->
  sheldon_result:misspelled_word().
add_suggestions(#{word := Word} = MisspelledWord, Lang) ->
  Timeout = application:get_env(sheldon, suggestion_timeout, 15000),
  Candidates = wpool:call(suggestions_pool, {suggest, Word, Lang}, available_worker, Timeout),
  MisspelledWord#{candidates => Candidates}.

%%%=============================================================================
%%% gen_server callbacks
%%%=============================================================================

-spec init(no_args) -> {ok, map()}.
init(no_args) ->
  {ok, #{}}.
{'fraction_non_alphanumeric': 0.336613505259586, 'fraction_numerical': 0.009501187648456057, 'mean_word_length': 5.969267139479905, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 21, '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': '1538712', 'n_tokens_mistral': 935, 'n_tokens_neox': 852, 'n_words': 128}