ruby-jdict 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
data/spec/spec_helper.rb CHANGED
@@ -1,50 +1,50 @@
1
- require 'rubygems' #use gems
2
- require 'bundler/setup' #load up the bundled environment
3
- # require 'spec' #test framework
4
-
5
- $DEBUG = true
6
-
7
- BASE_PATH = File.dirname(__FILE__) + '/..'
8
- INDEX_PATH = BASE_PATH + '/test_index'
9
- JMDICT_PATH = BASE_PATH + '/dictionaries/JMdict'
10
-
11
- ##
12
- # rSpec Hash additions.
13
- #
14
- # From
15
- # * http://wincent.com/knowledge-base/Fixtures_considered_harmful%3F
16
- # * Neil Rahilly
17
-
18
- class Hash
19
-
20
- ##
21
- # Filter keys out of a Hash.
22
- #
23
- # { :a => 1, :b => 2, :c => 3 }.except(:a)
24
- # => { :b => 2, :c => 3 }
25
-
26
- def except(*keys)
27
- self.reject { |k,v| keys.include?(k || k.to_sym) }
28
- end
29
-
30
- ##
31
- # Override some keys.
32
- #
33
- # { :a => 1, :b => 2, :c => 3 }.with(:a => 4)
34
- # => { :a => 4, :b => 2, :c => 3 }
35
-
36
- def with(overrides = {})
37
- self.merge overrides
38
- end
39
-
40
- ##
41
- # Returns a Hash with only the pairs identified by +keys+.
42
- #
43
- # { :a => 1, :b => 2, :c => 3 }.only(:a)
44
- # => { :a => 1 }
45
-
46
- def only(*keys)
47
- self.reject { |k,v| !keys.include?(k || k.to_sym) }
48
- end
49
-
1
+ require 'rubygems' #use gems
2
+ require 'bundler/setup' #load up the bundled environment
3
+ # require 'spec' #test framework
4
+
5
+ $DEBUG = true
6
+
7
+ BASE_PATH = File.dirname(__FILE__) + '/..'
8
+ INDEX_PATH = BASE_PATH + '/test_index'
9
+ JMDICT_PATH = BASE_PATH + '/dictionaries/JMdict'
10
+
11
+ ##
12
+ # rSpec Hash additions.
13
+ #
14
+ # From
15
+ # * http://wincent.com/knowledge-base/Fixtures_considered_harmful%3F
16
+ # * Neil Rahilly
17
+
18
+ class Hash
19
+
20
+ ##
21
+ # Filter keys out of a Hash.
22
+ #
23
+ # { :a => 1, :b => 2, :c => 3 }.except(:a)
24
+ # => { :b => 2, :c => 3 }
25
+
26
+ def except(*keys)
27
+ self.reject { |k,v| keys.include?(k || k.to_sym) }
28
+ end
29
+
30
+ ##
31
+ # Override some keys.
32
+ #
33
+ # { :a => 1, :b => 2, :c => 3 }.with(:a => 4)
34
+ # => { :a => 4, :b => 2, :c => 3 }
35
+
36
+ def with(overrides = {})
37
+ self.merge overrides
38
+ end
39
+
40
+ ##
41
+ # Returns a Hash with only the pairs identified by +keys+.
42
+ #
43
+ # { :a => 1, :b => 2, :c => 3 }.only(:a)
44
+ # => { :a => 1 }
45
+
46
+ def only(*keys)
47
+ self.reject { |k,v| !keys.include?(k || k.to_sym) }
48
+ end
49
+
50
50
  end
metadata CHANGED
@@ -1,85 +1,85 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-jdict
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ian Pickering
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-06-11 00:00:00.000000000 Z
11
+ date: 2019-02-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: libxml-ruby
14
+ name: rake
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 2.8.0
19
+ version: '12.3'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 2.8.0
26
+ version: '12.3'
27
27
  - !ruby/object:Gem::Dependency
28
- name: amalgalite
28
+ name: nokogiri
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 1.5.0
33
+ version: '1.10'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 1.5.0
40
+ version: '1.10'
41
41
  - !ruby/object:Gem::Dependency
42
- name: rsync
42
+ name: amalgalite
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 1.0.9
47
+ version: '1.6'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 1.0.9
54
+ version: '1.6'
55
55
  - !ruby/object:Gem::Dependency
