carrot2 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 33734687ea74c1750a823b92eb21648910a7c11c
4
- data.tar.gz: 3683ea29b97fa311a23919048d49b2c4c3784701
2
+ SHA256:
3
+ metadata.gz: 73489263c06ae2b8e9f7509570c35c052635340d8401f04d659fe4080188b049
4
+ data.tar.gz: 891c4d26486b4c39c1cdff7756bb97faea0ff01ae5aceaa8082ed122d4300f6c
5
5
  SHA512:
6
- metadata.gz: 8c87a0029e7d304717778fc7fadeee896895cb412524e7fe0d435aec2f84308cbd9d6967481abd8493dff75303024bcdd467b33f7f25947931c8702f261d0f6c
7
- data.tar.gz: 5028411dc8eb0bf3a5629824e9fba106846f2759a3c687a43fa5d19636b1cce0bc9b564daf5ab2b0e23ab2a6ca318061345584c0641db0933d7e5b834dc70e39
6
+ metadata.gz: 30e723899e33b4ce32463b52a65b24ac1f1a1fc7a39fec038dfd95c5fad7cdf0bb78555e24fdeff18657905ca194fcc59afded05dc292cfcb06ca7aa919eca59
7
+ data.tar.gz: 1dae126a035baf128cc7e4ec265259056e1817694b2a61317edc339f4b193a1f0b81c4f08bc80a8d98fda28dd69f4ef12be75f30d2450be55654f33ee8085927
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 0.2.1
2
+
3
+ - Added `open_timeout` and `read_timeout` options
4
+
1
5
  ## 0.2.0
2
6
 
3
7
  - Added `request` method
File without changes
data/README.md CHANGED
@@ -1,10 +1,10 @@
1
1
  # Carrot2
2
2
 
