class FpGrowth::Miner::PatternBaseExtractor

Public Class Methods

new(tree=FpTree::FpTree.new() , item) click to toggle source
# File lib/fpgrowth/miner/pattern_base_extractor.rb, line 8
def initialize(tree=FpTree::FpTree.new() , item)
  @tree = tree
  @horizontal_cursor = tree.heads[item]
  @conditional_item = item
  @patterns=[]
end

Public Instance Methods

down_to_top_traversal(current_branch=@current_branch, vertical_cursor=@vertical_cursor) click to toggle source

Method accountable of reading the upper part of the branch

Each step, it makes a new node with the same item, but with minimum support Then the new node is added to a list Finally, the list is reversed

# File lib/fpgrowth/miner/pattern_base_extractor.rb, line 52
def down_to_top_traversal(current_branch=@current_branch, vertical_cursor=@vertical_cursor)
  @vertical_cursor = vertical_cursor
  while @vertical_cursor != nil and @vertical_cursor.item != nil
    down_to_top_traversal_step(current_branch)
    @vertical_cursor = @vertical_cursor.parent
  end
  current_branch.reverse!
end
down_to_top_traversal_step(current_branch=@current_branch, vertical_cursor=@vertical_cursor) click to toggle source

Method wich represent a step of the vertical down_to_top_traversal

It just gather items

# File lib/fpgrowth/miner/pattern_base_extractor.rb, line 65
def down_to_top_traversal_step(current_branch=@current_branch, vertical_cursor=@vertical_cursor)
  current_branch << vertical_cursor.item
end
execute() click to toggle source
# File lib/fpgrowth/miner/pattern_base_extractor.rb, line 15
def execute()
  horizontal_traversal()
  return @patterns
end
horizontal_traversal(horizontal_cursor=@horizontal_cursor) click to toggle source

Method accountable of horizontal tree traversal

# File lib/fpgrowth/miner/pattern_base_extractor.rb, line 22
def horizontal_traversal(horizontal_cursor=@horizontal_cursor)
  @horizontal_cursor=horizontal_cursor
  while @horizontal_cursor != nil
    horizontal_traversal_step()
    @horizontal_cursor = @horizontal_cursor.lateral
  end
end
horizontal_traversal_step(horizontal_cursor=@horizontal_cursor) click to toggle source

Method accountable of treating each branch

Make a copy of the item branch and append it to tree

To achieve it, it make a list of the upper nodes Then build a Pattern

# File lib/fpgrowth/miner/pattern_base_extractor.rb, line 37
def horizontal_traversal_step(horizontal_cursor=@horizontal_cursor)
  @min_support = horizontal_cursor.support
  @current_branch = []
  @vertical_cursor = horizontal_cursor.parent
  @current_branch = down_to_top_traversal()
  @patterns << Pattern.new(@current_branch, @min_support)
end
test_conditionnal_item(item ) click to toggle source

fonction qui sert uniquement pour les tests

# File lib/fpgrowth/miner/pattern_base_extractor.rb, line 71
def test_conditionnal_item(item )
  if   item == @conditional_item
  then  return true
  end
  return false
end
test_current_branch(current_branch) click to toggle source
# File lib/fpgrowth/miner/pattern_base_extractor.rb, line 99
def test_current_branch (current_branch)
  if current_branch  == @current_branch
  then  return true
  end
  return false
end
test_min_support( min_support ) click to toggle source
# File lib/fpgrowth/miner/pattern_base_extractor.rb, line 92
def test_min_support( min_support )
  if  min_support == @min_support
  then  return true
  end
  return false
end
test_patterns(patterns = []) click to toggle source
# File lib/fpgrowth/miner/pattern_base_extractor.rb, line 78
def test_patterns(patterns = [])
  if  patterns == @patterns
  then  return true
  end
  return false
end
test_tree(tree = FpTree::FpTree.new() ) click to toggle source
# File lib/fpgrowth/miner/pattern_base_extractor.rb, line 85
def test_tree(tree = FpTree::FpTree.new() )
  if  tree.threshold == @tree.threshold and tree.root == @tree.root
  then  return true
  end
  return false
end
vertical_cursor(vertical_cursor) click to toggle source
# File lib/fpgrowth/miner/pattern_base_extractor.rb, line 106
def vertical_cursor (vertical_cursor)
  if vertical_cursor  == @vertical_cursor
  then  return true
  end
  return false
end