<commit_before>require 'spqr/spqr'
require 'rhubarb/rhubarb'
require 'mrg/grid/config/Subsystem'
require 'mrg/grid/config/Parameter'
require 'mrg/grid/config/ArcLabel'
require 'mrg/grid/config/ArcUtils'
require 'mrg/grid/config/QmfUtils'

require 'set'

module Mrg
  module Grid
    module Config
      class Feature
        include ::Rhubarb::Persisting
        include ::SPQR::Manageable

        qmf_package_name 'mrg.grid.config'
        qmf_class_name 'Feature'
        ### Property method declarations
        # property uid uint32 

        declare_column :name, :string
        declare_index_on :name
        
        def uid
          @row_id
        end
        
        def Feature.find_by_uid(u)
          find(u)
        end
        
        qmf_property :uid, :uint32, :index=>true
        ### Schema method declarations
        
        # GetName 
        # * name (sstr/O)
        def GetName()
          log.debug "GetName called on feature #{self.inspect}"
          # Assign values to output parameters
          return self.name
        end
        
        expose :GetName do |args|
          args.declare :name, :sstr, :out, {}
        end
        
        # SetName 
        # * name (sstr/I)
        def SetName(name)
          # Print values of input parameters
          log.debug "SetName: name => #{name}"
          raise "Feature name #{name} is taken" if (self.name != name and Feature.find_first_by_name(name))
          self.name = name
        end
        
        expose :SetName do |args|
          args.declare :name, :sstr, :in, {}
        end
        
        # GetFeatures 
        # * list (map/O)
        #   list of other features a feature includes
        def GetFeatures()
          log.debug "GetFeatures called on feature #{self.inspect}"
          # Assign values to output parameters
          list ||= {}
          log.warn "GetFeatures() is not implemented"
          # Return value
          return list
        end
        
        expose :GetFeatures do |args|
          args.declare :list, :map, :out, {}
        end
        
        # ModifyFeatures 
        # * command (sstr/I)
        #   Valid commands are 'ADD', 'REMOVE', and 'REPLACE'.
        # * features (map/I)
        #   A list of other features a feature includes
        def ModifyFeatures(command,features,options={})
          # Print values of input parameters
          log.debug "ModifyFeatures: command => #{command}"
          log.debug "ModifyFeatures: features => #{features}"
        end
        
        expose :ModifyFeatures do |args|
          args.declare :command, :sstr, :in, {}
          args.declare :features, :map, :in, {}
          args.declare :options, :map, :in, {}
        end
        
        # GetParams 
        # * list (map/O)
        #   A map(paramName, value) of parameters and their corresponding values that is specific to a group
        def GetParams()
          log.debug "GetParams called on feature #{self.inspect}"
          Hash[*FeatureParams.find_by(:feature=>self).map {|fp| [fp.param.name, fp.value]}.flatten]
        end
        
        expose :GetParams do |args|
          args.declare :list, :map, :out, {}
        end
        
        def GetParamsAsString
          log.debug "GetParamsAsString called on feature #{self.inspect}"
          hash = self.GetParams
          "{"+hash.map{|pair| "#{pair[0].inspect}:#{pair[1].inspect}"}.join(",")+"}"
        end
        
        expose :GetParamsAsString do |args|
          args.declare :params, :lstr, :out, {}
        end
        
        def AddParamMapping(param,value)
          log.debug "AddParam:  param => #{param}"
          log.debug "AddParam:  value => #{value}"
          
          self.ModifyParams("ADD", {param=>value})
        end

        expose :AddParamMapping do |args|
          args.declare :param, :sstr, :in, {}
          args.declare :value, :sstr, :in, {}
        end

        def RemoveParamMapping(param)
          log.debug "RemoveParam:  param => #{param}"
          
          self.ModifyParams("REMOVE", {param=>true})
        end

        expose :RemoveParamMapping do |args|
          args.declare :param, :sstr, :in, {}
        end
        
        def ClearParams
          log.debug "ClearParams called on feature #{self.inspect}"
          self.ModifyParams("REPLACE", {})
          0
        end
        
        expose :ClearParams do |args|
          args.declare :ret, :int, :out, {}
        end
        
        # ModifyParams 
        # * command (sstr/I)
        #   Valid commands are 'ADD', 'REMOVE', and 'REPLACE'.
        # * params (map/I)
        #   A map(paramName, value) of parameters and their corresponding values that is specific to a group
        def ModifyParams(command,pvmap,options={})
          # Print values of input parameters
          log.debug "ModifyParams: command => #{command}"
          log.debug "ModifyParams: params => #{pvmap}"
          
          pvmap ||= {}
          
          params = pvmap.keys.map do |pn|
            prow = Parameter.find_first_by_name(pn)
            raise "invalid parameter #{pn}" unless prow
            prow
          end
          
          case command
          when "ADD", "REMOVE" then
            params.each do |prow|
              pn = prow.name

              # Delete any prior mappings for each supplied param in either case
              FeatureParams.find_by(:feature=>self, :param=>prow).map {|fp| fp.delete}
              
              # Add new mappings when requested
              FeatureParams.create(:feature=>self, :param=>prow, :value=>pvmap[pn]) if command == "ADD"
            end<commit_msg>The command parameter to Feature::ModifyParams is case-insensitive now.<commit_after>require 'spqr/spqr'
