srgs 0.5.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 390a6193c41c0b64138ec62e9398d204b92fd56f
4
- data.tar.gz: 82d27e46aaafceae8313531e052c747dfc1e1825
3
+ metadata.gz: 36ca218a8938ba13a38b4582a2fa757635d07ff4
4
+ data.tar.gz: 63925ebfa4aaa9697b61a165c4fc9abf1e774207
5
5
  SHA512:
6
- metadata.gz: 2815041a09db82312bb0284c31fef3ae0380d4a367333adaa5bf6c52c664c9dae83a23898decf84d65601a3edc32c0d706af4e5e2ab663070f62ecfc4d31cb62
7
- data.tar.gz: e2ed6e86daef6652ba3c29485cbd353b9ef747dca3ec2dd1de30edab23e4391aa70a060af02321b9a574d55deb045d5df1702721778552b96724df3e3eeba906
6
+ metadata.gz: 2b399f5f039aed7127c50f50f239240e80d731ddbc9de36d9fa18fe2c5361bcef39b1b948432e95f16c21f9bedb2f8fdb35ed5d192721b75c1da6e2f5cd35597
7
+ data.tar.gz: aeb17f9b4c653d77f0976dcf6aeda9df9a3190b06f780d3c19ea7abfdf839c39ccd4685669ce3be544d420b3a752cf935d0043a5685f3c174eda3ad5895d2a0c
data/README.md CHANGED
@@ -20,62 +20,59 @@ Or install it yourself as:
20
20
 
21
21
  Here's an example file. It will be documented better later
22
22
 