3
- Ruby client for [Carrot2](http://project.carrot2.org/) - the open-source document clustering server
3
+ Ruby client for [Carrot2](https://project.carrot2.org/) - the open-source document clustering server
4
4
 
5
5
  ## Installation
6
6
 
7
- First, [download and run](http://project.carrot2.org/download-dcs.html) the Carrot2 server. It’s the one on [this page](https://github.com/carrot2/carrot2/releases) that begins with `carrot2-dcs`.
7
+ First, [download and run](https://project.carrot2.org/download-dcs.html) the Carrot2 server. It’s the one on [this page](https://github.com/carrot2/carrot2/releases) that begins with `carrot2-dcs`.
8
8
 
9
9
  With Homebrew, use:
10
10
 
@@ -73,6 +73,14 @@ This returns:
73
73
 
74
74
  Documents are numbered in the order provided, starting with 0.
75
75
 
76
+ Specify a language with:
77
+
78
+ ```ruby
79
+ carrot2.cluster(documents, language: "FRENCH")
80
+ ```
81
+
82
+ [All of these languages are supported](https://doc.carrot2.org/#section.faq.preliminaries.supported-languages)
83
+
76
84
  For other requests, use:
77
85
 
78
86
  ```ruby
@@ -89,6 +97,12 @@ To specify the Carrot2 server, set `ENV["CARROT2_URL"]` or use:
89
97
  Carrot2.new(url: "http://localhost:8080")
90
98
  ```
91
99
 
100
+ Set timeouts [master]
101
+
102
+ ```ruby
103
+ Carrot2.new(open_timeout: 3, read_timeout: 5)
104
+ ```
105
+
92
106
  ## Heroku
93
107
 
94
108
  Carrot2 can be easily deployed to Heroku thanks to support for [WAR deployment](https://devcenter.heroku.com/articles/war-deployment).
data/lib/carrot2.rb CHANGED
@@ -6,15 +6,18 @@ require "json"
6
6
  class Carrot2
7
7
  class Error < StandardError; end
8
8
 
9
- def initialize(url: nil)
9
+ def initialize(url: nil, open_timeout: 3, read_timeout: nil)
10
10
  @url = url || ENV["CARROT2_URL"] || "http://localhost:8080"
11
11
 
12
12
  # add dcs/rest
13
13
  @url = "#{@url.sub(/\/\z/, "")}/dcs/rest"
14
14
  @uri = URI.parse(@url)
15
+
16
+ @open_timeout = open_timeout
17
+ @read_timeout = read_timeout
15
18
  end
16
19
 
17
- def cluster(documents, language: "ENGLISH")
20
+ def cluster(documents, language: "English")
18
21
  xml = Builder::XmlMarkup.new
19
22
  xml.instruct! :xml, version: "1.0", encoding: "UTF-8"
20
23
  xml.searchresult do |s|
@@ -28,13 +31,25 @@ class Carrot2
28
31
  request(
29
32
  "dcs.clusters.only" => true,
30
33
  "dcs.c2stream" => xml.target!,
31
- "MultilingualClustering.defaultLanguage" => language,
34
+ "MultilingualClustering.defaultLanguage" => language.upcase,
32
35
  multipart: true
33
36
  )
34
37
  end
35
38
 
36
39
  def request(params)
37
- response = Net::HTTP.post_form(@uri, params.merge("dcs.output.format" => "JSON"))
40
+ req = Net::HTTP::Post.new(@uri)
41
+ req.set_form_data(params.merge("dcs.output.format" => "JSON"))
42
+
43
+ options = {
44
+ use_ssl: @uri.scheme == "https"
45
+ }
46
+ options[:open_timeout] = @open_timeout if @open_timeout
47
+ options[:read_timeout] = @read_timeout if @read_timeout
48
+
49
+ response = Net::HTTP.start(@uri.hostname, @uri.port, options) do |http|
50
+ http.request(req)
51
+ end
52
+
38
53
  if response.code == "200"
39
54
  JSON.parse(response.body)
40
55
  else
@@ -1,3 +1,3 @@
1
1
  class Carrot2
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: carrot2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kane
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-01-23 00:00:00.000000000 Z
11
+ date: 2019-10-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: builder
@@ -66,26 +66,20 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
- description: Ruby client for Carrot2
70
- email:
71
- - andrew@chartkick.com
69
+ description:
70
+ email: andrew@chartkick.com
72
71
  executables: []
73
72
  extensions: []
74
73
  extra_rdoc_files: []
75
74
  files:
76
- - ".gitignore"
77
75
  - CHANGELOG.md
78
- - Gemfile
79
- - LICENSE
76
+ - LICENSE.txt
80
77
  - README.md
81
- - Rakefile
82
- - carrot2.gemspec
83
78
  - lib/carrot2.rb
84
79
  - lib/carrot2/version.rb
85
- - test/carrot2_test.rb
86
- - test/test_helper.rb
87
80
  homepage: https://github.com/ankane/carrot2
88
- licenses: []
81
+ licenses:
82
+ - MIT
89
83
  metadata: {}
90
84
  post_install_message:
91
85
  rdoc_options: []
@@ -95,18 +89,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
95
89
  requirements:
96
90
  - - ">="
97
91
  - !ruby/object:Gem::Version
98
- version: '0'
92
+ version: '2.4'
99
93
  required_rubygems_version: !ruby/object:Gem::Requirement
100
94
  requirements:
101
95
  - - ">="
102
96
  - !ruby/object:Gem::Version
103
97
  version: '0'
104
98
  requirements: []
105
- rubyforge_project:
106
- rubygems_version: 2.6.8
99
+ rubygems_version: 3.0.3
107
100
  signing_key:
108
101
  specification_version: 4
109
102
  summary: Ruby client for Carrot2
110
- test_files:
111
- - test/carrot2_test.rb
112
- - test/test_helper.rb
103
+ test_files: []
data/.gitignore DELETED
@@ -1,17 +0,0 @@
1
- *.gem
2
- *.rbc
3
- .bundle
4
- .config
5
- .yardoc
6
- Gemfile.lock
7
- InstalledFiles
8
- _yardoc
9
- coverage
10
- doc/
11
- lib/bundler/man
12
- pkg
13
- rdoc
14
- spec/reports
15
- test/tmp
16
- test/version_tmp
17
- tmp
data/Gemfile DELETED
@@ -1,4 +0,0 @@
1
- source "https://rubygems.org"
2
-
3
- # Specify your gem's dependencies in carrot2.gemspec
4
- gemspec
data/Rakefile DELETED
@@ -1,9 +0,0 @@
1
- require "bundler/gem_tasks"
2
- require "rake/testtask"
3
-
4
- task default: :test
5
- Rake::TestTask.new do |t|
6
- t.libs << "test"
7
- t.pattern = "test/**/*_test.rb"
8
- t.warning = false
9
- end
data/carrot2.gemspec DELETED
@@ -1,23 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
- require File.expand_path("../lib/carrot2/version", __FILE__)
3
-
4
- Gem::Specification.new do |spec|
5
- spec.authors = ["Andrew Kane"]
6
- spec.email = ["andrew@chartkick.com"]
7
- spec.description = "Ruby client for Carrot2"
8
- spec.summary = "Ruby client for Carrot2"
9
- spec.homepage = "https://github.com/ankane/carrot2"
10
-
11
- spec.files = `git ls-files`.split($OUTPUT_RECORD_SEPARATOR)
12
- spec.executables = spec.files.grep(%r{^exe/}).map { |f| File.basename(f) }
13
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
14
- spec.name = "carrot2"
15
- spec.require_paths = ["lib"]
16
- spec.version = Carrot2::VERSION
17
-
18
- spec.add_dependency "builder"
19
-
20
- spec.add_development_dependency "bundler"
21
- spec.add_development_dependency "rake"
22
- spec.add_development_dependency "minitest"
23
- end
data/test/carrot2_test.rb DELETED
@@ -1,23 +0,0 @@
1
- require_relative "test_helper"
2
-
3
- class Carrot2Test < Minitest::Test
4
- def test_cluster
5
- documents = [
6
- "Sign up for an exclusive coupon.",
7
- "Exclusive members get a free coupon.",
8
- "Coupons are going fast.",
9
- "This is completely unrelated to the other documents."
10
- ]
11
-
12
- assert_equal ["Coupon", "Exclusive", "Other Topics"], carrot2.cluster(documents)["clusters"].map { |c| c["phrases"].first }
13
- end
14
-
15
- def test_bad_request
16
- error = assert_raises(Carrot2::Error) { carrot2.request({}) }
17
- assert_includes error.message, "Error 400"
18
- end
19
-
20
- def carrot2
21
- @carrot2 ||= Carrot2.new
22
- end
23
- end
data/test/test_helper.rb DELETED
@@ -1,6 +0,0 @@
1
- require "bundler/setup"
2
- Bundler.require(:default)
3
- require "minitest/autorun"
4
- require "minitest/pride"
5
-
6
- Minitest::Test = Minitest::Unit::TestCase unless defined?(Minitest::Test)