parsley-store 0.1.0
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/.document +5 -0
- data/.gitignore +21 -0
- data/LICENSE +20 -0
- data/README.rdoc +32 -0
- data/Rakefile +59 -0
- data/VERSION +1 -0
- data/bin/parsley-store +3 -0
- data/features/parsley-store.feature +14 -0
- data/features/step_definitions/parsley-store_steps.rb +37 -0
- data/features/support/env.rb +4 -0
- data/lib/parsley-store.rb +28 -0
- data/spec/parsley-store_spec.rb +7 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +11 -0
- metadata +139 -0
data/.document
ADDED
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Dmitry Mozzherin
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
= parsley-store
|
2
|
+
|
3
|
+
This gem allows to dramatically increase speed of 'parsing' scientific names.
|
4
|
+
It stores parsed strings in Redis database and does not repeat work already done
|
5
|
+
|
6
|
+
== Installation
|
7
|
+
|
8
|
+
Make sure you have Redis installed on your localhost
|
9
|
+
|
10
|
+
gem install parsley-store
|
11
|
+
|
12
|
+
== Usage
|
13
|
+
|
14
|
+
parser = ParsleyStore.new
|
15
|
+
parser.parse('Homo sapiens sapiens Linn. 1758)
|
16
|
+
parser.parse('Homo sapiens sapiens Linn. 1758)
|
17
|
+
|
18
|
+
The second parse must be much faster!
|
19
|
+
|
20
|
+
== Note on Patches/Pull Requests
|
21
|
+
|
22
|
+
* Fork the project.
|
23
|
+
* Make your feature addition or bug fix.
|
24
|
+
* Add tests for it. This is important so I don't break it in a
|
25
|
+
future version unintentionally.
|
26
|
+
* Commit, do not mess with rakefile, version, or history.
|
27
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
28
|
+
* Send me a pull request. Bonus points for topic branches.
|
29
|
+
|
30
|
+
== Copyright
|
31
|
+
|
32
|
+
Copyright (c) 2010 Dmitry Mozzherin. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "parsley-store"
|
8
|
+
gem.summary = %Q{Scientific Names Parser with Cached Results}
|
9
|
+
gem.description = %Q{Scientific names parser/atomizer with cached distributed storage of atomized data}
|
10
|
+
gem.email = "dmozzherin@gmail.com"
|
11
|
+
gem.homepage = "http://github.com/GlobalNamesArchitecture/parsley-store"
|
12
|
+
gem.authors = ["Dmitry Mozzherin"]
|
13
|
+
gem.add_development_dependency "rspec", ">= 1.2.9"
|
14
|
+
gem.add_development_dependency "cucumber", ">= 0"
|
15
|
+
gem.add_dependency "biodiversity"
|
16
|
+
gem.add_dependency "redis"
|
17
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
18
|
+
end
|
19
|
+
Jeweler::GemcutterTasks.new
|
20
|
+
rescue LoadError
|
21
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
22
|
+
end
|
23
|
+
|
24
|
+
require 'spec/rake/spectask'
|
25
|
+
Spec::Rake::SpecTask.new(:spec) do |spec|
|
26
|
+
spec.libs << 'lib' << 'spec'
|
27
|
+
spec.spec_files = FileList['spec/**/*_spec.rb']
|
28
|
+
end
|
29
|
+
|
30
|
+
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
31
|
+
spec.libs << 'lib' << 'spec'
|
32
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
33
|
+
spec.rcov = true
|
34
|
+
end
|
35
|
+
|
36
|
+
task :spec => :check_dependencies
|
37
|
+
|
38
|
+
begin
|
39
|
+
require 'cucumber/rake/task'
|
40
|
+
Cucumber::Rake::Task.new(:features)
|
41
|
+
|
42
|
+
task :features => :check_dependencies
|
43
|
+
rescue LoadError
|
44
|
+
task :features do
|
45
|
+
abort "Cucumber is not available. In order to run features, you must: sudo gem install cucumber"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
task :default => :spec
|
50
|
+
|
51
|
+
require 'rake/rdoctask'
|
52
|
+
Rake::RDocTask.new do |rdoc|
|
53
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
54
|
+
|
55
|
+
rdoc.rdoc_dir = 'rdoc'
|
56
|
+
rdoc.title = "parsley-store #{version}"
|
57
|
+
rdoc.rdoc_files.include('README*')
|
58
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
59
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/bin/parsley-store
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
Feature: Cached parsind of Scientific Names
|
2
|
+
In order to be able to parse scientific names super fast
|
3
|
+
A user should be able to parse and cache and retrieve results
|
4
|
+
So I want to implement Redis backend to a parser
|
5
|
+
|
6
|
+
Scenario: Connecting to local redis database
|
7
|
+
Given Redis server is running locally
|
8
|
+
Then I get "LOCAL" and "SLAVE" databases connection
|
9
|
+
|
10
|
+
Scenario: "Parsing a name by parser and from database"
|
11
|
+
Given a clean local database
|
12
|
+
When I parse a name "Homo sapiens sapiens (Linn.) 1758" two times
|
13
|
+
Then second parse should be much faster
|
14
|
+
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'socket'
|
2
|
+
|
3
|
+
Given /^Redis server is running locally$/ do
|
4
|
+
lambda do
|
5
|
+
socket = TCPSocket.open('localhost', 6379)
|
6
|
+
socket.close
|
7
|
+
end.should_not raise_error
|
8
|
+
@conn = Redis.new
|
9
|
+
end
|
10
|
+
|
11
|
+
Then /^I get "([^"]*)" and "([^"]*)" databases connection$/ do |local, slave|
|
12
|
+
@conn.select(eval("ParsleyStore::#{slave}")).should == "OK"
|
13
|
+
@conn.select(eval("ParsleyStore::#{local}")).should == "OK"
|
14
|
+
lambda { @conn.select(200) }.should raise_error
|
15
|
+
end
|
16
|
+
|
17
|
+
Given /^a clean local database$/ do
|
18
|
+
@conn = Redis.new
|
19
|
+
@conn.select(ParsleyStore::LOCAL)
|
20
|
+
@conn.flushdb
|
21
|
+
@conn.dbsize.should == 0
|
22
|
+
@parser = ParsleyStore.new
|
23
|
+
end
|
24
|
+
|
25
|
+
When /^I parse a name "([^"]*)" two times$/ do |name|
|
26
|
+
now = Time.now
|
27
|
+
res = @parser.parse(name)
|
28
|
+
@delta1 = Time.now - now
|
29
|
+
now = Time.now
|
30
|
+
res = @parser.parse(name)
|
31
|
+
@delta2 = Time.now - now
|
32
|
+
end
|
33
|
+
|
34
|
+
Then /^second parse should be much faster$/ do
|
35
|
+
(@delta1/@delta2).should > 10
|
36
|
+
end
|
37
|
+
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'redis'
|
2
|
+
require 'biodiversity'
|
3
|
+
|
4
|
+
|
5
|
+
class ParsleyStore
|
6
|
+
#database numbers for Redis
|
7
|
+
LOCAL = 1
|
8
|
+
SLAVE = 2
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
@parser = ScientificNameParser.new
|
12
|
+
@local = Redis.new
|
13
|
+
@local.select(LOCAL)
|
14
|
+
end
|
15
|
+
|
16
|
+
def parse(scientific_name)
|
17
|
+
stored = @local.get(scientific_name)
|
18
|
+
return stored if stored
|
19
|
+
begin
|
20
|
+
parsed = @parser.parse(scientific_name)
|
21
|
+
rescue
|
22
|
+
@parser = ScientificNameParser.new
|
23
|
+
parsed = @parser.parse(scientific_name)
|
24
|
+
end
|
25
|
+
@local.set scientific_name, parsed
|
26
|
+
parsed
|
27
|
+
end
|
28
|
+
end
|
data/spec/spec.opts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
2
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
3
|
+
require 'parsley-store'
|
4
|
+
require 'spec'
|
5
|
+
require 'spec/autorun'
|
6
|
+
|
7
|
+
puts "You need to start Redis server on your machine"
|
8
|
+
|
9
|
+
Spec::Runner.configure do |config|
|
10
|
+
|
11
|
+
end
|
metadata
ADDED
@@ -0,0 +1,139 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: parsley-store
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Dmitry Mozzherin
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-09-10 00:00:00 -04:00
|
19
|
+
default_executable: parsley-store
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: rspec
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 13
|
30
|
+
segments:
|
31
|
+
- 1
|
32
|
+
- 2
|
33
|
+
- 9
|
34
|
+
version: 1.2.9
|
35
|
+
type: :development
|
36
|
+
version_requirements: *id001
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: cucumber
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
hash: 3
|
46
|
+
segments:
|
47
|
+
- 0
|
48
|
+
version: "0"
|
49
|
+
type: :development
|
50
|
+
version_requirements: *id002
|
51
|
+
- !ruby/object:Gem::Dependency
|
52
|
+
name: biodiversity
|
53
|
+
prerelease: false
|
54
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
55
|
+
none: false
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
hash: 3
|
60
|
+
segments:
|
61
|
+
- 0
|
62
|
+
version: "0"
|
63
|
+
type: :runtime
|
64
|
+
version_requirements: *id003
|
65
|
+
- !ruby/object:Gem::Dependency
|
66
|
+
name: redis
|
67
|
+
prerelease: false
|
68
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
69
|
+
none: false
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
hash: 3
|
74
|
+
segments:
|
75
|
+
- 0
|
76
|
+
version: "0"
|
77
|
+
type: :runtime
|
78
|
+
version_requirements: *id004
|
79
|
+
description: Scientific names parser/atomizer with cached distributed storage of atomized data
|
80
|
+
email: dmozzherin@gmail.com
|
81
|
+
executables:
|
82
|
+
- parsley-store
|
83
|
+
extensions: []
|
84
|
+
|
85
|
+
extra_rdoc_files:
|
86
|
+
- LICENSE
|
87
|
+
- README.rdoc
|
88
|
+
files:
|
89
|
+
- .document
|
90
|
+
- .gitignore
|
91
|
+
- LICENSE
|
92
|
+
- README.rdoc
|
93
|
+
- Rakefile
|
94
|
+
- VERSION
|
95
|
+
- bin/parsley-store
|
96
|
+
- features/parsley-store.feature
|
97
|
+
- features/step_definitions/parsley-store_steps.rb
|
98
|
+
- features/support/env.rb
|
99
|
+
- lib/parsley-store.rb
|
100
|
+
- spec/parsley-store_spec.rb
|
101
|
+
- spec/spec.opts
|
102
|
+
- spec/spec_helper.rb
|
103
|
+
has_rdoc: true
|
104
|
+
homepage: http://github.com/GlobalNamesArchitecture/parsley-store
|
105
|
+
licenses: []
|
106
|
+
|
107
|
+
post_install_message:
|
108
|
+
rdoc_options:
|
109
|
+
- --charset=UTF-8
|
110
|
+
require_paths:
|
111
|
+
- lib
|
112
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
hash: 3
|
118
|
+
segments:
|
119
|
+
- 0
|
120
|
+
version: "0"
|
121
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
122
|
+
none: false
|
123
|
+
requirements:
|
124
|
+
- - ">="
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
hash: 3
|
127
|
+
segments:
|
128
|
+
- 0
|
129
|
+
version: "0"
|
130
|
+
requirements: []
|
131
|
+
|
132
|
+
rubyforge_project:
|
133
|
+
rubygems_version: 1.3.7
|
134
|
+
signing_key:
|
135
|
+
specification_version: 3
|
136
|
+
summary: Scientific Names Parser with Cached Results
|
137
|
+
test_files:
|
138
|
+
- spec/parsley-store_spec.rb
|
139
|
+
- spec/spec_helper.rb
|