Module: Sequitur

Defined in:
lib/sequitur/digram.rb,
lib/sequitur.rb,
lib/sequitur/constants.rb,
lib/sequitur/production.rb,
lib/sequitur/dynamic_grammar.rb,
lib/sequitur/sequitur_grammar.rb

Overview

Module for classes implementing the Sequitur algorithm

Defined Under Namespace

Classes: Digram, DynamicGrammar, Production, SequiturGrammar

Constant Summary collapse

Version =

The version number of the gem.

'0.0.11'
Description =

Brief description of the gem.

'Ruby implementation of the Sequitur algorithm'
RootDir =

The root folder of Sequitur.

begin
  require 'pathname' # Load Pathname class from standard library
  rootdir = Pathname(__FILE__).dirname.parent.parent.expand_path
  rootdir.to_s + '/' # Append trailing slash character to it
end

Class Method Summary collapse

Class Method Details

.build_from(tokens) ⇒ Object

Convenience method. Builds a Sequitur-generated grammar based on the sequence of input tokens Can be a sequence of characters (i.e. a String) or an Enumerator Tokens returned by enumerator should respond to the :hash message. Returns a SequiturGrammar instance.

Parameters:

  • The input sequence of input tokens.



17
18
19
20
21
22
23
24
25
# File 'lib/sequitur.rb', line 17

def self.build_from(tokens)
  input_sequence = case tokens
    when String then tokens.chars
    when Enumerator then tokens
    else tokens.to_enum
  end
  
  return SequiturGrammar.new(input_sequence)
end