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 +4 -4
- data/README.md +46 -49
- data/lib/srgs/dsl.rb +70 -0
- data/lib/srgs/elements/grammar.rb +2 -1
- data/lib/srgs/elements/item.rb +6 -0
- data/lib/srgs/elements/rule_ref.rb +1 -1
- data/lib/srgs/grammar_builder.rb +2 -2
- data/lib/srgs/version.rb +1 -1
- data/lib/srgs.rb +1 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 36ca218a8938ba13a38b4582a2fa757635d07ff4
|
4
|
+
data.tar.gz: 63925ebfa4aaa9697b61a165c4fc9abf1e774207
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
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)
|
data/lib/srgs/elements/item.rb
CHANGED
data/lib/srgs/grammar_builder.rb
CHANGED
@@ -102,8 +102,8 @@ module Srgs
|
|
102
102
|
|
103
103
|
def token(token, xml)
|
104
104
|
att = {}
|
105
|
-
|
106
|
-
|
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
data/lib/srgs.rb
CHANGED
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.
|
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
|