Class: NluTools::Test

Inherits:
Thor
  • Object
show all
Defined in:
lib/nlu_tools/cli/test.rb

Overview

The subcommand for test

Instance Method Summary collapse

Instance Method Details

#dialogflowObject



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/nlu_tools/cli/test.rb', line 40

def dialogflow
  unless File.exist?(options[:file])
    puts "File #{options[:file]} does not exist"
    exit(1)
  end

  intents = JSON.parse(File.read(options[:file]))
  schema = Pathname.new('schema/nlu_testing_data.json')
  schemer = JSONSchemer.schema(schema)
  if schemer.valid?(intents)
    na = NluAdapter.new(:Dialogflow,
                        project_id: options[:project_id],
                        session_id: 'SESSION1')
    new_intents = {}
    intents['testing_data'].each do |intent|
      new_intents[intent['intent']] = intent['utterences']
    end

    run_tests(na, new_intents, options[:output_file], options[:output_type])
  else
    puts "Testing data is not in valid format\nPlease check data/simple_test.json for reference"
    exit(1)
  end
end

#lexObject



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/nlu_tools/cli/test.rb', line 100

def lex
  unless File.exist?(options[:file])
    puts "File #{options[:file]} does not exist"
    exit(1)
  end

  intents = JSON.parse(File.read(options[:file]))
  schema = Pathname.new('schema/nlu_testing_data.json')
  schemer = JSONSchemer.schema(schema)
  if schemer.valid?(intents)
    na = NluAdapter.new(:Lex,
                        bot_name: options[:botname],
                        bot_alias: 'BotAlias',
                        user_id: 'user-1')
    new_intents = {}
    intents['testing_data'].each do |intent|
      intent_name = intent['intent'].gsub('-', '_')
      new_intents[intent_name] = intent['utterences']
    end

    run_tests(na, new_intents, options[:output_file], options[:output_type])
  else
    puts "Testing data is not in valid format\nPlease check data/simple_test.json for reference"
    exit(1)
  end
end