rlsm 0.2.4 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.txt +0 -0
- data/Manifest.txt +3 -28
- data/README.txt +0 -0
- data/Rakefile +0 -0
- data/bin/smon +1 -3
- data/lib/data/monoids.db +0 -0
- data/lib/dfa.rb +656 -0
- data/lib/monoid.rb +778 -0
- data/lib/re.rb +492 -0
- data/lib/rlsm.rb +57 -36
- metadata +5 -30
- data/lib/rlsm/dfa.rb +0 -705
- data/lib/rlsm/exceptions.rb +0 -39
- data/lib/rlsm/mgen.rb +0 -138
- data/lib/rlsm/monkey_patching.rb +0 -126
- data/lib/rlsm/monoid.rb +0 -552
- data/lib/rlsm/monoid_db.rb +0 -123
- data/lib/rlsm/regexp.rb +0 -229
- data/lib/rlsm/regexp_nodes/concat.rb +0 -112
- data/lib/rlsm/regexp_nodes/primexp.rb +0 -49
- data/lib/rlsm/regexp_nodes/renodes.rb +0 -95
- data/lib/rlsm/regexp_nodes/star.rb +0 -50
- data/lib/rlsm/regexp_nodes/union.rb +0 -85
- data/lib/smon/commands/db_find.rb +0 -37
- data/lib/smon/commands/db_stat.rb +0 -20
- data/lib/smon/commands/exit.rb +0 -9
- data/lib/smon/commands/help.rb +0 -31
- data/lib/smon/commands/intro.rb +0 -32
- data/lib/smon/commands/monoid.rb +0 -27
- data/lib/smon/commands/quit.rb +0 -10
- data/lib/smon/commands/regexp.rb +0 -20
- data/lib/smon/commands/reload.rb +0 -22
- data/lib/smon/commands/show.rb +0 -21
- data/lib/smon/presenter.rb +0 -18
- data/lib/smon/presenter/txt_presenter.rb +0 -157
- data/lib/smon/smon.rb +0 -79
- data/test/dfa_spec.rb +0 -99
- data/test/monoid_spec.rb +0 -270
- data/test/regexp_spec.rb +0 -25
@@ -1,49 +0,0 @@
|
|
1
|
-
module RLSM::RENodes
|
2
|
-
private
|
3
|
-
class PrimExp
|
4
|
-
def initialize(parent, str)
|
5
|
-
@parent = parent
|
6
|
-
if str == '&' or str == ['&']
|
7
|
-
@content = '&'
|
8
|
-
@null = true
|
9
|
-
else
|
10
|
-
@content = str.reject { |c| c == '&' }
|
11
|
-
@null = false
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
def null?
|
16
|
-
@null
|
17
|
-
end
|
18
|
-
|
19
|
-
def first
|
20
|
-
@null ? [] : @content[0,1]
|
21
|
-
end
|
22
|
-
|
23
|
-
def last
|
24
|
-
@null ? [] : @content[-1,1]
|
25
|
-
end
|
26
|
-
|
27
|
-
def follow
|
28
|
-
res = []
|
29
|
-
|
30
|
-
(1...@content.length).each do |i|
|
31
|
-
res << [@content[i-1,1], @content[i,1]]
|
32
|
-
end
|
33
|
-
|
34
|
-
res
|
35
|
-
end
|
36
|
-
|
37
|
-
def to_s
|
38
|
-
@content.to_s
|
39
|
-
end
|
40
|
-
|
41
|
-
def lambda?
|
42
|
-
@null
|
43
|
-
end
|
44
|
-
|
45
|
-
def empty?
|
46
|
-
@content == '' or @content == []
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
@@ -1,95 +0,0 @@
|
|
1
|
-
|
2
|
-
#Monkey Patching the RLSM constant.
|
3
|
-
module RLSM
|
4
|
-
end
|
5
|
-
|
6
|
-
#Loading the node types
|
7
|
-
require File.join(File.dirname(__FILE__), "primexp")
|
8
|
-
require File.join(File.dirname(__FILE__), "star")
|
9
|
-
require File.join(File.dirname(__FILE__), "union")
|
10
|
-
require File.join(File.dirname(__FILE__), "concat")
|
11
|
-
|
12
|
-
module RLSM::RENodes
|
13
|
-
|
14
|
-
#Simplifiying the counting of parenthesis
|
15
|
-
PCount = Hash.new(0)
|
16
|
-
PCount['('] = 1
|
17
|
-
PCount[')'] = -1
|
18
|
-
|
19
|
-
#Creates a new tree for the given description +desc+ and parent node +parent+
|
20
|
-
def self.new(desc, parent=nil)
|
21
|
-
#Convert a string description to an array
|
22
|
-
desc = desc.scan(/./m) if desc.class == String
|
23
|
-
|
24
|
-
##Some a priori simplifications
|
25
|
-
#Removing surrounding parentheses
|
26
|
-
desc = desc[(1..-2)] while sp?(desc)
|
27
|
-
|
28
|
-
#Squeezing repeated *'s and &'s and *&'s and &*'s
|
29
|
-
#This is required only once, so if the parent isn't nil, there should be no need to do this again.
|
30
|
-
unless parent
|
31
|
-
desc = desc.inject([]) do |res,char|
|
32
|
-
[char,res.last].all? { |c| ['*', '&'].include? c } ? res : res + [char]
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
##Determine the correct node type and return it
|
37
|
-
if prim?(desc)
|
38
|
-
return PrimExp.new(parent, desc)
|
39
|
-
elsif star?(desc)
|
40
|
-
return Star.new(parent, desc)
|
41
|
-
elsif union?(desc)
|
42
|
-
return Union.new(parent,desc)
|
43
|
-
else
|
44
|
-
return Concat.new(parent,desc)
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
def self.sp?(desc)
|
49
|
-
if desc[0,1].include? '(' and desc[-1,1].include? ')'
|
50
|
-
state = 0
|
51
|
-
l = 0
|
52
|
-
#count = Hash.new(0)
|
53
|
-
#count['('] = 1
|
54
|
-
#count[')'] = -1
|
55
|
-
|
56
|
-
desc.each_char do |c|
|
57
|
-
state += PCount[c]
|
58
|
-
l += 1
|
59
|
-
break if state == 0
|
60
|
-
end
|
61
|
-
|
62
|
-
return true if desc.length == l
|
63
|
-
end
|
64
|
-
|
65
|
-
false
|
66
|
-
end
|
67
|
-
|
68
|
-
def self.prim?(desc)
|
69
|
-
not ['(', ')', '|', '*'].any? { |c| desc.include? c }
|
70
|
-
end
|
71
|
-
|
72
|
-
def self.star?(desc)
|
73
|
-
if desc[-1,1].include? '*'
|
74
|
-
return true if sp?(desc[(0..-2)]) #something like (....)*
|
75
|
-
return true if desc.length == 2 #something like a*
|
76
|
-
end
|
77
|
-
|
78
|
-
false
|
79
|
-
end
|
80
|
-
|
81
|
-
def self.union?(desc)
|
82
|
-
state = 0
|
83
|
-
#count = Hash.new(0)
|
84
|
-
#count['('] = 1
|
85
|
-
#count[')'] = -1
|
86
|
-
|
87
|
-
desc.each_char do |c|
|
88
|
-
state += PCount[c]
|
89
|
-
|
90
|
-
return true if c == '|' and state == 0
|
91
|
-
end
|
92
|
-
|
93
|
-
false
|
94
|
-
end
|
95
|
-
end
|
@@ -1,50 +0,0 @@
|
|
1
|
-
module RLSM::RENodes
|
2
|
-
private
|
3
|
-
class Star
|
4
|
-
def initialize(parent, str)
|
5
|
-
@parent = parent
|
6
|
-
@child = RLSM::RENodes.new(str[(0..-2)], self)
|
7
|
-
end
|
8
|
-
|
9
|
-
def null?
|
10
|
-
true
|
11
|
-
end
|
12
|
-
|
13
|
-
def first
|
14
|
-
@child.first
|
15
|
-
end
|
16
|
-
|
17
|
-
def last
|
18
|
-
@child.last
|
19
|
-
end
|
20
|
-
|
21
|
-
def follow
|
22
|
-
res = @child.follow
|
23
|
-
|
24
|
-
#Cross of last and first
|
25
|
-
first.each do |f|
|
26
|
-
last.each do |l|
|
27
|
-
res << [l,f]
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
res
|
32
|
-
end
|
33
|
-
|
34
|
-
def to_s
|
35
|
-
if @child.class == PrimExp and @child.to_s.length == 1
|
36
|
-
return "#{@child.to_s}*"
|
37
|
-
else
|
38
|
-
return "(#{@child.to_s})*"
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
def lambda?
|
43
|
-
false
|
44
|
-
end
|
45
|
-
|
46
|
-
def empty?
|
47
|
-
false
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
@@ -1,85 +0,0 @@
|
|
1
|
-
module RLSM::RENodes
|
2
|
-
private
|
3
|
-
class Union
|
4
|
-
def initialize(parent, str)
|
5
|
-
@parent = parent
|
6
|
-
@childs = _split(str).map do |substr|
|
7
|
-
RLSM::RENodes.new(substr,self)
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
def null?
|
12
|
-
@childs.any? { |child| child.null? }
|
13
|
-
end
|
14
|
-
|
15
|
-
def first
|
16
|
-
res = []
|
17
|
-
@childs.each do |child|
|
18
|
-
child.first.each do |f|
|
19
|
-
res << f
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
res
|
24
|
-
end
|
25
|
-
|
26
|
-
def last
|
27
|
-
res = []
|
28
|
-
@childs.each do |child|
|
29
|
-
child.last.each do |l|
|
30
|
-
res << l
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
res
|
35
|
-
end
|
36
|
-
|
37
|
-
def follow
|
38
|
-
res = []
|
39
|
-
@childs.each do |child|
|
40
|
-
child.follow.each do |f|
|
41
|
-
res << f
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
res
|
46
|
-
end
|
47
|
-
|
48
|
-
def to_s
|
49
|
-
if @parent.nil? or @parent.class == Union or @parent.class == Star
|
50
|
-
return @childs.map { |child| child.to_s }.join('|')
|
51
|
-
else
|
52
|
-
return '(' + @childs.map { |child| child.to_s }.join('|') + ')'
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
def lambda?
|
57
|
-
false
|
58
|
-
end
|
59
|
-
|
60
|
-
def empty?
|
61
|
-
false
|
62
|
-
end
|
63
|
-
|
64
|
-
private
|
65
|
-
def _split(str)
|
66
|
-
state = 0
|
67
|
-
count = Hash.new(0)
|
68
|
-
count['('] = 1
|
69
|
-
count[')'] = -1
|
70
|
-
|
71
|
-
res = [[]]
|
72
|
-
|
73
|
-
str.each_char do |c|
|
74
|
-
state += count[c]
|
75
|
-
if c == '|' and state == 0
|
76
|
-
res << []
|
77
|
-
else
|
78
|
-
res.last << c
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
res#.map { |substr| substr.join }
|
83
|
-
end
|
84
|
-
end
|
85
|
-
end
|
@@ -1,37 +0,0 @@
|
|
1
|
-
#category RLSM
|
2
|
-
=begin help
|
3
|
-
Returns monoids from the database.
|
4
|
-
|
5
|
-
Usage: db_find params
|
6
|
-
Here, params is a comma seperated list of property requests.
|
7
|
-
A property request has the form:
|
8
|
-
col => val
|
9
|
-
|
10
|
-
Known columns are:
|
11
|
-
- :binop -> the binary operation
|
12
|
-
- :m_order -> the order of the monoid
|
13
|
-
- :num_generators -> the size of the smallest generating subset
|
14
|
-
- :num_idempotents -> the number of idempotent elements
|
15
|
-
- :num_right_nulls -> the number of elements a with the property: xa = a for all x
|
16
|
-
- :num_left_nulls -> the number of elements a with the property: ax = a for all x
|
17
|
-
- :has_null -> 1 if the monoid has a null element, 0 otherwise
|
18
|
-
- :is_group -> 1 if the monoid is a group, 0 otherwise
|
19
|
-
- :syntactic -> 1 if the monoid is syntactic, 0 otherwise
|
20
|
-
- :commutative -> 1 if the monoid is commutative, 0 otherwise
|
21
|
-
- :idempotent -> 1 if the monoid is idempotent, 0 otherwise
|
22
|
-
- :aperiodic -> 1 if the monoid is aperiodic, 0 otherwise
|
23
|
-
- :l_trivial -> 1 if the monoid is L-trivial, 0 otherwise
|
24
|
-
- :r_trivial -> 1 if the monoid is R-trivial, 0 otherwise
|
25
|
-
- :d_trivial -> 1 if the monoid is D-trivial, 0 otherwise
|
26
|
-
|
27
|
-
The values are numbers except for the binop column.
|
28
|
-
|
29
|
-
Example:
|
30
|
-
db_find :m_order => 3
|
31
|
-
db_find :binop => '01 10'
|
32
|
-
db_find :syntactic => 1, :idempotent => 0
|
33
|
-
=end
|
34
|
-
|
35
|
-
def db_find(params = {})
|
36
|
-
RLSM::MonoidDB.find(params).flatten.map { |d| RLSM::Monoid.new d, :create_names => true }
|
37
|
-
end
|
@@ -1,20 +0,0 @@
|
|
1
|
-
#category RLSM
|
2
|
-
=begin help
|
3
|
-
Shows a small summery of the database.
|
4
|
-
|
5
|
-
Usage: db_stat
|
6
|
-
|
7
|
-
Prints out a small overview of the monoids in the database.
|
8
|
-
=end
|
9
|
-
|
10
|
-
def db_stat
|
11
|
-
res = RLSM::MonoidDB.statistic
|
12
|
-
|
13
|
-
res.each_with_index do |row,i|
|
14
|
-
if i == 0
|
15
|
-
puts row.map { |name| name[(0..4)] + '.' }.join("\t")
|
16
|
-
else
|
17
|
-
puts row.join("\t")
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
data/lib/smon/commands/exit.rb
DELETED
data/lib/smon/commands/help.rb
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
#category help
|
2
|
-
=begin help
|
3
|
-
Prints help topics.
|
4
|
-
|
5
|
-
Usage: help "command"
|
6
|
-
Prints the help topic for +command+.
|
7
|
-
The command name must be surrounded by " (double quote).
|
8
|
-
Example: help help -> prints this text.
|
9
|
-
|
10
|
-
=end
|
11
|
-
def help(cmd = nil)
|
12
|
-
if cmd.nil?
|
13
|
-
puts "Known Commands:"
|
14
|
-
Categories.each_pair do |cat, cmds|
|
15
|
-
puts " Category #{cat}"
|
16
|
-
cmds.each do |cmd|
|
17
|
-
puts " #{cmd} : #{(CmdHelp[cmd] || [cmd]).first}"
|
18
|
-
end
|
19
|
-
end
|
20
|
-
puts
|
21
|
-
puts 'Type help "command" for more information for "command"'
|
22
|
-
puts '(command must be surrounded by double quotes!)'
|
23
|
-
puts
|
24
|
-
else
|
25
|
-
if CmdHelp[cmd]
|
26
|
-
puts CmdHelp[cmd].join
|
27
|
-
else
|
28
|
-
puts " Nothing known about #{cmd}"
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
data/lib/smon/commands/intro.rb
DELETED
@@ -1,32 +0,0 @@
|
|
1
|
-
#category help
|
2
|
-
=begin help
|
3
|
-
Displays a small introduction.
|
4
|
-
|
5
|
-
Usage: intro
|
6
|
-
|
7
|
-
Shows some of the rules for work with the program.
|
8
|
-
=end
|
9
|
-
|
10
|
-
def intro
|
11
|
-
puts <<INTRO
|
12
|
-
======================
|
13
|
-
INTRODUCTION TO SMON
|
14
|
-
======================
|
15
|
-
|
16
|
-
==Basic rules
|
17
|
-
- Every input, which should be interpreted literally
|
18
|
-
must be surrounded by quotes or double quotes.
|
19
|
-
|
20
|
-
- Parenthesis for commands may be omitted in the most cases.
|
21
|
-
When in doubt, write the parenthesis.
|
22
|
-
|
23
|
-
- Basicly, every valid Ruby command is allowed.
|
24
|
-
|
25
|
-
==Basic Usage
|
26
|
-
- Type < help > for an overview of availible commands.
|
27
|
-
|
28
|
-
- If you wanna use variables, just type < @var = ... >.
|
29
|
-
The @-sign is important!
|
30
|
-
|
31
|
-
INTRO
|
32
|
-
end
|
data/lib/smon/commands/monoid.rb
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
#category RLSM
|
2
|
-
|
3
|
-
=begin help
|
4
|
-
Creates a monoid.
|
5
|
-
|
6
|
-
Usage: monoid desc or monoid(desc)
|
7
|
-
|
8
|
-
+desc+ is here the description of a binary operation. The form of the
|
9
|
-
description follows some simple rules:
|
10
|
-
- A binary operation is represented as a quadratic matrix
|
11
|
-
- Rows are seperated by ' ' (space)
|
12
|
-
- Columns are seperated by ',' (comma)
|
13
|
-
The comma may be omitted if every element descriptor is only one
|
14
|
-
char.
|
15
|
-
- The first row and column belongs to the neutral element.
|
16
|
-
- The +desc+ parameter must be surrounded by " (double quote)
|
17
|
-
|
18
|
-
Examples:
|
19
|
-
monoid "1a aa"
|
20
|
-
monoid "1ab aab bab"
|
21
|
-
monoid "1,a a,1"
|
22
|
-
=end
|
23
|
-
|
24
|
-
def monoid(desc)
|
25
|
-
RLSM::Monoid.new desc
|
26
|
-
end
|
27
|
-
|