require 'rhubarb/rhubarb'
require 'mrg/grid/config/Subsystem'
require 'mrg/grid/config/Parameter'
require 'mrg/grid/config/ArcLabel'
require 'mrg/grid/config/ArcUtils'
require 'mrg/grid/config/QmfUtils'

require 'set'

module Mrg
  module Grid
    module Config
      class Feature
        include ::Rhubarb::Persisting
        include ::SPQR::Manageable

        qmf_package_name 'mrg.grid.config'
        qmf_class_name 'Feature'
        ### Property method declarations
        # property uid uint32 

        declare_column :name, :string
        declare_index_on :name
        
        def uid
          @row_id
        end
        
        def Feature.find_by_uid(u)
          find(u)
        end
        
        qmf_property :uid, :uint32, :index=>true
        ### Schema method declarations
        
        # GetName 
        # * name (sstr/O)
        def GetName()
          log.debug "GetName called on feature #{self.inspect}"
          # Assign values to output parameters
          return self.name
        end
        
        expose :GetName do |args|
          args.declare :name, :sstr, :out, {}
        end
        
        # SetName 
        # * name (sstr/I)
        def SetName(name)
          # Print values of input parameters
          log.debug "SetName: name => #{name}"
          raise "Feature name #{name} is taken" if (self.name != name and Feature.find_first_by_name(name))
          self.name = name
        end
        
        expose :SetName do |args|
          args.declare :name, :sstr, :in, {}
        end
        
        # GetFeatures 
        # * list (map/O)
        #   list of other features a feature includes
        def GetFeatures()
          log.debug "GetFeatures called on feature #{self.inspect}"
          # Assign values to output parameters
          list ||= {}
          log.warn "GetFeatures() is not implemented"
          # Return value
          return list
        end
        
        expose :GetFeatures do |args|
          args.declare :list, :map, :out, {}
        end
        
        # ModifyFeatures 
        # * command (sstr/I)
        #   Valid commands are 'ADD', 'REMOVE', and 'REPLACE'.
        # * features (map/I)
        #   A list of other features a feature includes
        def ModifyFeatures(command,features,options={})
          # Print values of input parameters
          log.debug "ModifyFeatures: command => #{command}"
          log.debug "ModifyFeatures: features => #{features}"
        end
        
        expose :ModifyFeatures do |args|
          args.declare :command, :sstr, :in, {}
          args.declare :features, :map, :in, {}
          args.declare :options, :map, :in, {}
        end
        
        # GetParams 
        # * list (map/O)
        #   A map(paramName, value) of parameters and their corresponding values that is specific to a group
        def GetParams()
          log.debug "GetParams called on feature #{self.inspect}"
          Hash[*FeatureParams.find_by(:feature=>self).map {|fp| [fp.param.name, fp.value]}.flatten]
        end
        
        expose :GetParams do |args|
          args.declare :list, :map, :out, {}
        end
        
        def GetParamsAsString
          log.debug "GetParamsAsString called on feature #{self.inspect}"
          hash = self.GetParams
          "{"+hash.map{|pair| "#{pair[0].inspect}:#{pair[1].inspect}"}.join(",")+"}"
        end
        
        expose :GetParamsAsString do |args|
          args.declare :params, :lstr, :out, {}
        end
        
        def AddParamMapping(param,value)
          log.debug "AddParam:  param => #{param}"
          log.debug "AddParam:  value => #{value}"
          
          self.ModifyParams("ADD", {param=>value})
        end

        expose :AddParamMapping do |args|
          args.declare :param, :sstr, :in, {}
          args.declare :value, :sstr, :in, {}
        end

        def RemoveParamMapping(param)
          log.debug "RemoveParam:  param => #{param}"
          
          self.ModifyParams("REMOVE", {param=>true})
        end

        expose :RemoveParamMapping do |args|
          args.declare :param, :sstr, :in, {}
        end
        
        def ClearParams
          log.debug "ClearParams called on feature #{self.inspect}"
          self.ModifyParams("REPLACE", {})
          0
        end
        
        expose :ClearParams do |args|
          args.declare :ret, :int, :out, {}
        end
        
        # ModifyParams 
        # * command (sstr/I)
        #   Valid commands are 'ADD', 'REMOVE', and 'REPLACE'.
        # * params (map/I)
        #   A map(paramName, value) of parameters and their corresponding values that is specific to a group
        def ModifyParams(command,pvmap,options={})
          # Print values of input parameters
          log.debug "ModifyParams: command => #{command}"
          log.debug "ModifyParams: params => #{pvmap}"
          
          pvmap ||= {}
          
          params = pvmap.keys.map do |pn|
            prow = Parameter.find_first_by_name(pn)
            raise "invalid parameter #{pn}" unless prow
            prow
          end
          
          case command.upcase
          when "ADD", "REMOVE" then
            params.each do |prow|
              pn = prow.name

              # Delete any prior mappings for each supplied param in either case
              FeatureParams.find_by(:feature=>self, :param=>prow).map {|fp| fp.delete}
              
              # Add new mappings when requested
              FeatureParams.create(:feature=>self, :param=>prow, :value=>pvmap[pn]) if command.upcase == "ADD"
            end
{'fraction_non_alphanumeric': 0.10646521433591005, 'fraction_numerical': 0.001229796205200281, 'mean_word_length': 1.7171837708830548, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 37, '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': '6487199', 'n_tokens_mistral': 3235, 'n_tokens_neox': 3186, 'n_words': 886}