56
- name: autotest
56
+ name: rsync
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ">="
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '0'
62
- type: :development
61
+ version: '1.0'
62
+ type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ">="
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '0'
68
+ version: '1.0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rspec
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: 3.4.0
75
+ version: '3.8'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: 3.4.0
82
+ version: '3.8'
83
83
  description:
84
84
  email:
85
85
  - ipickering2@gmail.com
@@ -90,29 +90,28 @@ files:
90
90
  - LICENSING
91
91
  - README.md
92
92
  - Rakefile
93
- - examples/lst.txt
94
93
  - examples/query.rb
95
- - lib/configuration.rb
96
- - lib/constants.rb
97
- - lib/dictionaries/jmdict.rb
98
- - lib/dictionary.rb
99
- - lib/downloader.rb
100
- - lib/entry.rb
101
- - lib/index.rb
102
- - lib/jdict.rb
103
- - lib/kana.rb
104
- - lib/kanji.rb
94
+ - lib/ruby-jdict.rb
95
+ - lib/ruby-jdict/constants.rb
96
+ - lib/ruby-jdict/convert.rb
97
+ - lib/ruby-jdict/dictionary.rb
98
+ - lib/ruby-jdict/index.rb
99
+ - lib/ruby-jdict/indexer/dictionary_indexer.rb
100
+ - lib/ruby-jdict/indexer/libxml_dictionary_indexer.rb
101
+ - lib/ruby-jdict/indexer/nokogiri_dictionary_indexer.rb
102
+ - lib/ruby-jdict/jdict.rb
103
+ - lib/ruby-jdict/models/entry.rb
104
+ - lib/ruby-jdict/models/sense.rb
105
105
  - lib/ruby-jdict/version.rb
106
- - lib/sense.rb
107
- - lib/unicode.rb
108
- - spec/configuration_spec.rb
106
+ - spec/convert_spec.rb
109
107
  - spec/dictionary_spec.rb
108
+ - spec/entry_spec.rb
110
109
  - spec/fixtures/feeds/sample_entry.xml
111
110
  - spec/index_spec.rb
112
- - spec/jmdict_spec.rb
113
111
  - spec/spec_helper.rb
114
112
  homepage: https://github.com/Ruin0x11/ruby-jdict
115
- licenses: []
113
+ licenses:
114
+ - MIT
116
115
  metadata: {}
117
116
  post_install_message:
118
117
  rdoc_options: []
@@ -130,7 +129,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
130
129
  version: '0'
131
130
  requirements: []
132
131
  rubyforge_project:
133
- rubygems_version: 2.4.5.1
132
+ rubygems_version: 2.6.14.3
134
133
  signing_key:
135
134
  specification_version: 4
136
135
  summary: Ruby gem for accessing Jim Breen's Japanese dictionaries
