<commit_before># -*- coding: utf-8 -*-

module Agharta
  module UserStream
    module Hooks
      class Keyword < Hook
        def initialize(context, *args, &block)
          options = args.last.is_a?(Hash) ? args.pop : {}
          @include = args
          @exclude = options.fetch(:exclude, [])
          @ignore_self = options.fetch(:ignore_self, false)
          super
        end

        # TODO: implement ignore self
        def call(status)
          return unless status[:text]
          return unless status[:user]
          return unless @include.flatten.any? { |k| status[:text].match(k) }
          keyword = $&.to_s
          return if @exclude.flatten.any? { |k| status[:text].match(k) }
          invoke(status, :type => :keyword, :keyword => keyword)
        end

        def include(*keywords)
          @include.concat(keywords)
        end

        def exclude(*keywords)
          @exclude.concat(keywords)
        end

        def ignore_self!
          @ignore_self = true
        end
      end
    end
  end
end<commit_msg>Implement ignore self at keyword hook.<commit_after># -*- coding: utf-8 -*-

module Agharta
  module UserStream
    module Hooks
      class Keyword < Hook
        def initialize(context, *args, &block)
          options = args.last.is_a?(Hash) ? args.pop : {}
          @include = args
          @exclude = options.fetch(:exclude, [])
          @ignore_self = options.fetch(:ignore_self, false)
          super
        end

        def call(status)
          return unless status[:text]
          return unless status[:user]
          return if @ignore_self && current_user?(status[:user][:screen_name])
          return unless @include.flatten.any? { |k| status[:text].match(k) }
          keyword = $&.to_s
          return if @exclude.flatten.any? { |k| status[:text].match(k) }
          invoke(status, :type => :keyword, :keyword => keyword)
        end

        def include(*keywords)
          @include.concat(keywords)
        end

        def exclude(*keywords)
          @exclude.concat(keywords)
        end

        def ignore_self!
          @ignore_self = true
        end
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.11414048059149723, 'fraction_numerical': 0.0009242144177449168, 'mean_word_length': 1.890520694259012, 'pattern_counts': {'":': 0, '<': 5, '<?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': '919145', 'n_tokens_mistral': 628, 'n_tokens_neox': 607, 'n_words': 154}