<commit_before>module Pione::Model
  # RuleIOElement is a special PIONE model object for matched data name result.
  class RuleIOElement < BasicModel
    set_pione_model_type TypeRuleIOElement

    attr_accessor :name
    attr_accessor :uri
    attr_accessor :match

    # Creates a element with the name.
    # @param [PioneString, String] name
    #   element name
    def initialize(name)
      @name = name.kind_of?(PioneString) ? name : PioneString.new(name)
      @uri = PioneString.new("")
      @match = PioneList.new()
    end

    # @api private
    def textize
      "rule-io-element(%s,%s,%s)" % [@name.to_ruby, @uri.textize, @match.textize]
    end

    # @api private
    def uri=(uri)
      @uri = uri.to_pione
    end

    # @api private
    def ==(other)
      return false unless other.kind_of?(self.class)
      @name == other.name && @uri == other.uri && @match == other.match
    end

    alias :eql? :"=="

    # @api private
    def hash
      @value.hash
    end

    #
    # pione method
    #

    define_pione_method("==", [TypeRuleIOElement], TypeBoolean) do |rec, other|
      PioneBoolean.new(rec.values == other.values)
    end

    define_pione_method("!=", [TypeRuleIOElement], TypeBoolean) do |rec, other|
      PioneBoolean.not(rec.call_pione_method("==", other))
    end

    define_pione_method("uri", [], TypeString) do |rec, other|
      PioneString.new(rec.uri)
    end

    define_pione_method("match", [], TypeList.new(TypeString)) do |rec|
      rec.match
    end

    define_pione_method("MATCH", [], TypeList.new(TypeString)) do |rec|
      rec.call_pione_method("match")
    end

    define_pione_method("as_string", [], TypeString) do |rec|
      rec.name
    end
  end

  # RuleIOList is a input or output list for RuleIOElement.<commit_msg>Add pione method #[] for io-element. This fixes wrong errors about [1].<commit_after>module Pione::Model
  # RuleIOElement is a special PIONE model object for matched data name result.
  class RuleIOElement < BasicModel
    set_pione_model_type TypeRuleIOElement

    attr_accessor :name
    attr_accessor :uri
    attr_accessor :match

    # Creates a element with the name.
    # @param [PioneString, String] name
    #   element name
    def initialize(name)
      @name = name.kind_of?(PioneString) ? name : PioneString.new(name)
      @uri = PioneString.new("")
      @match = PioneList.new()
    end

    # @api private
    def textize
      "rule-io-element(%s,%s,%s)" % [@name.to_ruby, @uri.textize, @match.textize]
    end

    # @api private
    def uri=(uri)
      @uri = uri.to_pione
    end

    # @api private
    def ==(other)
      return false unless other.kind_of?(self.class)
      @name == other.name && @uri == other.uri && @match == other.match
    end

    alias :eql? :"=="

    # @api private
    def hash
      @value.hash
    end

    #
    # pione method
    #

    define_pione_method("==", [TypeRuleIOElement], TypeBoolean) do |rec, other|
      PioneBoolean.new(rec.values == other.values)
    end

    define_pione_method("!=", [TypeRuleIOElement], TypeBoolean) do |rec, other|
      PioneBoolean.not(rec.call_pione_method("==", other))
    end

    define_pione_method("uri", [], TypeString) do |rec, other|
      PioneString.new(rec.uri)
    end

    define_pione_method("match", [], TypeList.new(TypeString)) do |rec|
      rec.match
    end

    define_pione_method("MATCH", [], TypeList.new(TypeString)) do |rec|
      rec.call_pione_method("match")
    end

    define_pione_method("[]", [TypeInteger], TypeAny) do |rec, i|
      rec.match[i.value-1]
    end

    define_pione_method("as_string", [], TypeString) do |rec|
      rec.name
    end
  end

  # RuleIOList is a input or output list for RuleIOElement.
{'fraction_non_alphanumeric': 0.12520064205457465, 'fraction_numerical': 0.0005350454788657035, 'mean_word_length': 2.890738813735692, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '2613814', 'n_tokens_mistral': 1278, 'n_tokens_neox': 1233, 'n_words': 301}