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 +5 -5
- data/CHANGELOG.md +4 -0
- data/{LICENSE → LICENSE.txt} +0 -0
- data/README.md +16 -2
- data/lib/carrot2.rb +19 -4
- data/lib/carrot2/version.rb +1 -1
- metadata +10 -19
- data/.gitignore +0 -17
- data/Gemfile +0 -4
- data/Rakefile +0 -9
- data/carrot2.gemspec +0 -23
- data/test/carrot2_test.rb +0 -23
- data/test/test_helper.rb +0 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 73489263c06ae2b8e9f7509570c35c052635340d8401f04d659fe4080188b049
|
4
|
+
data.tar.gz: 891c4d26486b4c39c1cdff7756bb97faea0ff01ae5aceaa8082ed122d4300f6c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 30e723899e33b4ce32463b52a65b24ac1f1a1fc7a39fec038dfd95c5fad7cdf0bb78555e24fdeff18657905ca194fcc59afded05dc292cfcb06ca7aa919eca59
|
7
|
+
data.tar.gz: 1dae126a035baf128cc7e4ec265259056e1817694b2a61317edc339f4b193a1f0b81c4f08bc80a8d98fda28dd69f4ef12be75f30d2450be55654f33ee8085927
|
data/CHANGELOG.md
CHANGED
data/{LICENSE → LICENSE.txt}
RENAMED
File without changes
|
data/README.md
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
# Carrot2
|
2
2
|
|
3
|
-
Ruby client for [Carrot2](
|
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](
|
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: "
|
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
|
-
|
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
|
data/lib/carrot2/version.rb
CHANGED
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.
|
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:
|
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:
|
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
|
-
-
|
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: '
|
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
|
-
|
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
data/Gemfile
DELETED
data/Rakefile
DELETED
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
|