Class: AlexaModelMd

Inherits:
WikiMd
  • Object
show all
Defined in:
lib/alexa_modelmd.rb

Defined Under Namespace

Classes: Intent

Instance Method Summary collapse

Constructor Details

#initialize(wiki = nil, keywords = {}) ⇒ AlexaModelMd

Returns a new instance of AlexaModelMd.



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
# File 'lib/alexa_modelmd.rb', line 39

def initialize(wiki=nil, keywords={})
  
  wcis = keywords.delete :whatcanisay
  puts 'wcis: ' + wcis.inspect if @debug
  
  super(wiki, keywords)
  
  if wcis then
    
    found = self.find 'What can I say'

    if not found then
      
      s=<<EOF        
# What can I say

## WhatCanISay
      
* what can I say
* give me some examples

`
#rsc.alexamodelmd.sample_utterances '#{self.title}'
"Not yet enabled."
`

+ help whatcanisay
EOF

      self.create_section s
      
    end

  end
end

Instance Method Details

#endpointObject



92
# File 'lib/alexa_modelmd.rb', line 92

def endpoint()      @dxsx.dx.endpoint       end

#endpoint=(s) ⇒ Object



93
# File 'lib/alexa_modelmd.rb', line 93

def endpoint=(s)    @dxsx.dx.endpoint = s   end

#entriesObject



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/alexa_modelmd.rb', line 75

def entries()

  r = super()

  r.map do |entry|

    def entry.intents()
      puts 'entries | x: ' + x.inspect if @debug
      self.body().split(/(?=^## )/).map {|x| Intent.new(x, debug: @debug)}
    end

    entry

  end

end

#invocationObject



94
# File 'lib/alexa_modelmd.rb', line 94

def invocation()    @dxsx.dx.invocation     end

#invocation=(s) ⇒ Object



95
# File 'lib/alexa_modelmd.rb', line 95

def invocation=(s)  @dxsx.dx.invocation = s end

#save_rsfObject



97
98
99
100
101
102
103
# File 'lib/alexa_modelmd.rb', line 97

def save_rsf()
  if @dxsx.dx.respond_to? :rsf_file then
    FileX.write @dxsx.dx.rsf_file, to_rsf()
  else
    raise AMSummaryExceptiom, 'no rsf_file summary field found'
  end
end

#save_txtObject



105
106
107
108
109
110
111
# File 'lib/alexa_modelmd.rb', line 105

def save_txt()
  if @dxsx.dx.respond_to? :txt_file then
    FileX.write @dxsx.dx.txt_file, to_txt()
  else
    raise AMSummaryExceptiom, 'no txt_file summary field found'
  end
end

#to_docObject

note: An intent or an utterance can’t contain numbers



134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
# File 'lib/alexa_modelmd.rb', line 134

def to_doc()

  a = RexleBuilder.build do |xml|

    xml.model do

      xml.summary do
        xml.title @dxsx.dx.title
        xml.invocation @dxsx.dx.invocation
        xml.endpoint @dxsx.dx.endpoint
      end

      xml.entries do 
        entries.each do |entry|

          xml.entry do
            xml.topic entry.heading.strip

            xml.intents do
              entry.intents.each do |intent|

                xml.intent do

                  xml.name intent.name.gsub(/\d+/, '')

                  xml.utterances do
                    intent.utterances.each do |utterance|
                      xml.utterance utterance.gsub(/\d+/, '')
                    end
                  end

                  xml.code do              
                    xml.cdata! intent.code
                  end
                end #/intent
              end
            end #/intents

            xml.tags do
              entry.tags.each do |tag|
                xml.tag tag
              end
            end
            
          end
        end 
      end #/entries

    end #/model
  end

  Rexle.new(a)

end

#to_mdObject

Transforms the document into an Alexa_modelmd formatted document



115
116
117
# File 'lib/alexa_modelmd.rb', line 115

def to_md
  Rexslt.new(md_xslt(), to_xml(), debug: @debug).to_s
end

#to_modelbObject Also known as: to_txt

This generates a plain text file representing the Alexa Model to be built using the alexa_modelbuilder gem



122
123
124
# File 'lib/alexa_modelmd.rb', line 122

def to_modelb
  Rexslt.new(modelbuilder_xslt(), to_xml()).to_s    
end

#to_rsfObject



128
129
130
# File 'lib/alexa_modelmd.rb', line 128

def to_rsf
  Rexslt.new(rsf_xslt(), to_xml(), debug: @debug).to_s
end

#to_xmlObject



189
190
191
# File 'lib/alexa_modelmd.rb', line 189

def to_xml()
  to_doc.xml pretty: true
end

#utterancesObject



193
194
195
196
# File 'lib/alexa_modelmd.rb', line 193

def utterances()
  to_doc.root.xpath('//entries/entry/intents/intent/' + 
                               'utterances/utterance').map(&:text)
end