Class: Datagun::Api::KeywordsExtractor::Client

Inherits:
Base
  • Object
show all
Defined in:
lib/datagun/api/keywords_extractor/client.rb

Overview

Client provides methods to interact with keywords_extractor endpoint

Instance Attribute Summary

Attributes inherited from Base

#client, #logger

Instance Method Summary collapse

Methods inherited from Base

set_logger

Constructor Details

#initialize(default_logger: nil, version: Datagun.config.api_version) ⇒ Client

Returns a new instance of Client.



13
14
15
16
17
# File 'lib/datagun/api/keywords_extractor/client.rb', line 13

def initialize(default_logger: nil, version: Datagun.config.api_version)
  super(default_logger: default_logger, version: version)
  base_url = "#{@api_url}/api/#{@version}/keyword_extractor"
  @client = HttpWrapper.new(base_url: base_url)
end

Instance Method Details

#analyze(model_id:, text:) ⇒ JSON

Extract top keywords from passed text using your model

Parameters:

  • model_id (String)
  • text (String)

Returns:

  • (JSON)


81
82
83
84
85
86
87
88
# File 'lib/datagun/api/keywords_extractor/client.rb', line 81

def analyze(model_id:, text:)
  client.endpoint = 'analyze'
  client.payload = {
    model_id: model_id,
    text: text
  }
  client.get.transform_keys(&:to_sym)
end

#delete(model_id:) ⇒ JSON

Delete a model

Returns:

  • (JSON)


68
69
70
71
# File 'lib/datagun/api/keywords_extractor/client.rb', line 68

def delete(model_id:)
  client.endpoint = model_id
  client.delete.transform_keys(&:to_sym)
end

#modelsJSON

Return the list of keywords extractors models

Returns:

  • (JSON)


58
59
60
61
# File 'lib/datagun/api/keywords_extractor/client.rb', line 58

def models
  client.endpoint = 'models'
  client.get.map { |item| item.transform_keys(&:to_sym) }
end

#save_model(name:, features: nil, file:) ⇒ JSON

Store your corpus file

Parameters:

  • name: (String)

    model name

  • features: (Integer) (defaults to: nil)

    max number of features to extract from the corpus

  • file (File)

Returns:

  • (JSON)


28
29
30
31
32
33
34
35
36
# File 'lib/datagun/api/keywords_extractor/client.rb', line 28

def save_model(name:, features: nil, file:)
  client.endpoint = 'save_model'
  client.payload = {
    model_name: name,
    file: file
  }
  client.payload[:max_features] = features unless features.nil?
  client.post.transform_keys(&:to_sym)
end

#status(model_id:) ⇒ JSON

Get status for a model_id

Parameters:

  • model_id (String)

Returns:

  • (JSON)


45
46
47
48
49
50
51
# File 'lib/datagun/api/keywords_extractor/client.rb', line 45

def status(model_id:)
  client.endpoint = 'status'
  client.payload = {
    model_id: model_id
  }
  client.get.transform_keys(&:to_sym)
end