stamina-gui 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. data/CHANGELOG.md +78 -0
  2. data/LICENCE.md +22 -0
  3. data/examples/0-reference/1-automaton-adl.rb +52 -0
  4. data/examples/0-reference/2-sample-adl.rb +56 -0
  5. data/examples/1-automata/1-introduction.rb +0 -0
  6. data/examples/1-automata/2-metrics.rb +0 -0
  7. data/examples/2-regular-languages/1-introduction.rb +22 -0
  8. data/examples/2-regular-languages/2-complement.rb +14 -0
  9. data/examples/2-regular-languages/3-difference.rb +5 -0
  10. data/examples/3-grammar-induction/1-introduction.rb +34 -0
  11. data/examples/3-grammar-induction/2-kernel.rb +32 -0
  12. data/examples/3-grammar-induction/3-characteristic-sample.rb +49 -0
  13. data/lib/stamina-gui/stamina-gui.rb +1 -0
  14. data/lib/stamina-gui/stamina/command/gui.rb +19 -0
  15. data/lib/stamina-gui/stamina/gui.rb +2 -0
  16. data/lib/stamina-gui/stamina/gui/app.rb +69 -0
  17. data/lib/stamina-gui/stamina/gui/examples.rb +68 -0
  18. data/lib/stamina-gui/stamina/gui/public/css/images/ui-bg_diagonals-thick_18_b81900_40x40.png +0 -0
  19. data/lib/stamina-gui/stamina/gui/public/css/images/ui-bg_diagonals-thick_20_666666_40x40.png +0 -0
  20. data/lib/stamina-gui/stamina/gui/public/css/images/ui-bg_flat_10_000000_40x100.png +0 -0
  21. data/lib/stamina-gui/stamina/gui/public/css/images/ui-bg_glass_100_f6f6f6_1x400.png +0 -0
  22. data/lib/stamina-gui/stamina/gui/public/css/images/ui-bg_glass_100_fdf5ce_1x400.png +0 -0
  23. data/lib/stamina-gui/stamina/gui/public/css/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
  24. data/lib/stamina-gui/stamina/gui/public/css/images/ui-bg_gloss-wave_35_f6a828_500x100.png +0 -0
  25. data/lib/stamina-gui/stamina/gui/public/css/images/ui-bg_highlight-soft_100_eeeeee_1x100.png +0 -0
  26. data/lib/stamina-gui/stamina/gui/public/css/images/ui-bg_highlight-soft_75_ffe45c_1x100.png +0 -0
  27. data/lib/stamina-gui/stamina/gui/public/css/images/ui-icons_222222_256x240.png +0 -0
  28. data/lib/stamina-gui/stamina/gui/public/css/images/ui-icons_228ef1_256x240.png +0 -0
  29. data/lib/stamina-gui/stamina/gui/public/css/images/ui-icons_ef8c08_256x240.png +0 -0
  30. data/lib/stamina-gui/stamina/gui/public/css/images/ui-icons_ffd27a_256x240.png +0 -0
  31. data/lib/stamina-gui/stamina/gui/public/css/images/ui-icons_ffffff_256x240.png +0 -0
  32. data/lib/stamina-gui/stamina/gui/public/css/jquery-ui-1.8.16.css +568 -0
  33. data/lib/stamina-gui/stamina/gui/public/css/stamina.less +63 -0
  34. data/lib/stamina-gui/stamina/gui/public/feedback.html +1 -0
  35. data/lib/stamina-gui/stamina/gui/public/js/ace-eclipse.js +1 -0
  36. data/lib/stamina-gui/stamina/gui/public/js/ace-ruby.js +1 -0
  37. data/lib/stamina-gui/stamina/gui/public/js/ace-textmate.js +1 -0
  38. data/lib/stamina-gui/stamina/gui/public/js/ace-twilight.js +1 -0
  39. data/lib/stamina-gui/stamina/gui/public/js/ace.js +1 -0
  40. data/lib/stamina-gui/stamina/gui/public/js/jquery-1.6.2.min.js +18 -0
  41. data/lib/stamina-gui/stamina/gui/public/js/jquery-ui-1.8.16.min.js +791 -0
  42. data/lib/stamina-gui/stamina/gui/public/js/less-1.1.3.min.js +16 -0
  43. data/lib/stamina-gui/stamina/gui/public/js/mustache.js +325 -0
  44. data/lib/stamina-gui/stamina/gui/public/js/stamina.js +75 -0
  45. data/lib/stamina-gui/stamina/gui/templates/image.erb +3 -0
  46. data/lib/stamina-gui/stamina/gui/templates/index.erb +67 -0
  47. metadata +136 -0
