Class: SuffixTreeDB

Inherits:
Object
  • Object
show all
Defined in:
lib/persist/suffix_tree_db.rb

Instance Method Summary collapse

Constructor Details

#initialize(textFile) ⇒ SuffixTreeDB

Returns a new instance of SuffixTreeDB.



4
5
6
7
8
# File 'lib/persist/suffix_tree_db.rb', line 4

def initialize(textFile)
  @textFile = File.open(textFile, "w")
  @dataValues = []
  @dataValueIdx = 0
end

Instance Method Details

#persist(node) ⇒ Object



18
19
20
21
22
23
24
25
26
# File 'lib/persist/suffix_tree_db.rb', line 18

def persist(node)
  @textFile.print "#{node.nodeId} #{val(node.parent)} #{node.incomingEdgeStartOffset} #{node.incomingEdgeEndOffset} #{node.suffixOffset} #{val(node.suffixLink)}"
  if (node.children != nil) then
    node.children.values.each do |childNode|
      @textFile.print " #{childNode.nodeId}"
    end
  end
  @textFile.print " 0\n"
end

#readIntObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/persist/suffix_tree_db.rb', line 28

def readInt()
  if (@dataValueIdx >= @dataValues.length) then
    if (@textFile.eof?) then
      return 0
    end
    line = @textFile.readline()
    if (line == nil) then
      return 0
    else
      line.chomp!
      @dataValueIdx = 0
      @dataValues = line.split
    end
  end

  result = @dataValues[@dataValueIdx].to_i
  @dataValueIdx += 1
  return result
end

#val(node) ⇒ Object



10
11
12
13
14
15
16
# File 'lib/persist/suffix_tree_db.rb', line 10

def val(node)
  if (node == nil) then
    return 0
  else
    return node.nodeId
  end
end