srgs 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +47 -5
- data/lib/srgs/dsl.rb +23 -17
- data/lib/srgs/elements/item.rb +4 -5
- data/lib/srgs/grammar_builder.rb +29 -20
- data/lib/srgs/version.rb +1 -1
- metadata +3 -3
- data/lib/srgs/test.rb +0 -49
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 78d562ce8bb4d8ecf263c1c97ff74e3149e4ba2f
|
4
|
+
data.tar.gz: 58826d3300604e031ab6dce87a589948abd3812b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4b69a52d2570830a940305af7af4db007205c1deca27ff0189d081d09328c53117bad69c9837363093b38ca3c87870d352f000d93aa4a1cc3f03e48f97653171
|
7
|
+
data.tar.gz: 4d3719463019e41d9425913970757e65c2513ae9a400efedccce1372c3e40b71c47f388559809c7ac2f5c5a7689609299261563453a46fd30e53f14171363a31
|
data/README.md
CHANGED
@@ -20,9 +20,6 @@ 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.aspx) is a good
|
24
|
-
reference on how srgs grammars work.
|
25
|
-
|
26
23
|
```ruby
|
27
24
|
require 'srgs'
|
28
25
|
|
@@ -53,7 +50,7 @@ module WeatherGrammar
|
|
53
50
|
tag 'out.day=rules.days;'
|
54
51
|
end
|
55
52
|
|
56
|
-
public_rule '
|
53
|
+
public_rule 'sun' do
|
57
54
|
item 'Mycroft when is sun'
|
58
55
|
reference 'riseset'
|
59
56
|
tag 'out.rise_or_set=rules.riseset;'
|
@@ -64,7 +61,7 @@ module WeatherGrammar
|
|
64
61
|
public_rule 'topLevel' do
|
65
62
|
one_of do
|
66
63
|
reference_item 'weather'
|
67
|
-
reference_item '
|
64
|
+
reference_item 'sun'
|
68
65
|
end
|
69
66
|
end
|
70
67
|
end
|
@@ -72,6 +69,51 @@ end
|
|
72
69
|
```
|
73
70
|
|
74
71
|
Running that will print to console the corresponding xml.
|
72
|
+
```xml
|
73
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
74
|
+
<grammar xmlns="http://www.w3.org/2001/06/grammar" xml:lang="en-US" root="toplevel" tag-format="semantics/1.0" version="1.0">
|
75
|
+
<rule id="toplevel">
|
76
|
+
<one-of>
|
77
|
+
<item>
|
78
|
+
<ruleref uri="#weather" />
|
79
|
+
</item>
|
80
|
+
<item>
|
81
|
+
<ruleref uri="#sun" />
|
82
|
+
</item>
|
83
|
+
</one-of>
|
84
|
+
</rule>
|
85
|
+
<rule id="weather" scope="public">
|
86
|
+
<item>Mycroft what is the weather</item>
|
87
|
+
<ruleref uri="#days" />
|
88
|
+
<tag>out.day=rules.days;</tag>
|
89
|
+
</rule>
|
90
|
+
<rule id="sun" scope="public">
|
91
|
+
<item>Mycroft When is sun</item>
|
92
|
+
<ruleref uri="#riseset" />
|
93
|
+
<tag>out.rise_or_set=rules.riseset;</tag>
|
94
|
+
<ruleref uri="#days" />
|
95
|
+
<tag>out.day=rules.days;</tag>
|
96
|
+
</rule>
|
97
|
+
<rule id="days" scope="private">
|
98
|
+
<one-of>
|
99
|
+
<item>today</item>
|
100
|
+
<item>tomorrow</item>
|
101
|
+
<item>currently</item>
|
102
|
+
</one-of>
|
103
|
+
</rule>
|
104
|
+
<rule id="riseset" scope="private">
|
105
|
+
<one-of>
|
106
|
+
<item>rise</item>
|
107
|
+
<item>set</item>
|
108
|
+
</one-of>
|
109
|
+
</rule>
|
110
|
+
</grammar>
|
111
|
+
```
|
112
|
+
|
113
|
+
## References
|
114
|
+
|
115
|
+
* [Speech Recognition Grammar Specification Version 1.0](http://www.w3.org/TR/speech-grammar/#S4.13)
|
116
|
+
* [SRGS Grammar XML Reference](http://msdn.microsoft.com/en-us/library/hh361653.aspx)
|
75
117
|
|
76
118
|
## Contributing
|
77
119
|
|
data/lib/srgs/dsl.rb
CHANGED
@@ -9,11 +9,13 @@ module Srgs
|
|
9
9
|
@grammar = Grammar.new root
|
10
10
|
instance_eval &block
|
11
11
|
@grammar.current_level = nil
|
12
|
-
|
12
|
+
grammar = Srgs.build(@grammar)
|
13
|
+
puts grammar
|
14
|
+
grammar
|
13
15
|
end
|
14
16
|
|
15
|
-
def item(element = '',
|
16
|
-
item = Item.new(element,
|
17
|
+
def item(element = '', args = {}, &block)
|
18
|
+
item = Item.new(element, args[:repeat], args[:repeat_prob], args[:weight])
|
17
19
|
@grammar.current_level << item
|
18
20
|
old_current = @grammar.current_level
|
19
21
|
@grammar.current_level = item
|
@@ -21,12 +23,12 @@ module Srgs
|
|
21
23
|
@grammar.current_level = old_current
|
22
24
|
end
|
23
25
|
|
24
|
-
def lexicon(uri,
|
25
|
-
@grammar << Lexicon.new(uri, type)
|
26
|
+
def lexicon(uri, args = {})
|
27
|
+
@grammar << Lexicon.new(uri, args[:type])
|
26
28
|
end
|
27
29
|
|
28
|
-
def meta(content,
|
29
|
-
@grammar << Meta.new(content, name, http_equiv)
|
30
|
+
def meta(content, args = {})
|
31
|
+
@grammar << Meta.new(content, args[:name], args[:http_equiv])
|
30
32
|
end
|
31
33
|
|
32
34
|
def one_of(&block)
|
@@ -37,34 +39,38 @@ module Srgs
|
|
37
39
|
@grammar.current_level = old_current
|
38
40
|
end
|
39
41
|
|
40
|
-
def public_rule(id,
|
41
|
-
@grammar.current_level = Rule.new(id, 'public', dynamic)
|
42
|
+
def public_rule(id, args = {}, &block)
|
43
|
+
@grammar.current_level = Rule.new(id, 'public', args[:dynamic])
|
42
44
|
@grammar << @grammar.current_level
|
43
45
|
instance_eval &block
|
44
46
|
@grammar.current_level = nil
|
45
47
|
end
|
46
48
|
|
47
|
-
def private_rule(id,
|
48
|
-
@grammar.current_level = Rule.new(id, 'private', dynamic)
|
49
|
+
def private_rule(id, args = {}, &block)
|
50
|
+
@grammar.current_level = Rule.new(id, 'private', args[:dynamic])
|
49
51
|
@grammar << @grammar.current_level
|
50
52
|
instance_eval &block
|
51
53
|
@grammar.current_level = nil
|
52
54
|
end
|
53
55
|
|
54
|
-
def reference(name,
|
55
|
-
@grammar.current_level << RuleRef.new(name, special)
|
56
|
+
def reference(name, args = {})
|
57
|
+
@grammar.current_level << RuleRef.new(name, args[:special])
|
56
58
|
end
|
57
59
|
|
58
|
-
def reference_item(name,
|
59
|
-
@grammar.current_level << Item.new(RuleRef.new(name, special))
|
60
|
+
def reference_item(name, args = {})
|
61
|
+
@grammar.current_level << Item.new(RuleRef.new(name, args[:special]))
|
60
62
|
end
|
61
63
|
|
62
64
|
def tag(text)
|
63
65
|
@grammar.current_level << Tag.new(text)
|
64
66
|
end
|
65
67
|
|
66
|
-
def
|
67
|
-
@grammar.current_level <<
|
68
|
+
def text(text)
|
69
|
+
@grammar.current_level << text
|
70
|
+
end
|
71
|
+
|
72
|
+
def token(text, args = {})
|
73
|
+
@grammar.current_level << Token.new(text, args[:display], args[:pron])
|
68
74
|
end
|
69
75
|
end
|
70
76
|
end
|
data/lib/srgs/elements/item.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
module Srgs
|
2
2
|
class Item
|
3
3
|
|
4
|
-
attr_accessor :
|
4
|
+
attr_accessor :elements, :repeat, :repeat_prob, :weight
|
5
5
|
|
6
|
-
def initialize(element
|
7
|
-
@
|
6
|
+
def initialize(element = '', repeat=nil, repeat_prob = nil, weight = nil)
|
7
|
+
@elements = [element]
|
8
8
|
@tag = tag
|
9
9
|
@repeat = repeat
|
10
10
|
@repeat_prob = repeat_prob
|
@@ -12,8 +12,7 @@ module Srgs
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def <<(element)
|
15
|
-
@
|
16
|
-
@element = element if(element.is_a? Token or element.is_a? String)
|
15
|
+
@elements << element
|
17
16
|
self
|
18
17
|
end
|
19
18
|
|
data/lib/srgs/grammar_builder.rb
CHANGED
@@ -30,19 +30,20 @@ module Srgs
|
|
30
30
|
set(:repeat, att, item.repeat)
|
31
31
|
set(:'repeat-prob', att, item.repeat_prob)
|
32
32
|
set(:weight, att, item.weight)
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
33
|
+
xml.item(att) do
|
34
|
+
item.elements.each do |element|
|
35
|
+
case element
|
36
|
+
when Token
|
37
|
+
token(element, xml)
|
38
|
+
when RuleRef
|
39
|
+
rule_ref(element, xml)
|
40
|
+
when Tag
|
41
|
+
tag(element, xml)
|
42
|
+
when String
|
43
|
+
text(element, xml)
|
44
|
+
else
|
45
|
+
raise "Can't add #{element.class} to item."
|
46
|
+
end
|
46
47
|
end
|
47
48
|
end
|
48
49
|
end
|
@@ -79,16 +80,21 @@ module Srgs
|
|
79
80
|
set(:'sapi:dynamic', att, rule.dynamic)
|
80
81
|
xml.rule(att) do
|
81
82
|
rule.elements.each do |element|
|
82
|
-
|
83
|
+
case element
|
84
|
+
when Item
|
83
85
|
item(element, xml)
|
84
|
-
|
86
|
+
when RuleRef
|
85
87
|
rule_ref(element, xml)
|
86
|
-
|
88
|
+
when OneOf
|
87
89
|
one_of(element, xml)
|
88
|
-
|
90
|
+
when Token
|
89
91
|
token(element, xml)
|
90
|
-
|
92
|
+
when Tag
|
91
93
|
tag(element, xml)
|
94
|
+
when Example
|
95
|
+
example(element, xml)
|
96
|
+
else
|
97
|
+
raise "Can't add #{element.class} to item"
|
92
98
|
end
|
93
99
|
end
|
94
100
|
end
|
@@ -104,6 +110,10 @@ module Srgs
|
|
104
110
|
xml.tag tag.text
|
105
111
|
end
|
106
112
|
|
113
|
+
def text(text, xml)
|
114
|
+
xml.text text
|
115
|
+
end
|
116
|
+
|
107
117
|
def token(token, xml)
|
108
118
|
att = {}
|
109
119
|
set(:'sapi:display', att, token.display)
|
@@ -114,5 +124,4 @@ module Srgs
|
|
114
124
|
def set(sym, att, value)
|
115
125
|
att[sym] = value unless value.nil?
|
116
126
|
end
|
117
|
-
|
118
|
-
end
|
127
|
+
end
|
data/lib/srgs/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: srgs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- kristenmills
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-01-
|
11
|
+
date: 2014-01-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -78,7 +78,6 @@ files:
|
|
78
78
|
- lib/srgs/elements/tag.rb
|
79
79
|
- lib/srgs/elements/token.rb
|
80
80
|
- lib/srgs/grammar_builder.rb
|
81
|
-
- lib/srgs/test.rb
|
82
81
|
- lib/srgs/version.rb
|
83
82
|
- srgs.gemspec
|
84
83
|
homepage: https://github.com/kristenmills/srgs
|
@@ -106,3 +105,4 @@ signing_key:
|
|
106
105
|
specification_version: 4
|
107
106
|
summary: A gem for building SRGS/grXML documents.
|
108
107
|
test_files: []
|
108
|
+
has_rdoc:
|
data/lib/srgs/test.rb
DELETED
@@ -1,49 +0,0 @@
|
|
1
|
-
require 'srgs'
|
2
|
-
|
3
|
-
grammar = Srgs::Grammar.new
|
4
|
-
|
5
|
-
sunriseset = Srgs::Rule.new('riseset')
|
6
|
-
sunriseset_choices = Srgs::OneOf.new << Srgs::Item.new('rise') << Srgs::Item.new('set')
|
7
|
-
sunriseset << sunriseset_choices
|
8
|
-
sunriseset.scope = 'private'
|
9
|
-
|
10
|
-
sunriseset_ref = Srgs::RuleRef.new(sunriseset)
|
11
|
-
|
12
|
-
days = Srgs::Rule.new('days')
|
13
|
-
days_choices = Srgs::OneOf.new << Srgs::Item.new('today') << Srgs::Item.new('tomorrow') << Srgs::Item.new('currently')
|
14
|
-
days << days_choices
|
15
|
-
days.scope = 'private'
|
16
|
-
|
17
|
-
days_ref = Srgs::RuleRef.new(days)
|
18
|
-
|
19
|
-
weather = Srgs::Rule.new('weather')
|
20
|
-
sun = Srgs::Rule.new('sun')
|
21
|
-
|
22
|
-
question1 = Srgs::Item.new("Mycroft what is the weather");
|
23
|
-
question2 = Srgs::Item.new("Mycroft When is sun");
|
24
|
-
|
25
|
-
weather << question1
|
26
|
-
weather << days_ref
|
27
|
-
weather << Srgs::Tag.new("out.day=rules.days;")
|
28
|
-
weather.scope = 'public'
|
29
|
-
|
30
|
-
sun << question2
|
31
|
-
sun << sunriseset_ref
|
32
|
-
sun << Srgs::Tag.new("out.rise_or_set=rules.riseset;")
|
33
|
-
sun << days_ref
|
34
|
-
sun << Srgs::Tag.new("out.day=rules.days;")
|
35
|
-
sun.scope = 'public'
|
36
|
-
|
37
|
-
top_level = Srgs::Rule.new("toplevel");
|
38
|
-
top_level_choices = Srgs::OneOf.new
|
39
|
-
item1 = Srgs::Item.new Srgs::RuleRef.new(weather)
|
40
|
-
item2 = Srgs::Item.new Srgs::RuleRef.new(sun)
|
41
|
-
top_level_choices << item1
|
42
|
-
top_level_choices << item2
|
43
|
-
top_level << top_level_choices
|
44
|
-
|
45
|
-
grammar << top_level << weather << sun << days << sunriseset
|
46
|
-
|
47
|
-
grammar.root = "toplevel"
|
48
|
-
|
49
|
-
puts Srgs.build(grammar)
|