65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
# File 'lib/bparity/formal/lts.rb', line 65
def learn(records)
usable = records.select { |record| record.key?("pre_state") && record.key?("post_state") }
if usable.empty?
raise ConfigurationError,
"The corpus has no state projections. Add a state block to the boundary."
end
labels = usable.flat_map { |record| [state_label(record["pre_state"]), state_label(record["post_state"])] }.uniq
names = labels.sort.each_with_index.to_h { |label, index| [label, "s#{index}"] }
transitions = usable.map do |record|
Transition.new(from: names.fetch(state_label(record["pre_state"])), input: record.fetch("operation"),
output: output_label(record.fetch("outcome")),
to: names.fetch(state_label(record["post_state"])))
end.uniq(&:to_h)
LTS.new(initial: names.fetch(state_label(usable.first["pre_state"])), transitions:)
end
|