<commit_before>%%%-------------------------------------------------------------------
%%% File    : interpreter.erl
%%% Author  : klemo <<EMAIL>>
%%% Description : Interpreter process for metafeed queries
%%% Created : 14 Apr 2010 by klemo <<EMAIL>>
%%%-------------------------------------------------------------------
-module(interpreter).
-export([main/2]).

%%%-------------------------------------------------------------------
%% Main interpreter process loop
%%%-------------------------------------------------------------------
main(Name, Query) ->
    main(Name, Query, create_init_state()).

main(Name, Query, State) ->
    receive
        %% start query execution
        {From, {run}} ->
            try do(Query) of
                Result ->
                    From ! {ok, Result}
            catch
                _:_ ->
                    io:format("Error ~p: ~n~p.~n", [Name, erlang:get_stacktrace()]),
                    From ! {error, Name}
            end,
            main(Name, Query, State);
        %% update query text
        {From, {update, NewQuery}} ->
            From ! {ok, Name},
            main(Name, NewQuery, State);
        %% dispach on lambda
        {From, {call, F}} ->
            F(),
            From ! {ok, Name},
            main(Name, Query, State);
        %% display process information
        {From, {get_info}} ->
            From ! {ok, {Name, self(), State}},
            main(Name, Query, State);
        %% terminate query
        {From, {stop}} ->
            From ! {ok, Name},
            {ok}
    end.

%%%-------------------------------------------------------------------
%% query language interpreter
%%%-------------------------------------------------------------------

do({fetch, Source}) ->
    feed_parser:fetch({url, Source});

do({fetch, url, Source}) ->
    feed_parser:fetch({url, Source});

do({fetch, pipe, Source}) ->
    feed_parser:fetch({pipe, Source});

do({filter, contains, String, Elements, L}) ->
    feed_parser:filter({contains, String, Elements},
                        do(L));<commit_msg>read rss feed message in interpreter<commit_after>%%%-------------------------------------------------------------------
%%% File    : interpreter.erl
%%% Author  : klemo <<EMAIL>>
%%% Description : Interpreter process for metafeed queries
%%% Created : 14 Apr 2010 by klemo <<EMAIL>>
%%%-------------------------------------------------------------------
-module(interpreter).
-export([main/2]).

%%%-------------------------------------------------------------------
%% Main interpreter process loop
%%%-------------------------------------------------------------------
main(Name, Query) ->
    main(Name, Query, create_init_state()).

main(Name, Query, State) ->
    receive
        %% start query execution
        {From, {run}} ->
            try do(Query) of
                Result ->
                    From ! {ok, Result}
            catch
                _:_ ->
                    io:format("Error ~p: ~n~p.~n", [Name, erlang:get_stacktrace()]),
                    From ! {error, Name}
            end,
            main(Name, Query, State);
        %% update query text
        {From, {update, NewQuery}} ->
            From ! {ok, Name},
            main(Name, NewQuery, State);
        %% generate rss feed
        {From, {read}} ->
            From ! {ok, utils:gen_rss(do(Query))},
            main(Name, Query, State);
        %% dispach on lambda
        {From, {call, F}} ->
            F(),
            From ! {ok, Name},
            main(Name, Query, State);
        %% display process information
        {From, {get_info}} ->
            From ! {ok, {Name, self(), State}},
            main(Name, Query, State);
        %% terminate query
        {From, {stop}} ->
            From ! {ok, Name},
            {ok}
    end.

%%%-------------------------------------------------------------------
%% query language interpreter
%%%-------------------------------------------------------------------

do({fetch, Source}) ->
    feed_parser:fetch({url, Source});

do({fetch, url, Source}) ->
    feed_parser:fetch({url, Source});

do({fetch, pipe, Source}) ->
    feed_parser:fetch({pipe, Source});

do({filter, contains, String, Elements, L}) ->
    feed_parser:filter({contains, String, Elements},
                        do(L));
{'fraction_non_alphanumeric': 0.3195566843685061, 'fraction_numerical': 0.0032325098129762178, 'mean_word_length': 1.1308411214953271, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 38, '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': '7412173', 'n_tokens_mistral': 1091, 'n_tokens_neox': 1037, 'n_words': 279}