Class: SFST::RegularTransducer
- Inherits:
-
Object
- Object
- SFST::RegularTransducer
- Defined in:
- lib/sfst.rb
Overview
A regular, i.e. not a compact, transducer.
Instance Method Summary collapse
-
#accepted_analysis?(string) ⇒ Boolean
Checks if the string
string
is accepted for analysis. -
#accepted_generating?(string) ⇒ Boolean
Checks if the string
string
is accepted for generating. -
#analyze(string, options = {}) ⇒ Object
(also: #analyse)
Analyses a string
string
. -
#generate(string) ⇒ Object
Generates a string
string
. -
#generate_language(options = {}, &block) ⇒ Object
Generates upper or lower level or both.
-
#initialize(file) ⇒ RegularTransducer
constructor
A new instance of RegularTransducer.
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.
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.
61 62 63 |
# File 'lib/sfst.rb', line 61 def (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, = {}) x = [] @fst._analyze(string) do |a| if [: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
- iftrue
, produces epsilons. Default isfalse
.
72 73 74 |
# File 'lib/sfst.rb', line 72 def generate_language( = {}, &block) @fst._generate_language([:levels] || :both, [:epsilons] ? :all : :noepsilons, &block) end |