analects 0.2.1 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +2 -3
- data/Gemfile +0 -9
- data/Gemfile.lock +2 -15
- data/lib/analects.rb +1 -0
- data/lib/analects/cedict_loader.rb +18 -7
- data/lib/analects/chise_ids_loader.rb +1 -1
- data/lib/analects/hsk_loader.rb +27 -0
- data/lib/analects/library.rb +7 -4
- data/lib/analects/source.rb +2 -1
- data/lib/analects/version.rb +1 -1
- data/spec/analects/cedict_loader_spec.rb +1 -1
- data/spec/analects/chise_ids_loader_spec.rb +1 -1
- data/spec/analects/library_spec.rb +7 -9
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c11afafa3e6efdbad98b84a73d3a190e2dc7fb52
|
4
|
+
data.tar.gz: 74b50dbb99b0fbb20182e682d1a5b044930e089a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bf0ef56017cdf8a29b8931ca7b6e838c0c0255b7e9cfa9f878e23a531bbb43c176f4ffc1840308c0a82427e2c00b764e625226d20b912b7eb4731a8ba8d4f834
|
7
|
+
data.tar.gz: ad3972c46c16426698709ecf2a1cf86246b7221333398ec5d8a2d9b51e9b3dd0532e66754c173bb3e04c05cb288bf475e20229dc844b5a8e0991d00101cceccf
|
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
@@ -5,13 +5,4 @@ group :development, :test do
|
|
5
5
|
eval_gemfile 'Gemfile.devtools'
|
6
6
|
end
|
7
7
|
|
8
|
-
if ENV['LOCAL']
|
9
|
-
source = ->(s) { { path: ENV['HOME'] + "/github/#{s}" } }
|
10
|
-
else
|
11
|
-
source = ->(s) { { github: "plexus/#{s}" } }
|
12
|
-
end
|
13
|
-
|
14
|
-
gem 'rmmseg' , source.('rmmseg')
|
15
|
-
gem 'ting' , source.('ting')
|
16
|
-
|
17
8
|
gemspec
|
data/Gemfile.lock
CHANGED
@@ -1,15 +1,3 @@
|
|
1
|
-
GIT
|
2
|
-
remote: git://github.com/plexus/rmmseg.git
|
3
|
-
revision: 73fb91682ddf955e6e72722cc3f2adbecaf7508d
|
4
|
-
specs:
|
5
|
-
rmmseg (0.1.6)
|
6
|
-
|
7
|
-
GIT
|
8
|
-
remote: git://github.com/plexus/ting.git
|
9
|
-
revision: 63491759a6b40c8dddc7aadcf16fce833ea107ba
|
10
|
-
specs:
|
11
|
-
ting (0.9.0)
|
12
|
-
|
13
1
|
GIT
|
14
2
|
remote: https://github.com/rom-rb/devtools.git
|
15
3
|
revision: 62d3fa16941e5b61e1e8bb520a1b40d6179aebf5
|
@@ -19,7 +7,7 @@ GIT
|
|
19
7
|
PATH
|
20
8
|
remote: .
|
21
9
|
specs:
|
22
|
-
analects (0.
|
10
|
+
analects (0.3.1)
|
23
11
|
ice_nine (~> 0.11.0)
|
24
12
|
inflecto (~> 0.0.2)
|
25
13
|
plexus-rmmseg (~> 0.1.6)
|
@@ -178,6 +166,7 @@ GEM
|
|
178
166
|
thread_safe (0.2.0)
|
179
167
|
atomic (>= 1.1.7, < 2)
|
180
168
|
timers (1.1.0)
|
169
|
+
ting (0.9.0)
|
181
170
|
unparser (0.1.9)
|
182
171
|
abstract_type (~> 0.0.7)
|
183
172
|
adamantium (~> 0.1)
|
@@ -220,7 +209,6 @@ DEPENDENCIES
|
|
220
209
|
rb-notifu (~> 0.0.4)
|
221
210
|
rbench (~> 0.2.3)
|
222
211
|
reek (~> 1.3.2)
|
223
|
-
rmmseg!
|
224
212
|
rspec (~> 2.14.1)
|
225
213
|
rspec-core (~> 2.14.8)
|
226
214
|
rubocop (~> 0.18.1)
|
@@ -231,7 +219,6 @@ DEPENDENCIES
|
|
231
219
|
rubysl-singleton (~> 2.0.0)
|
232
220
|
simplecov (~> 0.8.2)
|
233
221
|
terminal-notifier-guard (~> 1.5.3)
|
234
|
-
ting!
|
235
222
|
yard (~> 0.8.7)
|
236
223
|
yard-spellcheck (~> 0.1.5)
|
237
224
|
yardstick (~> 0.9.9)
|
data/lib/analects.rb
CHANGED
@@ -6,7 +6,7 @@ module Analects
|
|
6
6
|
|
7
7
|
attr_reader :headers
|
8
8
|
|
9
|
-
def initialize(io)
|
9
|
+
def initialize(io, library)
|
10
10
|
@contents = io.read
|
11
11
|
@headers = {}
|
12
12
|
@contents.each_line do |line|
|
@@ -21,14 +21,25 @@ module Analects
|
|
21
21
|
[:traditional, :simplified, :pinyin, :definitions]
|
22
22
|
end
|
23
23
|
|
24
|
-
def each
|
25
|
-
|
26
|
-
|
27
|
-
|
24
|
+
def each(&blk)
|
25
|
+
return to_enum(__method__) unless block_given?
|
26
|
+
@entries ||= @contents.each_line.map do |line|
|
27
|
+
process_contents(line) if line !~ /^#/
|
28
|
+
end.compact
|
29
|
+
@entries.each(&blk)
|
30
|
+
end
|
31
|
+
|
32
|
+
def find_by(qry)
|
33
|
+
qry.map {|field, value| lookup_index(field).fetch(value, [])}.inject {|r1, r2| r1 & r2}
|
34
|
+
end
|
35
|
+
|
36
|
+
def lookup_index(field)
|
37
|
+
@indexes ||= field_names.each_with_object({}) do |field, acc|
|
38
|
+
acc[field] = each_with_object({}) do |entry, acc|
|
39
|
+
(acc[entry[field_names.index(field)]] ||= []) << entry
|
28
40
|
end
|
29
|
-
else
|
30
|
-
enum_for(:each)
|
31
41
|
end
|
42
|
+
@indexes[field]
|
32
43
|
end
|
33
44
|
|
34
45
|
private
|
@@ -14,7 +14,7 @@ module Analects
|
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
-
def initialize(pathname, only_unicode = true)
|
17
|
+
def initialize(pathname, library, only_unicode = true)
|
18
18
|
@contents = MultiFile.new(pathname.children.select{|ch| ch.to_s =~ /IDS-.*\.txt/})
|
19
19
|
@only_unicode = only_unicode
|
20
20
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
module Analects
|
4
|
+
class HskLoader
|
5
|
+
extend Forwardable
|
6
|
+
include Enumerable
|
7
|
+
|
8
|
+
FIELDS = [:level, :simplified, :traditional, :pinyin]
|
9
|
+
|
10
|
+
class HskEntry < Struct.new(:library, *FIELDS)
|
11
|
+
def cedict
|
12
|
+
@cedict ||= library.cedict.loader.find_by(
|
13
|
+
traditional: traditional,
|
14
|
+
simplified: simplified,
|
15
|
+
)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def_delegators :@contents, :each
|
20
|
+
|
21
|
+
def initialize(io, library)
|
22
|
+
@contents = CSV(io.read).map do |level, simplified, traditional, pinyin|
|
23
|
+
HskEntry.new(library, level, simplified, traditional, pinyin)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/lib/analects/library.rb
CHANGED
@@ -47,17 +47,20 @@ module Analects
|
|
47
47
|
}.merge(options_for :chise_ids)
|
48
48
|
)
|
49
49
|
end
|
50
|
-
# def hsk
|
51
|
-
# @hsk ||= Source.new(
|
52
50
|
|
53
|
-
|
54
|
-
|
51
|
+
def hsk
|
52
|
+
@hsk ||= Source.new( {
|
53
|
+
data_file: 'hsk.csv'
|
54
|
+
}.merge(options_for :hsk)
|
55
|
+
)
|
56
|
+
end
|
55
57
|
|
56
58
|
private
|
57
59
|
|
58
60
|
def options_for(name)
|
59
61
|
{
|
60
62
|
name: name,
|
63
|
+
library: self,
|
61
64
|
url: Analects.const_get("#{name.to_s.upcase}_URL"),
|
62
65
|
loader: Analects.const_get("#{Inflecto.camelize name}Loader"),
|
63
66
|
data_dir: data_dir
|
data/lib/analects/source.rb
CHANGED
@@ -7,12 +7,13 @@ module Analects
|
|
7
7
|
@options = options
|
8
8
|
end
|
9
9
|
|
10
|
+
def library ; options[:library] ; end
|
10
11
|
def name ; options[:name] ; end
|
11
12
|
def url ; options[:url] ; end
|
12
13
|
def retrieval ; Array(options[:retrieval]) ; end
|
13
14
|
|
14
15
|
def loader
|
15
|
-
@loader ||= options[:loader].new(Pathname(location))
|
16
|
+
@loader ||= options[:loader].new(Pathname(location), library)
|
16
17
|
end
|
17
18
|
|
18
19
|
def data_dir
|
data/lib/analects/version.rb
CHANGED
@@ -14,7 +14,7 @@ describe Analects::CedictLoader do
|
|
14
14
|
'
|
15
15
|
end
|
16
16
|
|
17
|
-
let ( :cedict_loader ) { Analects::CedictLoader.new( StringIO.new(contents) ) }
|
17
|
+
let ( :cedict_loader ) { Analects::CedictLoader.new( StringIO.new(contents), nil ) }
|
18
18
|
|
19
19
|
it "should parse headers" do
|
20
20
|
cedict_loader.headers.should == { 'charset' => 'UTF-8', 'entries' => '104941' }
|
@@ -3,7 +3,7 @@ require 'spec_helper'
|
|
3
3
|
|
4
4
|
describe Analects::ChiseIdsLoader do
|
5
5
|
subject(:loader) do
|
6
|
-
Analects::ChiseIdsLoader.new(Analects::ROOT.join('spec/test_data/chise_ids'), only_unicode)
|
6
|
+
Analects::ChiseIdsLoader.new(Analects::ROOT.join('spec/test_data/chise_ids'), nil, only_unicode)
|
7
7
|
end
|
8
8
|
|
9
9
|
let(:only_unicode) { false }
|
@@ -1,19 +1,19 @@
|
|
1
1
|
require 'tempfile'
|
2
|
-
require 'spec_helper'
|
3
2
|
require 'securerandom'
|
3
|
+
require 'pathname'
|
4
|
+
|
5
|
+
require 'spec_helper'
|
4
6
|
|
5
7
|
describe Analects::Library do
|
6
8
|
subject(:library) {
|
7
9
|
described_class.new(options)
|
8
10
|
}
|
9
|
-
let(:
|
11
|
+
let(:data_dir) { File.join(Dir.tmpdir, 'analects-' + SecureRandom.hex(16)) }
|
12
|
+
let(:options) {
|
13
|
+
{ data_dir: data_dir }
|
14
|
+
}
|
10
15
|
|
11
16
|
context 'with a data_dir specified' do
|
12
|
-
let(:data_dir) { File.join(Dir.tmpdir, 'analects-' + SecureRandom.hex(16)) }
|
13
|
-
let(:options) {
|
14
|
-
{ data_dir: data_dir }
|
15
|
-
}
|
16
|
-
|
17
17
|
it 'should set that data dir on the sources' do
|
18
18
|
subject.cedict.data_dir.should == data_dir
|
19
19
|
end
|
@@ -23,7 +23,6 @@ describe Analects::Library do
|
|
23
23
|
subject(:cedict) { library.cedict }
|
24
24
|
|
25
25
|
its(:name) { should == :cedict }
|
26
|
-
its(:location) { should == File.join(Dir.home, '.analects/cedict_1_0_ts_utf-8_mdbg.txt') }
|
27
26
|
|
28
27
|
it "should download and unpack the CEDICT archive" do
|
29
28
|
cedict.should_receive(:retrieve_http).once.with(Analects::CEDICT_URL).and_return(:a_stream)
|
@@ -42,7 +41,6 @@ describe Analects::Library do
|
|
42
41
|
|
43
42
|
its( :name ) { should == :chise_ids }
|
44
43
|
its( :retrieval ) { should == [ :git ] }
|
45
|
-
its(:location ) { should == File.join(Dir.home, '.analects/chise_ids') }
|
46
44
|
its( :url ) { should == Analects::CHISE_IDS_URL}
|
47
45
|
end
|
48
46
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: analects
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Arne Brasseur
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-04-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -169,6 +169,7 @@ files:
|
|
169
169
|
- lib/analects/chise_ids_loader.rb
|
170
170
|
- lib/analects/cli/progress.rb
|
171
171
|
- lib/analects/encoding.rb
|
172
|
+
- lib/analects/hsk_loader.rb
|
172
173
|
- lib/analects/library.rb
|
173
174
|
- lib/analects/models/kangxi_radical.rb
|
174
175
|
- lib/analects/models/zi.rb
|
@@ -208,7 +209,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
208
209
|
version: '0'
|
209
210
|
requirements: []
|
210
211
|
rubyforge_project:
|
211
|
-
rubygems_version: 2.
|
212
|
+
rubygems_version: 2.0.14
|
212
213
|
signing_key:
|
213
214
|
specification_version: 4
|
214
215
|
summary: Toolkit for Mandarin language learning apps
|