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.



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

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)


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

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

#accepted_generating?(string) ⇒ Boolean

Checks if the string string is accepted for generating.

Returns:

  • (Boolean)


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

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>.



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

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.



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

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.



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

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