Class: Stamina::RegLang::CanonicalInfo
- Inherits:
-
Object
- Object
- Stamina::RegLang::CanonicalInfo
- Defined in:
- lib/stamina-induction/stamina/reg_lang/canonical_info.rb
Defined Under Namespace
Classes: ShortPrefixes
Instance Attribute Summary collapse
-
#cdfa ⇒ Object
readonly
Returns the value of attribute cdfa.
Instance Method Summary collapse
-
#characteristic_sample ⇒ Object
Builds a characteristic sample.
-
#initialize(lang) ⇒ CanonicalInfo
constructor
A new instance of CanonicalInfo.
-
#kernel ⇒ Object
Returns the language kernel as a sample.
-
#negative_suffix(state) ⇒ Object
Returns a negative suffix for ‘state`.
-
#positive_suffix(state) ⇒ Object
Returns a positive suffix for ‘state`.
-
#short_prefix(s_or_e) ⇒ Object
Returns the short prefix of a state or an edge.
-
#short_prefixes ⇒ Object
Returns the short prefixes of the language as a sample.
Constructor Details
#initialize(lang) ⇒ CanonicalInfo
Returns a new instance of CanonicalInfo.
26 27 28 |
# File 'lib/stamina-induction/stamina/reg_lang/canonical_info.rb', line 26 def initialize(lang) @cdfa = lang.to_cdfa end |
Instance Attribute Details
#cdfa ⇒ Object (readonly)
Returns the value of attribute cdfa.
24 25 26 |
# File 'lib/stamina-induction/stamina/reg_lang/canonical_info.rb', line 24 def cdfa @cdfa end |
Instance Method Details
#characteristic_sample ⇒ Object
Builds a characteristic sample
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/stamina-induction/stamina/reg_lang/canonical_info.rb', line 74 def characteristic_sample sample = Sample.new # at least one positive string should be found from # the initial state if pos = positive_suffix(cdfa.initial_state) sample << InputString.new(pos, true) else sample << InputString.new([], false) return sample end # condition 1: positive string for each element of the kernel cdfa.each_edge do |edge| pos = short_prefix(edge) + positive_suffix(edge.target) sample << InputString.new(pos, true, false) end # condition 2: pair-wise distinguising suffixes cdfa.each_state do |source| cdfa.each_edge do |edge| next if (target = edge.target) == source if suffix = distinguish(source, target) sign = cdfa.accepts?(suffix, source) sample << InputString.new(short_prefix(source) + suffix, sign) sample << InputString.new(short_prefix(edge) + suffix, !sign) end end end sample end |
#kernel ⇒ Object
Returns the language kernel as a sample
62 63 64 65 66 67 68 69 |
# File 'lib/stamina-induction/stamina/reg_lang/canonical_info.rb', line 62 def kernel kernel = Sample.new kernel << InputString.new([], cdfa.initial_state.accepting?) cdfa.each_edge do |e| kernel << InputString.new(short_prefix(e), e.target.accepting?) end kernel end |
#negative_suffix(state) ⇒ Object
Returns a negative suffix for ‘state`
44 45 46 |
# File 'lib/stamina-induction/stamina/reg_lang/canonical_info.rb', line 44 def negative_suffix(state) state[:negative_suffix] ||= find_suffix(state, false) end |
#positive_suffix(state) ⇒ Object
Returns a positive suffix for ‘state`
39 40 41 |
# File 'lib/stamina-induction/stamina/reg_lang/canonical_info.rb', line 39 def positive_suffix(state) state[:positive_suffix] ||= find_suffix(state, true) end |
#short_prefix(s_or_e) ⇒ Object
Returns the short prefix of a state or an edge.
31 32 33 34 35 36 |
# File 'lib/stamina-induction/stamina/reg_lang/canonical_info.rb', line 31 def short_prefix(s_or_e) prefixes! s_or_e[:short_prefix] ||= begin s_or_e.source[:short_prefix] + [s_or_e.symbol] end end |
#short_prefixes ⇒ Object
Returns the short prefixes of the language as a sample
51 52 53 54 55 56 57 |
# File 'lib/stamina-induction/stamina/reg_lang/canonical_info.rb', line 51 def short_prefixes prefixes = Sample.new cdfa.each_state do |s| prefixes << InputString.new(short_prefix(s), s.accepting?) end prefixes end |