Class: SFST::RegularTransducer

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

Overview

A regular, i.e. not a compact, transducer.

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ RegularTransducer

Returns a new instance of RegularTransducer


25
26
27
# File 'lib/sfst.rb', line 25

def initialize(file)
  @fst = RegularTransducerMachine.new(file)
end

Instance Method Details

#accepted_analysis?(string) ⇒ Boolean

Checks if the string string is accepted for analysis.

Returns:

  • (Boolean)

48
49
50
# File 'lib/sfst.rb', line 48

def accepted_analysis?(string)
  @fst._analyze(string)
end

#accepted_generating?(string) ⇒ Boolean

Checks if the string string is accepted for generating.

Returns:

  • (Boolean)

61
62
63
# File 'lib/sfst.rb', line 61

def accepted_generating?(string)
  @fst._generate(string)
end

#analyze(string, options = {}) ⇒ Object Also known as: analyse

Analyses a string string. Returns an array of analysed strings if the string is accepted, or an empty array if not.

Options

  • symbol_sequence - Return each analysis as a sequence of symbols. Multicharacter symbols will be strings on the form <symbol>.


35
36
37
38
39
40
41
42
43
44
45
# File 'lib/sfst.rb', line 35

def analyze(string, options = {})
  x = []
  @fst._analyze(string) do |a| 
    if options[:symbol_sequence]
      x << a.map { |s| s.match(/^<(.*)>$/) ? $1.to_sym : s }
    else
      x << a.join
    end
  end
  x
end

#generate(string) ⇒ Object

Generates a string string. Returns an array of generated strings if the string is accepted or an empty array if not.


54
55
56
57
58
# File 'lib/sfst.rb', line 54

def generate(string)
  x = []
  @fst._generate(string) { |a| x << a.join }
  x
end

#generate_language(options = {}, &block) ⇒ Object

Generates upper or lower level or both. This only works with non-compact transducers.

Options

  • levels - if :upper, generates only upper level. If :lower generates only lower level. If :both, generates both. Default is :both.

  • epsilons - if true, produces epsilons. Default is false.


72
73
74
# File 'lib/sfst.rb', line 72

def generate_language(options = {}, &block)
  @fst._generate_language(options[:levels] || :both, options[:epsilons] ? :all : :noepsilons, &block)
end