class FuzzyWhere::PredicateMembershipDegree
Class to determine the membership degree calculation for a given column and add the select conditions
Attributes
calculation[R]
@!attribute [r] calculation
@return [String] calculation query to be used for the given column
Public Class Methods
new(table, column, fuzzy_predicate)
click to toggle source
New MembershipDegree intance @param table [String] table name @param column [String] column name @param fuzzy_predicate [Hash] fuzzy predicate
# File lib/fuzzy_where/predicate_membership_degree.rb, line 14 def initialize(table, column, fuzzy_predicate) @table = table @column = column @fuzzy_predicate = fuzzy_predicate end
Public Instance Methods
membership_function()
click to toggle source
Take instance attributes and return a calculations for them Based on fuzzy set trapezium function @return [String] the calculation query to be used for the column
# File lib/fuzzy_where/predicate_membership_degree.rb, line 23 def membership_function min = @fuzzy_predicate[:min] max = @fuzzy_predicate[:max] @calculation = if !min || min == 'infinite'.freeze decreasing elsif !max || max == 'infinite'.freeze increasing else unimodal end @calculation end
Private Instance Methods
comparator_condition(x, comparator)
click to toggle source
# File lib/fuzzy_where/predicate_membership_degree.rb, line 75 def comparator_condition(x, comparator) "#{@table}.#{@column} #{comparator} #{@fuzzy_predicate[x].to_f}" end
decreasing()
click to toggle source
Decreasing function calculation @return [String] condition representation for membership calculation
# File lib/fuzzy_where/predicate_membership_degree.rb, line 40 def decreasing "CASE WHEN #{less_than(:core2, true)} THEN 1.0 "\ "WHEN #{greater_than(:core2)} AND #{less_than(:max)} THEN "\ "(#{right_border_formula}) ELSE 0 END" end
greater_than(x, equal = false)
click to toggle source
# File lib/fuzzy_where/predicate_membership_degree.rb, line 65 def greater_than(x, equal = false) comparator = equal ? '>='.freeze : '>'.freeze comparator_condition(x, comparator) end
increasing()
click to toggle source
Increasing function calculation @return [String] condition representation for membership calculation
# File lib/fuzzy_where/predicate_membership_degree.rb, line 48 def increasing "CASE WHEN #{greater_than(:core1, true)} THEN 1.0 "\ "WHEN #{greater_than(:min)} AND #{less_than(:core1)} THEN "\ "(#{left_border_formula}) ELSE 0 END" end
left_border_formula()
click to toggle source
# File lib/fuzzy_where/predicate_membership_degree.rb, line 84 def left_border_formula "#{@table}.#{@column} - #{@fuzzy_predicate[:min].to_f})/"\ "(#{@fuzzy_predicate[:core1].to_f} - #{@fuzzy_predicate[:min].to_f}" end
less_than(x, equal = false)
click to toggle source
# File lib/fuzzy_where/predicate_membership_degree.rb, line 70 def less_than(x, equal = false) comparator = equal ? '<='.freeze : '<'.freeze comparator_condition(x, comparator) end
right_border_formula()
click to toggle source
# File lib/fuzzy_where/predicate_membership_degree.rb, line 79 def right_border_formula "#{@fuzzy_predicate[:max].to_f} - #{@table}.#{@column})/"\ "(#{@fuzzy_predicate[:max].to_f} - #{@fuzzy_predicate[:core2].to_f}" end
unimodal()
click to toggle source
Unimodal function calculation @return [String] condition representation for membership calculation
# File lib/fuzzy_where/predicate_membership_degree.rb, line 56 def unimodal 'CASE WHEN '\ "#{greater_than(:core1, true)} AND #{less_than(:core2, true)} THEN 1.0 "\ "WHEN #{greater_than(:min)} AND #{less_than(:core1)} THEN "\ "(#{left_border_formula})"\ "WHEN #{greater_than(:core2)} AND #{less_than(:max)} THEN "\ "(#{right_border_formula}) ELSE 0 END" end