class TSS::Vertex
Trie
vertex class
Attributes
Letter representing this vertex
Array of children TSS::Vertex
references for nested models(full trie, Aho-Corasick trie) or as list of nested vertexes of root vertex of flat trie
Array of indexes of word in dictionary Empty if it is intermediate TSS::Vertex
in chain
Array of TSS::Vertex
links for flat trie model, also used as suffixes of Aho-Corasick trie
Reference to the parent TSS::Vertex
Reference to the root vertex of the trie
Public Class Methods
Initializes new vertex
-
parent
is parentTSS::Vertex
Example:
>> TSS::Vertex.new(@root_vertex) >> TSS::Vertex.new(@root_vertex)
Optional arguments:
parent: (TSS::Vertex)
# File lib/tss/vertex.rb, line 35 def initialize(parent = nil) @char = nil @parent = parent @children = [] @links = [] @end_indexes = [] yield(self) if block_given? end
Public Instance Methods
Initializes new TSS::Vertex
and adds it to the parent attribute
# File lib/tss/vertex.rb, line 46 def add_child(char, end_index) child = get_child(char) if child child.end_indexes << end_index unless end_index.nil? child else init_subchild(char, end_index) end end
Adds reference to the linked vertexes
# File lib/tss/vertex.rb, line 64 def add_link(vertex, end_index = nil) @links << TSS::Link.new(vertex, end_index) end
Returns array of characters from array of children TSS::Vertex
# File lib/tss/vertex.rb, line 76 def children_chars @children.map(&:char) end
Returns child TSS::Vertex
by letter, from children attribute
# File lib/tss/vertex.rb, line 58 def get_child(char) @children.find { |c| c.char == char } end
Returns link by character
# File lib/tss/vertex.rb, line 70 def get_link(char) @links.find { |l| l.char == char } end
# File lib/tss/vertex.rb, line 80 def vertex self end
Private Instance Methods
# File lib/tss/vertex.rb, line 86 def init_subchild(char, end_index) child = self.class.new(self) child.char = char child.root = @root child.end_indexes << end_index unless end_index.nil? @children << child child end