red-datasets 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.yardopts +6 -0
- data/Gemfile +5 -0
- data/LICENSE.txt +7 -0
- data/README.md +42 -0
- data/Rakefile +21 -0
- data/doc/text/news.md +7 -0
- data/lib/datasets/dataset.rb +42 -0
- data/lib/datasets/iris.rb +55 -0
- data/lib/datasets/metadata.rb +14 -0
- data/lib/datasets/version.rb +3 -0
- data/lib/datasets.rb +3 -0
- data/red-datasets.gemspec +42 -0
- data/test/helper.rb +3 -0
- data/test/run-test.rb +16 -0
- data/test/test-iris.rb +32 -0
- metadata +137 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 21e6ccf743e4603d55a8c628213d3e8278b4c9a29f4914887cc4f148065e6edc
|
4
|
+
data.tar.gz: 5d45f1ed6e5e2ec6620243641322323b78d22bb52c1f06ed3b0a0fe2555a7dd7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 791bb9a4953a6c7667e95ff8b479180e91ce25f4f090a55a119118884caf59482ec6cff3993486427e85156228041c2ece0734312210079a7a057067d709d277
|
7
|
+
data.tar.gz: 8f76e7a5d781d85767d1b476dac26e9b954d556e9e54d689b1cdbe0f881a8f165b6188cce072857b19b3f7c5f57537b82b962fb7c74a35102aad396cb9617ddd
|
data/.yardopts
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
Copyright 2017 Kouhei Sutou <kou@clear-code.com>
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
4
|
+
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
6
|
+
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
# README
|
2
|
+
|
3
|
+
## Name
|
4
|
+
|
5
|
+
Red Datasets
|
6
|
+
|
7
|
+
## Description
|
8
|
+
|
9
|
+
Red Datasets provides classes that provide common datasets such as iris dataset.
|
10
|
+
|
11
|
+
You can use datasets easily because you can access each dataset with multiple ways such as `#each` and Apache Arrow Record Batch.
|
12
|
+
|
13
|
+
## Install
|
14
|
+
|
15
|
+
```console
|
16
|
+
% gem install red-datasets
|
17
|
+
```
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
Here is an example to access iris dataset by `#each`:
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
require "datasets"
|
25
|
+
|
26
|
+
iris = Datasets::Iris.new
|
27
|
+
iris.each do |record|
|
28
|
+
p [
|
29
|
+
record.sepal_length,
|
30
|
+
record.sepal_width,
|
31
|
+
record.petal_length,
|
32
|
+
record.petal_width,
|
33
|
+
record.class,
|
34
|
+
]
|
35
|
+
# [5.1, 3.5, 1.4, 0.2, "Iris-setosa"]
|
36
|
+
# [7.0, 3.2, 4.7, 1.4, "Iris-versicolor"]
|
37
|
+
end
|
38
|
+
```
|
39
|
+
|
40
|
+
## License
|
41
|
+
|
42
|
+
The MIT license. See `LICENSE.txt` for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
|
3
|
+
require "rubygems"
|
4
|
+
require "bundler/gem_helper"
|
5
|
+
|
6
|
+
base_dir = File.join(File.dirname(__FILE__))
|
7
|
+
|
8
|
+
helper = Bundler::GemHelper.new(base_dir)
|
9
|
+
def helper.version_tag
|
10
|
+
version
|
11
|
+
end
|
12
|
+
|
13
|
+
helper.install
|
14
|
+
spec = helper.gemspec
|
15
|
+
|
16
|
+
desc "Run tests"
|
17
|
+
task :test do
|
18
|
+
ruby("test/run-test.rb")
|
19
|
+
end
|
20
|
+
|
21
|
+
task default: :test
|
data/doc/text/news.md
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
require "fileutils"
|
2
|
+
require "open-uri"
|
3
|
+
require "pathname"
|
4
|
+
|
5
|
+
require_relative "metadata"
|
6
|
+
|
7
|
+
module Datasets
|
8
|
+
class Dataset
|
9
|
+
attr_reader :metadata
|
10
|
+
def initialize
|
11
|
+
@metadata = Metadata.new
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
def cache_dir_path
|
16
|
+
case RUBY_PLATFORM
|
17
|
+
when /mswin/, /mingw/
|
18
|
+
base_dir = ENV["LOCALAPPDATA"] || "~/AppData"
|
19
|
+
when /darwin/
|
20
|
+
base_dir = "~/Library/Caches"
|
21
|
+
else
|
22
|
+
base_dir = ENV["XDG_CACHE_HOME"] || "~/.cache"
|
23
|
+
end
|
24
|
+
Pathname(base_dir).expand_path + "red-datasets" + metadata.name
|
25
|
+
end
|
26
|
+
|
27
|
+
def download(output_path, url)
|
28
|
+
url = URI.parse(url) unless url.is_a?(URI::Generic)
|
29
|
+
output_path.parent.mkpath
|
30
|
+
begin
|
31
|
+
url.open do |input|
|
32
|
+
output_path.open("wb") do |output|
|
33
|
+
IO.copy_stream(input, output)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
rescue
|
37
|
+
FileUtils.rm_f(output_path)
|
38
|
+
raise
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require "csv"
|
2
|
+
|
3
|
+
require_relative "dataset"
|
4
|
+
|
5
|
+
module Datasets
|
6
|
+
class Iris < Dataset
|
7
|
+
Record = Struct.new(:sepal_length,
|
8
|
+
:sepal_width,
|
9
|
+
:petal_length,
|
10
|
+
:petal_width,
|
11
|
+
:class)
|
12
|
+
|
13
|
+
def initialize
|
14
|
+
super()
|
15
|
+
@metadata.name = "iris"
|
16
|
+
@metadata.url = "https://archive.ics.uci.edu/ml/datasets/Iris"
|
17
|
+
@metadata.description = lambda do
|
18
|
+
read_names
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def each
|
23
|
+
return to_enum(__method__) unless block_given?
|
24
|
+
|
25
|
+
open_data do |csv|
|
26
|
+
csv.each do |row|
|
27
|
+
next if row[0].nil?
|
28
|
+
record = Record.new(*row)
|
29
|
+
yield(record)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
def open_data
|
36
|
+
data_path = cache_dir_path + "iris.csv"
|
37
|
+
unless data_path.exist?
|
38
|
+
data_url = "https://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data"
|
39
|
+
download(data_path, data_url)
|
40
|
+
end
|
41
|
+
CSV.open(data_path, converters: [:numeric]) do |csv|
|
42
|
+
yield(csv)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def read_names
|
47
|
+
names_path = cache_dir_path + "iris.names"
|
48
|
+
unless names_path.exist?
|
49
|
+
names_url = "https://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.names"
|
50
|
+
download(names_path, names_url)
|
51
|
+
end
|
52
|
+
names_path.read
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Datasets
|
2
|
+
class Metadata < Struct.new(:name,
|
3
|
+
:url,
|
4
|
+
:license,
|
5
|
+
:description)
|
6
|
+
def description
|
7
|
+
description_raw = super
|
8
|
+
if description_raw.respond_to?(:call)
|
9
|
+
self.description = description_raw = description_raw.call
|
10
|
+
end
|
11
|
+
description_raw
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/lib/datasets.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
|
3
|
+
clean_white_space = lambda do |entry|
|
4
|
+
entry.gsub(/(\A\n+|\n+\z)/, '') + "\n"
|
5
|
+
end
|
6
|
+
|
7
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "lib"))
|
8
|
+
require "datasets/version"
|
9
|
+
|
10
|
+
Gem::Specification.new do |spec|
|
11
|
+
spec.name = "red-datasets"
|
12
|
+
spec.version = Datasets::VERSION
|
13
|
+
spec.homepage = "https://github.com/red-data-tools/red-datasets"
|
14
|
+
spec.authors = ["tomisuker", "Kouhei Sutou"]
|
15
|
+
spec.email = ["tomisuker16@gmail.com", "kou@clear-code.com"]
|
16
|
+
|
17
|
+
readme = File.read("README.md")
|
18
|
+
readme.force_encoding("UTF-8")
|
19
|
+
entries = readme.split(/^\#\#\s(.*)$/)
|
20
|
+
clean_white_space.call(entries[entries.index("Description") + 1])
|
21
|
+
description = clean_white_space.call(entries[entries.index("Description") + 1])
|
22
|
+
spec.summary, spec.description, = description.split(/\n\n+/, 3)
|
23
|
+
spec.license = "MIT"
|
24
|
+
spec.files = [
|
25
|
+
"README.md",
|
26
|
+
"LICENSE.txt",
|
27
|
+
"Rakefile",
|
28
|
+
"Gemfile",
|
29
|
+
"#{spec.name}.gemspec",
|
30
|
+
]
|
31
|
+
spec.files += [".yardopts"]
|
32
|
+
spec.files += Dir.glob("lib/**/*.rb")
|
33
|
+
spec.files += Dir.glob("image/*.*")
|
34
|
+
spec.files += Dir.glob("doc/text/*")
|
35
|
+
spec.test_files += Dir.glob("test/**/*")
|
36
|
+
|
37
|
+
spec.add_development_dependency("bundler")
|
38
|
+
spec.add_development_dependency("rake")
|
39
|
+
spec.add_development_dependency("test-unit")
|
40
|
+
spec.add_development_dependency("yard")
|
41
|
+
spec.add_development_dependency("kramdown")
|
42
|
+
end
|
data/test/helper.rb
ADDED
data/test/run-test.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$VERBOSE = true
|
4
|
+
|
5
|
+
require "pathname"
|
6
|
+
|
7
|
+
base_dir = Pathname.new(__FILE__).dirname.parent.expand_path
|
8
|
+
|
9
|
+
lib_dir = base_dir + "lib"
|
10
|
+
test_dir = base_dir + "test"
|
11
|
+
|
12
|
+
$LOAD_PATH.unshift(lib_dir.to_s)
|
13
|
+
|
14
|
+
require_relative "helper"
|
15
|
+
|
16
|
+
exit(Test::Unit::AutoRunner.run(true, test_dir.to_s))
|
data/test/test-iris.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
class IrisTest < Test::Unit::TestCase
|
2
|
+
def setup
|
3
|
+
@dataset = Datasets::Iris.new
|
4
|
+
end
|
5
|
+
|
6
|
+
def record(*args)
|
7
|
+
Datasets::Iris::Record.new(*args)
|
8
|
+
end
|
9
|
+
|
10
|
+
test("#each") do
|
11
|
+
records = @dataset.each.to_a
|
12
|
+
assert_equal([
|
13
|
+
150,
|
14
|
+
record(5.1, 3.5, 1.4, 0.2, "Iris-setosa"),
|
15
|
+
record(5.9, 3.0, 5.1, 1.8, "Iris-virginica"),
|
16
|
+
],
|
17
|
+
[
|
18
|
+
records.size,
|
19
|
+
records[0],
|
20
|
+
records[-1],
|
21
|
+
])
|
22
|
+
end
|
23
|
+
|
24
|
+
sub_test_case("#metadata") do
|
25
|
+
test("#description") do
|
26
|
+
description = @dataset.metadata.description
|
27
|
+
assert do
|
28
|
+
description.start_with?("1. Title: Iris Plants Database")
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
metadata
ADDED
@@ -0,0 +1,137 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: red-datasets
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- tomisuker
|
8
|
+
- Kouhei Sutou
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2018-01-08 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ">="
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '0'
|
21
|
+
type: :development
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '0'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: rake
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: test-unit
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: yard
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: kramdown
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
description: 'You can use datasets easily because you can access each dataset with
|
85
|
+
multiple ways such as `#each` and Apache Arrow Record Batch.
|
86
|
+
|
87
|
+
'
|
88
|
+
email:
|
89
|
+
- tomisuker16@gmail.com
|
90
|
+
- kou@clear-code.com
|
91
|
+
executables: []
|
92
|
+
extensions: []
|
93
|
+
extra_rdoc_files: []
|
94
|
+
files:
|
95
|
+
- ".yardopts"
|
96
|
+
- Gemfile
|
97
|
+
- LICENSE.txt
|
98
|
+
- README.md
|
99
|
+
- Rakefile
|
100
|
+
- doc/text/news.md
|
101
|
+
- lib/datasets.rb
|
102
|
+
- lib/datasets/dataset.rb
|
103
|
+
- lib/datasets/iris.rb
|
104
|
+
- lib/datasets/metadata.rb
|
105
|
+
- lib/datasets/version.rb
|
106
|
+
- red-datasets.gemspec
|
107
|
+
- test/helper.rb
|
108
|
+
- test/run-test.rb
|
109
|
+
- test/test-iris.rb
|
110
|
+
homepage: https://github.com/red-data-tools/red-datasets
|
111
|
+
licenses:
|
112
|
+
- MIT
|
113
|
+
metadata: {}
|
114
|
+
post_install_message:
|
115
|
+
rdoc_options: []
|
116
|
+
require_paths:
|
117
|
+
- lib
|
118
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
119
|
+
requirements:
|
120
|
+
- - ">="
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: '0'
|
123
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
124
|
+
requirements:
|
125
|
+
- - ">="
|
126
|
+
- !ruby/object:Gem::Version
|
127
|
+
version: '0'
|
128
|
+
requirements: []
|
129
|
+
rubyforge_project:
|
130
|
+
rubygems_version: 2.7.4
|
131
|
+
signing_key:
|
132
|
+
specification_version: 4
|
133
|
+
summary: Red Datasets provides classes that provide common datasets such as iris dataset.
|
134
|
+
test_files:
|
135
|
+
- test/test-iris.rb
|
136
|
+
- test/run-test.rb
|
137
|
+
- test/helper.rb
|