carrot2 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +8 -0
- data/Gemfile +1 -1
- data/README.md +36 -11
- data/Rakefile +8 -1
- data/carrot2.gemspec +19 -15
- data/lib/carrot2.rb +9 -7
- data/lib/carrot2/version.rb +1 -1
- data/test/carrot2_test.rb +15 -0
- data/test/test_helper.rb +6 -0
- metadata +62 -27
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: df9af6b5e399ac7f765c9d63d868c75414e0ff0a
|
4
|
+
data.tar.gz: 86addac3d8e7f071be5c04c3bd23d67ddb472acd
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e7606bd9caf52138a4e25f50d0019495bd8a9fc9ec7c0a79ca85789a8869a2490ff6275d2f72dca160a78c4cb5056bd5c317255416f5fe308e74259822b4570e
|
7
|
+
data.tar.gz: ec8b17439d0a30259d6791cd5d2f287f03e36f485457e1551038925e43c76bc146a6ecb16ed1de4bbddbb3e0c34c2c276244503e52dd49c505c2efc22d165d04
|
data/CHANGELOG.md
ADDED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,14 +1,20 @@
|
|
1
1
|
# Carrot2
|
2
2
|
|
3
|
-
Ruby client for Carrot2 - the
|
3
|
+
Ruby client for [Carrot2](http://project.carrot2.org/) - the open-source document clustering server
|
4
4
|
|
5
|
-
##
|
5
|
+
## Installation
|
6
6
|
|
7
|
-
|
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`.
|
8
|
+
|
9
|
+
Then add this line to your application’s Gemfile:
|
8
10
|
|
9
11
|
```ruby
|
10
|
-
|
12
|
+
gem 'carrot2'
|
13
|
+
```
|
11
14
|
|
15
|
+
## How to Use
|
16
|
+
|
17
|
+
```ruby
|
12
18
|
documents = [
|
13
19
|
"Sign up for an exclusive coupon.",
|
14
20
|
"Exclusive members get a free coupon.",
|
@@ -58,16 +64,35 @@ returns
|
|
58
64
|
|
59
65
|
Documents are numbered in the order provided, starting with 0.
|
60
66
|
|
61
|
-
To specify the Carrot2
|
67
|
+
To specify the Carrot2 server, set `ENV["CARROT2_URL"]` or use:
|
62
68
|
|
63
69
|
```ruby
|
64
|
-
|
70
|
+
Carrot2.new(url: "http://localhost:8080")
|
65
71
|
```
|
66
72
|
|
73
|
+
## Heroku
|
74
|
+
|
75
|
+
Carrot2 can be easily deployed to Heroku thanks to support for [WAR deployment](https://devcenter.heroku.com/articles/war-deployment).
|
76
|
+
|
77
|
+
You can find the `.war` file in the `war` directory in the dcs download. Then run:
|
78
|
+
|
79
|
+
```sh
|
80
|
+
heroku plugins:install heroku-cli-deploy
|
81
|
+
heroku create <app_name>
|
82
|
+
heroku war:deploy carrot2-dcs.war --app <app_name>
|
83
|
+
```
|
84
|
+
|
85
|
+
And set `ENV["CARROT2_URL"]` in your application.
|
86
|
+
|
87
|
+
## History
|
88
|
+
|
89
|
+
View the [changelog](https://github.com/ankane/carrot2/blob/master/CHANGELOG.md)
|
90
|
+
|
67
91
|
## Contributing
|
68
92
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
93
|
+
Everyone is encouraged to help improve this project. Here are a few ways you can help:
|
94
|
+
|
95
|
+
- [Report bugs](https://github.com/ankane/carrot2/issues)
|
96
|
+
- Fix bugs and [submit pull requests](https://github.com/ankane/carrot2/pulls)
|
97
|
+
- Write, clarify, or fix documentation
|
98
|
+
- Suggest or add new features
|
data/Rakefile
CHANGED
data/carrot2.gemspec
CHANGED
@@ -1,20 +1,24 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
require File.expand_path(
|
2
|
+
require File.expand_path("../lib/carrot2/version", __FILE__)
|
3
3
|
|
4
|
-
Gem::Specification.new do |
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
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
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
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
17
|
|
18
|
-
|
19
|
-
|
18
|
+
spec.add_dependency "builder"
|
19
|
+
spec.add_dependency "rest-client"
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "minitest"
|
20
24
|
end
|
data/lib/carrot2.rb
CHANGED
@@ -4,14 +4,16 @@ require "rest-client"
|
|
4
4
|
require "json"
|
5
5
|
|
6
6
|
class Carrot2
|
7
|
+
def initialize(url: nil)
|
8
|
+
@url = url || ENV["CARROT2_URL"] || "http://localhost:8080"
|
7
9
|
|
8
|
-
|
9
|
-
@
|
10
|
+
# add dcs/rest
|
11
|
+
@url = "#{@url.sub(/\/\z/, "")}/dcs/rest"
|
10
12
|
end
|
11
13
|
|
12
|
-
def cluster(documents)
|
14
|
+
def cluster(documents, opts = {})
|
13
15
|
xml = Builder::XmlMarkup.new
|
14
|
-
xml.instruct! :xml, :version=>"1.0", :encoding=>"UTF-8"
|
16
|
+
xml.instruct! :xml, :version => "1.0", :encoding => "UTF-8"
|
15
17
|
xml.searchresult do |s|
|
16
18
|
documents.each do |document|
|
17
19
|
s.document do |d|
|
@@ -24,14 +26,14 @@ class Carrot2
|
|
24
26
|
"dcs.output.format" => "JSON",
|
25
27
|
"dcs.clusters.only" => true,
|
26
28
|
"dcs.c2stream" => xml.target!,
|
27
|
-
|
29
|
+
"MultilingualClustering.defaultLanguage" => opts[:language] || "ENGLISH",
|
30
|
+
multipart: true
|
28
31
|
}
|
29
|
-
response = RestClient.post
|
32
|
+
response = RestClient.post(@url, params) { |response, request, result| response }
|
30
33
|
if response.code == 200
|
31
34
|
JSON.parse(response.body)
|
32
35
|
else
|
33
36
|
raise "Bad response code from Carrot2 server: #{response.code}"
|
34
37
|
end
|
35
38
|
end
|
36
|
-
|
37
39
|
end
|
data/lib/carrot2/version.rb
CHANGED
@@ -0,0 +1,15 @@
|
|
1
|
+
require_relative "test_helper"
|
2
|
+
|
3
|
+
class Carrot2Test < Minitest::Test
|
4
|
+
def test_basic
|
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
|
+
carrot2 = Carrot2.new
|
13
|
+
assert_equal ["Coupon", "Exclusive", "Other Topics"], carrot2.cluster(documents)["clusters"].map { |c| c["phrases"].first }
|
14
|
+
end
|
15
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
CHANGED
@@ -1,56 +1,94 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: carrot2
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
5
|
-
prerelease:
|
4
|
+
version: 0.1.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Andrew Kane
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2017-01-18 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: builder
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - ">="
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '0'
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - ">="
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: '0'
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: rest-client
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- -
|
31
|
+
- - ">="
|
36
32
|
- !ruby/object:Gem::Version
|
37
33
|
version: '0'
|
38
34
|
type: :runtime
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- -
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: minitest
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
44
81
|
- !ruby/object:Gem::Version
|
45
82
|
version: '0'
|
46
83
|
description: Ruby client for Carrot2
|
47
84
|
email:
|
48
|
-
-
|
85
|
+
- andrew@chartkick.com
|
49
86
|
executables: []
|
50
87
|
extensions: []
|
51
88
|
extra_rdoc_files: []
|
52
89
|
files:
|
53
|
-
- .gitignore
|
90
|
+
- ".gitignore"
|
91
|
+
- CHANGELOG.md
|
54
92
|
- Gemfile
|
55
93
|
- LICENSE
|
56
94
|
- README.md
|
@@ -58,34 +96,31 @@ files:
|
|
58
96
|
- carrot2.gemspec
|
59
97
|
- lib/carrot2.rb
|
60
98
|
- lib/carrot2/version.rb
|
61
|
-
|
99
|
+
- test/carrot2_test.rb
|
100
|
+
- test/test_helper.rb
|
101
|
+
homepage: https://github.com/ankane/carrot2
|
62
102
|
licenses: []
|
103
|
+
metadata: {}
|
63
104
|
post_install_message:
|
64
105
|
rdoc_options: []
|
65
106
|
require_paths:
|
66
107
|
- lib
|
67
108
|
required_ruby_version: !ruby/object:Gem::Requirement
|
68
|
-
none: false
|
69
109
|
requirements:
|
70
|
-
- -
|
110
|
+
- - ">="
|
71
111
|
- !ruby/object:Gem::Version
|
72
112
|
version: '0'
|
73
|
-
segments:
|
74
|
-
- 0
|
75
|
-
hash: 389504047466366044
|
76
113
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
77
|
-
none: false
|
78
114
|
requirements:
|
79
|
-
- -
|
115
|
+
- - ">="
|
80
116
|
- !ruby/object:Gem::Version
|
81
117
|
version: '0'
|
82
|
-
segments:
|
83
|
-
- 0
|
84
|
-
hash: 389504047466366044
|
85
118
|
requirements: []
|
86
119
|
rubyforge_project:
|
87
|
-
rubygems_version:
|
120
|
+
rubygems_version: 2.6.8
|
88
121
|
signing_key:
|
89
|
-
specification_version:
|
122
|
+
specification_version: 4
|
90
123
|
summary: Ruby client for Carrot2
|
91
|
-
test_files:
|
124
|
+
test_files:
|
125
|
+
- test/carrot2_test.rb
|
126
|
+
- test/test_helper.rb
|