Class: NluAdapter::Adapters::Dialogflow::Intent

Inherits:
Object
  • Object
show all
Includes:
NluAdapterIntent
Defined in:
lib/nlu_adapter/dialogflow.rb

Overview

Class represents Intent in an IntentCollection

Instance Attribute Summary collapse

Attributes included from NluAdapterIntent

#name, #utterences

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Intent

Constructor



116
117
118
119
120
# File 'lib/nlu_adapter/dialogflow.rb', line 116

def initialize(options = {})
	@name = options[:name] #DF.intent.display_name
	@id = options[:id] #DF.intent.name
	@utterences = options[:utterences]
end

Instance Attribute Details

#idObject

Returns the value of attribute id.



113
114
115
# File 'lib/nlu_adapter/dialogflow.rb', line 113

def id
  @id
end

Instance Method Details

#to_hHash

Convert self to Hash

Returns:

  • (Hash)

    ruby hash



125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/nlu_adapter/dialogflow.rb', line 125

def to_h
	training_phrases = []
	@utterences.each do |u|
		training_phrases << {"type" => "EXAMPLE", "parts" =>[{"text" => u }]}
	end

	{
		name: @id,
		display_name: @name,
		training_phrases: training_phrases
	}
end

#to_jsonjson

convert self to json

Returns:

  • (json)

    json



141
142
143
# File 'lib/nlu_adapter/dialogflow.rb', line 141

def to_json
	to_h.to_json
end