carrot2 0.0.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.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +73 -0
- data/Rakefile +2 -0
- data/carrot2.gemspec +20 -0
- data/lib/carrot2.rb +37 -0
- data/lib/carrot2/version.rb +3 -0
- metadata +91 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Andrew Kane
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
# Carrot2
|
2
|
+
|
3
|
+
Ruby client for Carrot2 - the **awesome** open-source document clustering server
|
4
|
+
|
5
|
+
## Usage
|
6
|
+
|
7
|
+
Download and run the Carrot2 server. [Great instructions here](http://project.carrot2.org/download-dcs.html)
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
require "carrot2"
|
11
|
+
|
12
|
+
documents = [
|
13
|
+
"Sign up for an exclusive coupon.",
|
14
|
+
"Exclusive members get a free coupon.",
|
15
|
+
"Coupons are going fast.",
|
16
|
+
"This is completely unrelated to the other documents."
|
17
|
+
]
|
18
|
+
|
19
|
+
carrot2 = Carrot2.new
|
20
|
+
carrot2.cluster(documents)
|
21
|
+
```
|
22
|
+
|
23
|
+
returns
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
{
|
27
|
+
"processing-time-total"=>1,
|
28
|
+
"clusters"=> [
|
29
|
+
{
|
30
|
+
"id"=>0,
|
31
|
+
"size"=>3,
|
32
|
+
"phrases"=>["Coupon"],
|
33
|
+
"score"=>0.06462323710740674,
|
34
|
+
"documents"=>[0, 1, 2],
|
35
|
+
"attributes"=>{"score"=>0.06462323710740674}
|
36
|
+
},
|
37
|
+
{
|
38
|
+
"id"=>1,
|
39
|
+
"size"=>2,
|
40
|
+
"phrases"=>["Exclusive"],
|
41
|
+
"score"=>0.05873148311034013,
|
42
|
+
"documents"=>[0, 1],
|
43
|
+
"attributes"=>{"score"=>0.05873148311034013}
|
44
|
+
},
|
45
|
+
{
|
46
|
+
"id"=>2,
|
47
|
+
"size"=>1,
|
48
|
+
"phrases"=>["Other Topics"],
|
49
|
+
"score"=>0.0,
|
50
|
+
"documents"=>[3],
|
51
|
+
"attributes"=>{"other-topics"=>true, "score"=>0.0}
|
52
|
+
}
|
53
|
+
],
|
54
|
+
"processing-time-algorithm"=>1,
|
55
|
+
"query"=>nil
|
56
|
+
}
|
57
|
+
```
|
58
|
+
|
59
|
+
Documents are numbered in the order provided, starting with 0.
|
60
|
+
|
61
|
+
To specify the Carrot2 endpoint, use
|
62
|
+
|
63
|
+
```ruby
|
64
|
+
carrot2 = Carrot2.new("http://localhost:8080/dcs/rest") # default
|
65
|
+
```
|
66
|
+
|
67
|
+
## Contributing
|
68
|
+
|
69
|
+
1. Fork it
|
70
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
71
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
72
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
73
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/carrot2.gemspec
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/carrot2/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Andrew Kane"]
|
6
|
+
gem.email = ["acekane1@gmail.com"]
|
7
|
+
gem.description = %q{Ruby client for Carrot2}
|
8
|
+
gem.summary = %q{Ruby client for Carrot2}
|
9
|
+
gem.homepage = ""
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "carrot2"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = Carrot2::VERSION
|
17
|
+
|
18
|
+
gem.add_dependency "builder"
|
19
|
+
gem.add_dependency "rest-client"
|
20
|
+
end
|
data/lib/carrot2.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
require "carrot2/version"
|
2
|
+
require "builder"
|
3
|
+
require "rest-client"
|
4
|
+
require "json"
|
5
|
+
|
6
|
+
class Carrot2
|
7
|
+
|
8
|
+
def initialize(endpoint = "http://localhost:8080/dcs/rest")
|
9
|
+
@endpoint = endpoint
|
10
|
+
end
|
11
|
+
|
12
|
+
def cluster(documents)
|
13
|
+
xml = Builder::XmlMarkup.new
|
14
|
+
xml.instruct! :xml, :version=>"1.0", :encoding=>"UTF-8"
|
15
|
+
xml.searchresult do |s|
|
16
|
+
documents.each do |document|
|
17
|
+
s.document do |d|
|
18
|
+
d.title document
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
params = {
|
24
|
+
"dcs.output.format" => "JSON",
|
25
|
+
"dcs.clusters.only" => true,
|
26
|
+
"dcs.c2stream" => xml.target!,
|
27
|
+
:multipart => true
|
28
|
+
}
|
29
|
+
response = RestClient.post @endpoint, params
|
30
|
+
if response.code == 200
|
31
|
+
JSON.parse(response.body)
|
32
|
+
else
|
33
|
+
raise "Bad response code from Carrot2 server: #{response.code}"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
metadata
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: carrot2
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Andrew Kane
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-06-21 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: builder
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rest-client
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
description: Ruby client for Carrot2
|
47
|
+
email:
|
48
|
+
- acekane1@gmail.com
|
49
|
+
executables: []
|
50
|
+
extensions: []
|
51
|
+
extra_rdoc_files: []
|
52
|
+
files:
|
53
|
+
- .gitignore
|
54
|
+
- Gemfile
|
55
|
+
- LICENSE
|
56
|
+
- README.md
|
57
|
+
- Rakefile
|
58
|
+
- carrot2.gemspec
|
59
|
+
- lib/carrot2.rb
|
60
|
+
- lib/carrot2/version.rb
|
61
|
+
homepage: ''
|
62
|
+
licenses: []
|
63
|
+
post_install_message:
|
64
|
+
rdoc_options: []
|
65
|
+
require_paths:
|
66
|
+
- lib
|
67
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
68
|
+
none: false
|
69
|
+
requirements:
|
70
|
+
- - ! '>='
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
segments:
|
74
|
+
- 0
|
75
|
+
hash: 389504047466366044
|
76
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
77
|
+
none: false
|
78
|
+
requirements:
|
79
|
+
- - ! '>='
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
segments:
|
83
|
+
- 0
|
84
|
+
hash: 389504047466366044
|
85
|
+
requirements: []
|
86
|
+
rubyforge_project:
|
87
|
+
rubygems_version: 1.8.23
|
88
|
+
signing_key:
|
89
|
+
specification_version: 3
|
90
|
+
summary: Ruby client for Carrot2
|
91
|
+
test_files: []
|