Class: Carrot2::Client
- Inherits:
-
Object
- Object
- Carrot2::Client
- Defined in:
- lib/carrot2/client.rb
Constant Summary collapse
- HEADERS =
{ "Content-Type" => "application/json", "Accept" => "application/json" }
Instance Method Summary collapse
- #cluster(documents, language: nil, algorithm: nil, parameters: nil, template: nil) ⇒ Object
-
#initialize(url: nil, open_timeout: 3, read_timeout: nil) ⇒ Client
constructor
A new instance of Client.
- #list ⇒ Object
Constructor Details
#initialize(url: nil, open_timeout: 3, read_timeout: nil) ⇒ Client
Returns a new instance of Client.
8 9 10 11 12 13 14 15 |
# File 'lib/carrot2/client.rb', line 8 def initialize(url: nil, open_timeout: 3, read_timeout: nil) url ||= ENV["CARROT2_URL"] || "http://localhost:8080" @uri = URI.parse(url) @http = Net::HTTP.new(@uri.host, @uri.port) @http.use_ssl = true if @uri.scheme == "https" @http.open_timeout = open_timeout if open_timeout @http.read_timeout = read_timeout if read_timeout end |
Instance Method Details
#cluster(documents, language: nil, algorithm: nil, parameters: nil, template: nil) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/carrot2/client.rb', line 21 def cluster(documents, language: nil, algorithm: nil, parameters: nil, template: nil) # no defaults if template unless template language ||= "English" algorithm ||= "Lingo" parameters ||= {} end # data data = { documents: documents.map { |v| v.is_a?(String) ? {field: v} : v } } data[:language] = language if language data[:algorithm] = algorithm if algorithm data[:parameters] = parameters if parameters # path path = "service/cluster" path = "#{path}?#{URI.encode_www_form(template: template)}" if template post(path, data) end |
#list ⇒ Object
17 18 19 |
# File 'lib/carrot2/client.rb', line 17 def list get("service/list") end |