data/examples/lst.txt DELETED
@@ -1,4 +0,0 @@
1
- できる
2
- 位置
3
- 労働
4
- 世論
data/lib/configuration.rb DELETED
@@ -1,34 +0,0 @@
1
- require 'constants'
2
-
3
- module JDict
4
- class Configuration
5
- attr_accessor :dictionary_path, :num_results, :language, :debug,
6
- :jmdict_url, :jmdict_rsync_url
7
-
8
- BASE_PATH = ENV["HOME"]
9
- DICT_PATH = File.join(BASE_PATH, '.dicts')
10
-
11
- JMDICT_URL = "ftp://ftp.monash.edu.au/pub/nihongo/JMdict.gz"
12
- JMDICT_RSYNC_URL = "rsync://ftp.monash.edu.au/nihongo/JMdict"
13
-
14
- def initialize
15
- # directory containing dictionary files
16
- @dictionary_path = DICT_PATH
17
-
18
- # maximum results to return from searching
19
- @num_results = 50
20
-
21
- # language to return search results in
22
- @language = JDict::JMDictConstants::Languages::ENGLISH
23
-
24
- # limit number of entries indexed, rebuild index on instantiation
25
- @debug = false
26
-
27
- # url to retrieve JMDict from
28
- @jmdict_url = JMDICT_URL
29
-
30
- # url to rsync JMDict from
31
- @jmdict_rsync_url = JMDICT_RSYNC_URL
32
- end
33
- end
34
- end
@@ -1,38 +0,0 @@
1
- require 'jdict'
2
- require 'dictionary'
3
- require 'downloader'
4
-
5
- module JDict
6
- class JMDict < Dictionary
7
- def dict_url
8
- JDict.config.jmdict_url
9
- end
10
-
11
- def dict_file
12
- 'JMDict'
13
- end
14
-
15
- private
16
-
17
- def initialize
18
- dict_path = JDict.config.dictionary_path
19
- @downloader = JMDictDownloader.new
20
-
21
- super(dict_path)
22
- end
23
- end
24
-
25
- class JMDictDownloader < Downloader
26
- def download(dir)
27
- url = JDict.config.jmdict_url
28
- full_path = retrieve_file(url, dir)
29
- gunzip(full_path)
30
- end
31
-
32
- def sync(dir)
33
- dict_path = File.join(dir, 'JMdict')
34
- rsync_url = JDict.config.jmdict_rsync_url
35
- rsync(rsync_url, dict_path)
36
- end
37
- end
38
- end
data/lib/dictionary.rb DELETED
@@ -1,90 +0,0 @@
1
- require 'jdict'
2
- require 'index'
3
-
4
- module JDict
5
- class Dictionary
6
- def initialize(path)
7
- @dictionary_path = File.join(path, self.dict_file)
8
- @entries = []
9
-
10
- prompt_for_download unless File.exists? @dictionary_path
11
-
12
- @index = DictIndex.new(@dictionary_path)
13
- end
14
-
15
- def size
16
- @entries.size
17
- end
18
-
19
- def loaded?
20
- @index.built?
21
- end
22
-
23
- def download(dir)
24
- @downloader.download(dir)
25
- end
26
-
27
- # abstract method
28
- def dict_url
29
- ""
30
- end
31
-
32
- def dict_file
33
- ""
34
- end
35
-
36
- def prompt_for_download
37
- base_dir = File.dirname(@dictionary_path)
38
-
39
- puts "Dictionary not found at #{@dictionary_path}.\n" \
40
- "Would you like to download the dictionary from the URL\n" \
41
- " #{self.dict_url}\n" \
42
- "into the folder\n" \
43
- " #{base_dir}? [y/N]"
44
-
45
- response = case $stdin.getch
46
- when "Y" then true
47
- when "y" then true
48
- else false
49
- end
50
-
51
- unless response
52
- puts "Dictionary not downloaded."
53
- exit
54
- end
55
-
56
- FileUtils.mkdir_p(base_dir)
57
-
58
- puts "Downloading dictionary..."
59
- download(base_dir)
60
- puts "Download completed."
61
- end
62
-
63
- # Search this dictionary's index for the given string.
64
- # @param query [String] the search query
65
- # @return [Array(Entry)] the results of the search
66
- def search(query, exact=false)
67
- results = []
68
- return results if query.empty?
69
-
70
- results = @index.search(query, exact)
71
- end
72
-
73
- # Retrieves the definition of a part-of-speech from its abbreviation
74
- # @param pos [String] the abbreviation for the part-of-speech
75
- # @return [String] the full description of the part-of-speech
76
- def get_pos(pos)
77
- @index.get_pos(pos)
78
- end
79
-
80
- private
81
-
82
- def load_index
83
- if loaded?
84
- Exception.new("Dictionary index is already loaded")
85
- else
86
- @index.build
87
- end
88
- end
89
- end
90
- end
data/lib/downloader.rb DELETED
@@ -1,42 +0,0 @@
1
- require 'open-uri'
2
- require 'zlib'
3
- require 'rsync'
4
-
5
- module JDict
6
- class Downloader
7
- def download
8
-
9
- end
10
-
11
- def sync
12
-
13
- end
14
-
15
- private
16
-
17
- def retrieve_file(url, dest_dir)
18
- filename = File.basename(url)
19
- full_path = File.join(dest_dir, filename)
20
- File.write(full_path, open(url).read)
21
- full_path
22
- end
23
-
24
- def gunzip(filename)
25
- to_write = File.join(File.dirname(filename), File.basename(filename, ".gz"))
26
-
27
- File.open(to_write, 'w') do |wri|
28
- File.open(filename) do |f|
29
- gz = Zlib::GzipReader.new(f)
30
- wri.write(gz.read)
31
- gz.close
32
- end
33
- end
34
-
35
- File.unlink(filename)
36
- end
37
-
38
- def rsync(src, dest)
39
- Rsync.run(src, dest)
40
- end
41
- end
42
- end