Class: FuzzyWhere::PredicateMembershipDegree

Inherits:
Object
  • Object
show all
Defined in:
lib/fuzzy_where/predicate_membership_degree.rb

Overview

Class to determine the membership degree calculation for a given column and add the select conditions

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(table, column, fuzzy_predicate) ⇒ PredicateMembershipDegree

New MembershipDegree intance

Parameters:

  • table (String)

    table name

  • column (String)

    column name

  • fuzzy_predicate (Hash)

    fuzzy predicate



14
15
16
17
18
# 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

Instance Attribute Details

#calculationObject (readonly)

Returns the value of attribute calculation.



8
9
10
# File 'lib/fuzzy_where/predicate_membership_degree.rb', line 8

def calculation
  @calculation
end

Instance Method Details

#membership_functionString

Take instance attributes and return a calculations for them Based on fuzzy set trapezium function

Returns:

  • (String)

    the calculation query to be used for the column



23
24
25
26
27
28
29
30
31
32
33
34
# 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