23
- [This](http://msdn.microsoft.com/en-us/library/hh361653(v=office.14).aspx) is a good
23
+ [This](http://msdn.microsoft.com/en-us/library/hh361653.aspx) is a good
24
24
  reference on how srgs grammars work.
25
25
 
26
- In the future, I plan to create a dsl for this but for now this is how it works.
27
26
  ```ruby
28
27
  require 'srgs'
29
28
 
30
- grammar = Srgs::Grammar.new
31
-
32
- sunriseset = Srgs::Rule.new('riseset')
33
- sunriseset_choices = Srgs::OneOf.new << Srgs::Item.new('rise') << Srgs::Item.new('set')
34
- sunriseset << sunriseset_choices
35
- sunriseset.scope = 'private'
36
-
37
- sunriseset_ref = Srgs::RuleRef.new(sunriseset)
38
-
39
- days = Srgs::Rule.new('days')
40
- days_choices = Srgs::OneOf.new << Srgs::Item.new('today') << Srgs::Item.new('tomorrow') << Srgs::Item.new('currently')
41
- days << days_choices
42
- days.scope = 'private'
43
-
44
- days_ref = Srgs::RuleRef.new(days)
45
-
46
- weather = Srgs::Rule.new('weather')
47
- sun = Srgs::Rule.new('sun')
48
-
49
- question1 = Srgs::Item.new("Mycroft what is the weather");
50
- question2 = Srgs::Item.new("Mycroft When is sun");
51
-
52
- weather << question1
53
- weather << days_ref
54
- weather << Srgs::Tag.new("out.day=rules.days;")
55
- weather.scope = 'public'
56
-
57
- sun << question2
58
- sun << sunriseset_ref
59
- sun << Srgs::Tag.new("out.rise_or_set=rules.riseset;")
60
- sun << days_ref
61
- sun << Srgs::Tag.new("out.day=rules.days;")
62
- sun.scope = 'public'
63
-
64
- top_level = Srgs::Rule.new("toplevel");
65
- top_level_choices = Srgs::OneOf.new
66
- item1 = Srgs::Item.new Srgs::RuleRef.new(weather)
67
- item2 = Srgs::Item.new Srgs::RuleRef.new(sun)
68
- top_level_choices << item1
69
- top_level_choices << item2
70
- top_level << top_level_choices
71
-
72
- grammar << top_level << weather << sun << days << sunriseset
73
-
74
- grammar.root = "toplevel"
75
-
76
- puts Srgs.build(grammar)
29
+ module WeatherGrammar
30
+ include Srgs::DSL
31
+
32
+ extend self
33
+
34
+ grammar 'topLevel' do
35
+ private_rule 'riseset' do
36
+ one_of do
37
+ item 'rise'
38
+ item 'set'
39
+ end
40
+ end
41
+
42
+ private_rule 'days' do
43
+ one_of do
44
+ item 'today'
45
+ item 'tomorrow'
46
+ item 'currently'
47
+ end
48
+ end
49
+
50
+ public_rule 'weather' do
51
+ item 'Mycroft what is the weather'
52
+ reference 'days'
53
+ tag 'out.day=rules.days;'
54
+ end
55
+
56
+ public_rule 'days' do
57
+ item 'Mycroft when is sun'
58
+ reference 'riseset'
59
+ tag 'out.rise_or_set=rules.riseset;'
60
+ reference 'days'
61
+ tag 'out.day=rules.days;'
62
+ end
63
+
64
+ public_rule 'topLevel' do
65
+ one_of do
66
+ reference_item 'weather'
67
+ reference_item 'days'
68
+ end
69
+ end
70
+ end
71
+ end
77
72
  ```
78
73
 
74
+ Running that will print to console the corresponding xml.
75
+
79
76
  ## Contributing
80
77
 
81
78
  1. Fork it
data/lib/srgs/dsl.rb ADDED
@@ -0,0 +1,70 @@
1
+ module Srgs
2
+ module DSL
3
+ @grammer = nil
4
+ def example(text)
5
+ @grammar.current_level << Example.new(text)
6
+ end
7
+
8
+ def grammar(root, &block)
9
+ @grammar = Grammar.new 'root'
10
+ instance_eval &block
11
+ @grammar.current_level = nil
12
+ puts Srgs.build(@grammar)
13
+ end
14
+
15
+ def item(element = '', tag=nil, repeat=nil, repeat_prob = nil, weight = nil, &block)
16
+ item = Item.new(element, tag, repeat, repeat_prob, weight)
17
+ @grammar.current_level << item
18
+ old_current = @grammar.current_level
19
+ @grammar.current_level = item
20
+ instance_eval &block unless block.nil?
21
+ @grammar.current_level = old_current
22
+ end
23
+
24
+ def lexicon(uri, type=nil)
25
+ @grammar << Lexicon.new(uri, type)
26
+ end
27
+
28
+ def meta(content, name = nil, http_equiv = nil)
29
+ @grammar << Meta.new(content, name, http_equiv)
30
+ end
31
+
32
+ def one_of(&block)
33
+ old_current = @grammar.current_level
34
+ @grammar.current_level = OneOf.new
35
+ old_current << @grammar.current_level
36
+ instance_eval &block
37
+ @grammar.current_level = old_current
38
+ end
39
+
40
+ def public_rule(id, dynamic= nil, &block)
41
+ @grammar.current_level = Rule.new(id, 'public', dynamic)
42
+ @grammar << @grammar.current_level
43
+ instance_eval &block
44
+ @grammar.current_level = nil
45
+ end
46
+
47
+ def private_rule(id, dynamic= nil, &block)
48
+ @grammar.current_level = Rule.new(id, 'private', dynamic)
49
+ @grammar << @grammar.current_level
50
+ instance_eval &block
51
+ @grammar.current_level = nil
52
+ end
53
+
54
+ def reference(name, special=nil)
55
+ @grammar.current_level << RuleRef.new(name, special)
56
+ end
57
+
58
+ def reference_item(name, special=nil)
59
+ @grammar.current_level << Item.new(RuleRef.new(name, special))
60
+ end
61
+
62
+ def tag(text)
63
+ @grammar.current_level << Tag.new(text)
64
+ end
65
+
66
+ def token(text, display=nil, pron = nil)
67
+ @grammar.current_level << Token.new(text, display, pron)
68
+ end
69
+ end
70
+ end
@@ -1,13 +1,14 @@
1
1
  module Srgs
2
2
  class Grammar
3
3
 
4
- attr_accessor :root, :lexicon, :rules, :metas
4
+ attr_accessor :root, :lexicon, :rules, :metas, :current_level
5
5
 
6
6
  def initialize(root = '')
7
7
  @root = root
8
8
  @lexicon = nil
9
9
  @metas = Array.new
10
10
  @rules = Array.new
11
+ @current_level = nil
11
12
  end
12
13
 
13
14
  def <<(element)
@@ -11,5 +11,11 @@ module Srgs
11
11
  @weight = weight
12
12
  end
13
13
 
14
+ def <<(element)
15
+ @tag = element if element.is_a? Tag
16
+ @element = element if(element.is_a? Token or element.is_a? String)
17
+ self
18
+ end
19
+
14
20
  end
15
21
  end
@@ -4,7 +4,7 @@ module Srgs
4
4
  attr_accessor :uri, :special
5
5
 
6
6
  def initialize(rule, special=nil)
7
- @uri = "##{rule.id}"
7
+ @uri = "##{rule}"
8
8
  @special =special
9
9
  end
10
10
 
@@ -102,8 +102,8 @@ module Srgs
102
102
 
103
103
  def token(token, xml)
104
104
  att = {}
105
- att(:'sapi:display', att, token.display)
106
- att(:'sapi:pron', att, token.pron)
105
+ set(:'sapi:display', att, token.display)
106
+ set(:'sapi:pron', att, token.pron)
107
107
  xml.token(token.text, att)
108
108
  end
109
109
 
data/lib/srgs/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Srgs
2
- VERSION = "0.5.0"
2
+ VERSION = "1.0.0"
3
3
  end
data/lib/srgs.rb CHANGED
@@ -11,6 +11,7 @@ require 'srgs/elements/rule_ref'
11
11
  require 'srgs/elements/tag'
12
12
  require 'srgs/elements/token'
13
13
  require 'srgs/grammar_builder'
14
+ require 'srgs/dsl'
14
15
 
15
16
  module Srgs
16
17
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: srgs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - kristenmills
@@ -65,6 +65,7 @@ files:
65
65
  - README.md
66
66
  - Rakefile
67
67
  - lib/srgs.rb
68
+ - lib/srgs/dsl.rb
68
69
  - lib/srgs/elements/example.rb
69
70
  - lib/srgs/elements/grammar.rb
70
71
  - lib/srgs/elements/item.rb