data/CHANGELOG.md ADDED
@@ -0,0 +1,78 @@
1
+ # 0.5.0 / FIX ME
2
+
3
+ * Breaking features.
4
+
5
+ * Support for ruby 1.8.7 has been definitely removed.
6
+
7
+ * Major enhancements
8
+
9
+ * The project has been split in different sub gems (core, induction and gui). This
10
+ implies a lot of internal changes, but the public API has not been affected. A main
11
+ 'stamina' gem automatically includes all sub gems so previous behavior is guaranteed.
12
+
13
+ * Minor enhancements
14
+ * Fixed a bug with bundler usage in main stamina binary
15
+ * adl2dot command now support samples as input in addition to automata. In that case,
16
+ the dot result models a PTA (prefix tree acceptor)
17
+ * Added --png to 'stamina adl2dot'
18
+
19
+ # 0.4.0 / 2011-05-01
20
+
21
+ * Major Enhancements
22
+
23
+ * Added Automaton#to_adl as an shortcut for Stamina::ADL::print_automaton(...)
24
+ * Added Sample#to_pta taken from Induction::Commons
25
+ * Added Automaton completion (all strings parsable) under Automaton#complete[!?]
26
+ * Added Automaton stripping (removal of unreachable states) under Automaton#strip[!]
27
+ * Added Automaton minimization (Hopcroft + Pitchies) under Automaton#minimize
28
+ * Added Abbadingo generators under Abbadingo::RandomDFA and Abbadingo::RandomSample
29
+ * Added a main 'stamina' command relying on Quickl. classiy/adl2dot commands become
30
+ subcommands of stamina itself (see stamina --help for a list of available commands).
31
+ Induction command (rpni and redblue) are now handled by a 'stamina infer' with
32
+ options.
33
+ * Error states and now correctly handled in ADL::parse and ADL::flush
34
+ * RedBlue has been renamed as BlueFringe everywhere (red_?blue -> blue_fringe)
35
+
36
+ * Minnor Enhancements
37
+ * Added a few optimizations here and there
38
+
39
+ * Bug fixes
40
+
41
+ * Fixed a bug in Automaton#depth when some states are unreachable
42
+
43
+ # 0.3.1 / 2011-03-24
44
+
45
+ * Major Enhancements
46
+
47
+ * Implemented the decoration algorithm of Damas10, allowing to decorate states
48
+ with information propagated from states to states until a fixpoint is reached.
49
+ * Added Automaton::Metrics module, automatically included, with useful metrics
50
+ like automaton depth, accepting ratio and so on.
51
+ * Added Scoring module and Classifier#classification_scoring(sample) method
52
+ with common measures from information retrieval.
53
+
54
+ * On the devel side
55
+
56
+ * Moved specific automaton tests under test/stamina/automaton/...
57
+
58
+ # 0.3.0 / 2011-03-24
59
+
60
+ * On the devel side
61
+
62
+ * The project structure is now handled by Noe
63
+ * Ensures that tests are correctly executed under ruby 1.9.2
64
+
65
+
66
+ # 0.2.2 / 2010-10-22
67
+
68
+ * Major Enhancements
69
+
70
+ * Sample#<< does not detect inconsistencies anymore, to ensure a linear method instead of a quadratic one.
71
+
72
+ * On the devel side
73
+
74
+ * Fixes a bug in Rakefile that lead to test failures under ruby 1.8.7
75
+
76
+ # 0.2.1 / 2010-05-01
77
+
78
+ * Main public version for the official competition, extracted from private SVN.
data/LICENCE.md ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License
2
+
3
+ Copyright (c) 2008-2009 University of Louvain
4
+ (Universite catholique de Louvain-la-Neuve, Belgium)
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in
14
+ all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
+ THE SOFTWARE.
@@ -0,0 +1,52 @@
1
+ code = <<-ADL
2
+ # First, it allows line comments 'a la' ruby, that is, lines starting with '#'
3
+ # are simply ignored. White spaces may also be inserted between the comment
4
+ # symbol like
5
+ # this
6
+ # Empty lines are also ignored:
7
+
8
+ # Still about comments and white spaces: end-of-line comments are also supported
9
+ # (see documentation on right later). Moreover, white spaces and tabs are allowed
10
+ # at beginning and end of lines as well as between state and edge elements.
11
+
12
+ # Next, the first (non comment or empty) line of the file must contain the number
13
+ # of states then the number of edges of the automaton: (white spaces between them,
14
+ # whitespace before and after are allowed) we refer to these two numbers as
15
+ # state_count and edge_count respectively (here: five states and six edges)
16
+ 5 6
17
+
18
+ # Then, we expect exactly state_count state definitions. A state definition is
19
+ # composed of three informations: 1) a state identifier (any string), 2) 'true'
20
+ # or 'false' for initial flag, 3) 'true' or 'false' for accepting flag. These
21
+ # informations are simply separated by white spaces:
22
+ 0 true false # here a state with identifier 0
23
+ # this state is initial and not accepting
24
+
25
+ identified_state false true # this kind of identifier is also allowed
26
+ # this state is not initial but is accepting
27
+
28
+ # other states below ...
29
+ 2 false false
30
+ 3 false true
31
+ 4 false false
32
+
33
+ # Then, we expect exactly edge_count edge definitions. An edge definition is
34
+ # simple as well: source and target state identifiers followed by a labeling
35
+ # input symbol (any word).
36
+ 0 identified_state hello # the first edge says hello from source
37
+ # state 0 to state identified_state
38
+
39
+ identified_state 2 w # identified_state 'sends' w to state 2
40
+
41
+ # and other edges below ...
42
+ 2 3 o
43
+ 3 4 r
44
+ 4 4 l
45
+ 4 0 d
46
+
47
+ # This automaton grammar does not provide a way to define empty symbols
48
+ # (something like '', which is interpreted for itself) nor does it provide an
49
+ # epsilon predefined character. You'll have to post-process your automaton
50
+ # yourself, sorry!
51
+ ADL
52
+ result = automaton(code)
@@ -0,0 +1,56 @@
1
+ code = <<-ADL
2
+ # First, it allows line comments 'a la' ruby, that is, lines starting with '#'
3
+ # are simply ignored. Whitespaces may also be inserted before the comment symbol
4
+ # like
5
+ # this
6
+ # Empty lines are also ignored:
7
+
8
+ # Still about comments and whitespaces: end-of-line comments are NOT supported
9
+ # because they would not allow using '#' as a input string symbol. Whitespaces
10
+ # and tabs are allowed (and ignored) at begining and end of lines as well as
11
+ # between input symbols (see later).
12
+
13
+ # Next, a sample is a sequence of input strings, separated by newlines (aka
14
+ # carriage return). An input string is simply a sequence of input symbols,
15
+ # separated by whitespace(s) or tabs. Symbols are simple characters or words.
16
+ # An input string is labeled as positive if its first symbol is '+', negative
17
+ # if it's '-' and unlabeled of the first symbol is '?' ('+', '-' and '?' symbols
18
+ # won't be not part of the input string itself). If the string does not start with one
19
+ # of these symbols, it is considered as an error string and ADL raises an error.
20
+ # '+', '-' and '?' anywhere else in the string count for themselve. So, positive,
21
+ # negative and unlabeled strings respectively looks like:
22
+ + a b a b
23
+ - a a
24
+ ? a b
25
+
26
+ # That's all ... here are some other examples and comments:
27
+
28
+ # This is the positive empty string (negative empty string is a simple '-' line,
29
+ # not shown here because it would create an inconsistent sample; unlabeled empty
30
+ # string is simply the '?' line):
31
+ +
32
+
33
+ # We've said earlier that words are accepted as input symbols, and we warn you
34
+ # that the following strings are not equivalent (the first has two symbols only,
35
+ # the second has ten symbols and the last has only one.
36
+ + hello world
37
+ + h e l l o w o r l d
38
+ + helloworld
39
+
40
+ # but whitespaces and tabs do not count, so the following positive string is already
41
+ # part of this sample:
42
+ + h e l l o w o r l d
43
+
44
+ # The following strings are supported: '+' and '-' count for themselve, expect
45
+ # the first, and the last is part of a '+a' symbol.
46
+ + a + b - a - b +a
47
+
48
+ # A last example, to insist on comment rules: here all '#" count for themselve:
49
+ + # a # b a b # and all these words are symbols too !!
50
+
51
+ # This sample grammar does not provide a way to define empty symbols
52
+ # (something like '', which is interpreted for itself) nor does it provide an
53
+ # epsilon predefined character. You'll have to post-process your sample
54
+ # yourself, sorry!
55
+ ADL
56
+ result = sample(code)
File without changes
File without changes
@@ -0,0 +1,22 @@
1
+ #
2
+ # Stamina recognizes regular expressions thanks the `regular` function.
3
+ #
4
+
5
+ # Let's build a regular language
6
+ abstar = regular("(a b)*")
7
+
8
+ # More complex regular languages may be put on multiple lines
9
+ complex = regular <<-LANG
10
+ (a b)+
11
+ | a+
12
+ | b
13
+ LANG
14
+
15
+ # Sometimes, it is useful to capture the universal regular language
16
+ # over an alphabet, that is,
17
+ univ = regular("(a | b | c | d | e)*")
18
+
19
+ # Here is a friendly shortcut, very useful if the alphabet become
20
+ # large
21
+ univ2 = sigma_star('a'..'e')
22
+ assert univ <=> univ2
@@ -0,0 +1,14 @@
1
+ abstar = regular("(a b)*")
2
+
3
+ # The complement of a regular language language L is defined as
4
+ # the set of strings not belonging to L
5
+ complement = abstar**-1
6
+
7
+ # The complement of the complement is the regular language itself
8
+ compcomp = complement**-1
9
+ assert abstar <=> compcomp
10
+
11
+ # Also observe that the complement of a regular language can be
12
+ # computed explicitly as the
13
+ otherway = regular("(a | b)*") - abstar
14
+ assert otherway <=> complement
@@ -0,0 +1,5 @@
1
+ ab_star = regular("(a b)*")
2
+
3
+ # The difference of a regular language with itself is empty
4
+ empty = (ab_star - ab_star)
5
+ assert empty.empty?
@@ -0,0 +1,34 @@
1
+ #
2
+ # This is the introduction example for Stamina induction algorithms
3
+ #
4
+ # Classical induction is aimed at learning a regular language from a
5
+ # `positive` sample, under the control of a `negative` sample.
6
+ #
7
+ # Samples are commonly captured through a Prefix Tree Acceptor (PTA).
8
+ # A PTA capturing both a positive and a negative sample is called an
9
+ # Augmented PTA (APTA)
10
+ #
11
+
12
+ # a positive sample will be captured through a PTA
13
+ # (accepting states capture positive strings)
14
+ positive = sample <<-SAMPLE
15
+ +
16
+ + a
17
+ + b b
18
+ + b b a
19
+ + b a a b
20
+ + b a a a b a
21
+ SAMPLE
22
+
23
+ # a negative sample will be captured through a PTA
24
+ # (no accepting states, but error states capturing negative
25
+ # strings)
26
+ negative = sample <<-SAMPLE
27
+ - b
28
+ - a b
29
+ - a b a
30
+ SAMPLE
31
+
32
+ # The union of samples is recognized as follows, and captured through
33
+ # an APTA (observe that both accepting and error states are present)
34
+ training = positive + negative
@@ -0,0 +1,32 @@
1
+ lang = automaton <<-ADL
2
+ 3 5
3
+ 0 true true
4
+ 1 false false
5
+ 2 false true
6
+ 0 1 a
7
+ 1 1 a
8
+ 1 2 b
9
+ 2 2 b
10
+ 2 0 a
11
+ ADL
12
+
13
+ # In a canonical automaton A(lang) of language `lang`, the set of short prefixes
14
+ # is the set of first strings in standard order, each leading to a particular
15
+ # state of the canonical automaton. As a consequence, there are as many short
16
+ # pre-fixes as states in A(lang). In other words, the short prefixes uniquely
17
+ # identify the states of A(lang).
18
+ prefixes = short_prefixes(lang)
19
+
20
+ # The kernel of a language is made of its short prefixes extended by one symbol
21
+ # together with the empty string. By construction, the short prefixes all belong
22
+ # to the kernel. The kernel elements capture the transitions of the canonical
23
+ # automaton A(lang). Indeed, they are obtained by adding one symbol to the short
24
+ # pre-fixes which capture its states.
25
+ kernel = kernel(lang)
26
+
27
+ characteristic = characteristic_sample(lang)
28
+
29
+ # A characteristic sample is such that RPNI will find the target automaton if
30
+ # invoked
31
+ rpnied = rpni(characteristic)
32
+ assert (regular(lang) - rpnied).empty?
@@ -0,0 +1,49 @@
1
+ target = automaton <<-ADL
2
+ 3 5
3
+ 0 true true
4
+ 1 false false
5
+ 2 false true
6
+ 0 1 a
7
+ 1 1 a
8
+ 1 2 b
9
+ 2 2 b
10
+ 2 0 a
11
+ ADL
12
+
13
+ characteristic = sample <<-ADL
14
+ # Sp(L) - short prefixes
15
+ # ?
16
+ # ? a
17
+ # ? a b
18
+ #
19
+ # N(L) - kernel
20
+ # ?
21
+ # ? a
22
+ # ? a a
23
+ # ? a b
24
+ # ? a b b
25
+ # ? a b a
26
+ #
27
+ # these strings for the first condition of the characteristic
28
+ # sample specification
29
+ +
30
+ + a b
31
+ + a a b
32
+ + a b b
33
+ + a b a
34
+ # these strings for the second condition
35
+ - a
36
+ - b
37
+ - a a
38
+ + a b b a
39
+ - a b a b
40
+ - a a a
41
+ - b b
42
+ - b b b
43
+ + a b b b
44
+ - b a
45
+ - b a b
46
+ ADL
47
+
48
+ learned = rpni(characteristic)
49
+ assert learned <=> target
@@ -0,0 +1 @@
1
+ require_relative 'stamina/gui'
@@ -0,0 +1,19 @@
1
+ module Stamina
2
+ class Command
3
+ #
4
+ # Launches the Stamina Web GUI
5
+ #
6
+ # SYNOPSIS
7
+ # #{program_name} #{command_name}
8
+ #
9
+ class Gui < Quickl::Command(__FILE__, __LINE__)
10
+
11
+ # Command execution
12
+ def execute(args)
13
+ require_relative '../gui'
14
+ Stamina::Gui::App.run!
15
+ end
16
+
17
+ end # class Gui
18
+ end # class Command
19
+ end # module Stamina
@@ -0,0 +1,2 @@
1
+ require_relative "command/gui"
2
+ require_relative "gui/app"
@@ -0,0 +1,69 @@
1
+ require 'tmpdir'
2
+ require 'json'
3
+ require 'sinatra/base'
4
+ require_relative 'examples'
5
+ module Stamina
6
+ module Gui
7
+ class App < Sinatra::Base
8
+
9
+ ### business
10
+
11
+ def go_for(tempdir, src)
12
+ source = File.join(tempdir, "source.rb")
13
+ File.open(source, "w"){|io| io << src}
14
+ Stamina::Command::Run.run(["--all", "--gif", source])
15
+ end
16
+
17
+ ### file helpers
18
+
19
+ def self._(path)
20
+ File.expand_path(path, File.dirname(__FILE__))
21
+ end
22
+ def _(path); self.class._(path); end
23
+
24
+ set :public_folder, _('public')
25
+ set :views, _('templates')
26
+ set :tmpdir, Dir.mktmpdir("stamina-gui")
27
+
28
+ get '/' do
29
+ erb :index, :locals => {
30
+ :examples => Gui::Examples.new
31
+ }
32
+ end
33
+
34
+ # example handlers
35
+ get '/examples/:folder/:file' do
36
+ cache_control :no_cache
37
+ expires 0, :no_cache
38
+ send_file File.join(Gui::Examples::FOLDER,
39
+ params[:folder],
40
+ "#{params[:file]}.rb")
41
+ end
42
+
43
+ # THE go post service
44
+
45
+ post '/go' do
46
+ context = go_for(settings.tmpdir, params[:src])
47
+ content_type :json
48
+ context.collect{|k,v|
49
+ (k != :main and v.respond_to?(:to_dot)) ? k : nil
50
+ }.compact.to_json
51
+ end
52
+
53
+ # image results
54
+
55
+ get '/image/:name' do
56
+ cache_control :no_cache
57
+ expires 0, :no_cache
58
+ erb :image, :locals => { :name => params[:name] }
59
+ end
60
+
61
+ get '/automata/*' do
62
+ cache_control :no_cache
63
+ expires 0, :no_cache
64
+ send_file File.join(settings.tmpdir, params[:splat])
65
+ end
66
+
67
+ end # class App
68
+ end # module Gui
69
+ end # module Stamina