natter 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/natter/rule.rb +15 -11
- data/lib/natter/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5a6a81b4f77164c15d606c99eca84daf1e6480a7
|
4
|
+
data.tar.gz: b8ba3a671260c6d0af840b52735edf6e51baf5a2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4a90a933ea1cc37fdf54d55f11b5606ac3f6df89d146d9b016314b3265b953e501fcc0e9bf16dc40a8636d82c3cf11a04162afe19088cb1f61a7b834ec14d433
|
7
|
+
data.tar.gz: 17f4b32482cac81f39f8e5fbdb43540d91db98d58087768cd658de8d5edf9dc3ae4e69ee37a72ce4431d1111a340896254db602c7f3db5d0a066a55d8d50585f
|
data/lib/natter/rule.rb
CHANGED
@@ -4,14 +4,16 @@ module Natter
|
|
4
4
|
# occurs within an utterance.
|
5
5
|
|
6
6
|
class Rule
|
7
|
-
|
7
|
+
# Identifier for rules added without an owning skill.
|
8
|
+
NO_SKILL = "_None"
|
9
|
+
|
8
10
|
# The string name of this rule. Defferent rules can share the same name.
|
9
11
|
attr_accessor :name
|
10
12
|
# The regex pattern to search for within the an utterance.
|
11
13
|
attr_accessor :pattern
|
12
14
|
# An array of Entity objects this rule expects. May be empty.
|
13
15
|
attr_accessor :entities
|
14
|
-
# The name of the skill that this rule belongs to.
|
16
|
+
# The name of the skill that this rule belongs to.
|
15
17
|
attr_accessor :skill
|
16
18
|
|
17
19
|
# Public: Constructor.
|
@@ -22,15 +24,16 @@ module Natter
|
|
22
24
|
# utterance. If this intent contains entities then the regex
|
23
25
|
# must capture the entities within the utterance as named
|
24
26
|
# capture groups. See examples below. Default: //
|
25
|
-
# skill - The name of the skill that this rule belongs to.
|
26
|
-
#
|
27
|
+
# skill - The name of the skill that this rule belongs to. The first
|
28
|
+
# letter will be capitalised (e.g. `sonos` => `Sonos`). If none
|
29
|
+
# is passed then is set to Rule::NO_SKILL
|
27
30
|
# entities - Optional array of Entity objects in the form:
|
28
31
|
# Each entity must have a correspondingly named capture group
|
29
32
|
# within the regex.
|
30
|
-
def initialize(name, pattern = //, skill =
|
33
|
+
def initialize(name, pattern = //, skill = NO_SKILL, *entities)
|
31
34
|
@name = name
|
32
35
|
@pattern = pattern
|
33
|
-
@skill = skill
|
36
|
+
skill == NO_SKILL ? @skill = NO_SKILL : @skill = skill.capitalize
|
34
37
|
@entities = entities || []
|
35
38
|
end
|
36
39
|
|
@@ -50,16 +53,17 @@ module Natter
|
|
50
53
|
return self
|
51
54
|
end
|
52
55
|
|
53
|
-
# Public: Returns this rule's identifier.
|
54
|
-
#
|
56
|
+
# Public: Returns this rule's identifier.
|
57
|
+
# An identifier is in the format `skill.name`.
|
55
58
|
#
|
56
|
-
# Returns string
|
59
|
+
# Returns a string.
|
57
60
|
def identifier
|
58
|
-
"#{@skill
|
61
|
+
"#{@skill}.#{@name}"
|
59
62
|
end
|
60
63
|
|
61
64
|
# Public: A convenience method to permit prettier building of rules.
|
62
65
|
# Returns the Rule back to the calling method to allowing chaining.
|
66
|
+
# The skill name will be capitalised (e.g. `sonos` => `Sonos`).
|
63
67
|
#
|
64
68
|
# skill - The name of the skill that this this rule belongs to.
|
65
69
|
#
|
@@ -67,7 +71,7 @@ module Natter
|
|
67
71
|
#
|
68
72
|
# def = Rule.new('play').belongs_to('sonos')
|
69
73
|
def belongs_to(skill)
|
70
|
-
@skill = skill
|
74
|
+
@skill = skill.capitalize
|
71
75
|
return self
|
72
76
|
end
|
73
77
|
|
data/lib/natter/version.rb
CHANGED