kanjidic 0.3.0 → 0.4.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.
- checksums.yaml +4 -4
- data/bin/kanjidic +83 -0
- data/lib/kanjidic.rb +7 -0
- metadata +5 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 7a84afcc6326773e3dce339b1a5e7308d6ff38c4
|
|
4
|
+
data.tar.gz: dfb53b89d2eefe510953ae9c3352239eb87b2e4a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 3abbfb813e3532e9c37aba8349ccf6c18369a3ead426b13e4e3f51e0570233b5ed4bf45a8171886c823b398dea72e1eced94d6c5aa5bde0b8d738a6a2cbf8686
|
|
7
|
+
data.tar.gz: ed7999d8710a4cebe97106c937812eaf9dca3f6b6ee925d73b9d4857ded86249f3c7141f3c971ebb4bdbe9827aeb302485f1ea0ff85dbff9e1d5c8423d1b7fb8
|
data/bin/kanjidic
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require "kanjidic"
|
|
4
|
+
require "optparse"
|
|
5
|
+
require "irb"
|
|
6
|
+
|
|
7
|
+
file_name = ARGV[0]
|
|
8
|
+
defaults = { file: file_name, jis: 0, ext_jis: [1, 2] }
|
|
9
|
+
raise "No such file #{file_name}" unless File.exist? file_name
|
|
10
|
+
options = {}
|
|
11
|
+
|
|
12
|
+
OptionParser.new do |opts|
|
|
13
|
+
|
|
14
|
+
opts.banner = "Usage: \tkanjidic FILE [options]\n\t\t\tkanjidic FILE [options] -e {expression}"
|
|
15
|
+
|
|
16
|
+
opts.on("-e EXPRESSION", "--expression EXPRESSION", "Run a Ruby expression inside the context of the dictionary") do |e|
|
|
17
|
+
options[:expression] = e
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
opts.on("-J PREFIX", "--JIS-prefix=PREFIX", "Run the dictionary with a custom prefix (only works with custom dictionary file)") do |p|
|
|
21
|
+
options[:jis] = p unless options[:file].nil?
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
opts.on("-x FILES", "--extensions=FILES", "Parse and add FILES to the dictionary") do |f|
|
|
25
|
+
options[:extensions] = f.split(";")
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
opts.on("--extensions-JIS=PREFIX", "Sets the prefixes for additional files.") do |p|
|
|
29
|
+
options[:ext_jis] = p.is_a?(Number) ? [p] : p
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
opts.on_head("-h", "--help", "Print this message") do
|
|
33
|
+
puts opts
|
|
34
|
+
exit
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
end.parse!
|
|
38
|
+
|
|
39
|
+
options = defaults.merge options
|
|
40
|
+
|
|
41
|
+
Kanjidic.open(options[:file], options[:jis])
|
|
42
|
+
if options[:extensions]
|
|
43
|
+
[options[:extensions], options[:ext_jis]].transpose.each do |ext, code|
|
|
44
|
+
Kanjidic.expand ext, code
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
if(e = options[:expression])
|
|
49
|
+
puts eval(e, Kanjidic.binding)
|
|
50
|
+
else
|
|
51
|
+
module Kanjidic
|
|
52
|
+
@@dic.freeze
|
|
53
|
+
|
|
54
|
+
def self.about arg = nil
|
|
55
|
+
unless arg.nil?
|
|
56
|
+
puts case arg
|
|
57
|
+
when Hash
|
|
58
|
+
arg.to_a.map { |k,v|
|
|
59
|
+
"#{k}".ljust(25) + "#{v}"
|
|
60
|
+
}.join("\n")
|
|
61
|
+
when Array
|
|
62
|
+
arg.join(", ")
|
|
63
|
+
else
|
|
64
|
+
arg
|
|
65
|
+
end
|
|
66
|
+
else
|
|
67
|
+
puts <<~HELP
|
|
68
|
+
All commands are evaluated inside the Kanjidic module (see library documentation for more information).
|
|
69
|
+
Unknown commands are redirected to the @@dic Array which contains the dictionary.
|
|
70
|
+
For example, to search for all kanji which can be pronunced "あ", type the command 'find_all { |k| k[:reading].include? "あ" }'
|
|
71
|
+
|
|
72
|
+
Type 'about symbols' to print a list of the symbols composing kanji Hashes
|
|
73
|
+
HELP
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
IRB.setup nil
|
|
78
|
+
IRB.conf[:MAIN_CONTEXT] = IRB::Irb.new.context
|
|
79
|
+
require 'irb/ext/multi-irb'
|
|
80
|
+
puts "Type 'about' for informations about this software."
|
|
81
|
+
puts "Type 'exit' to terminate the session."
|
|
82
|
+
IRB.irb nil, Kanjidic
|
|
83
|
+
end
|
data/lib/kanjidic.rb
CHANGED
|
@@ -282,6 +282,13 @@ module Kanjidic
|
|
|
282
282
|
coded_symboles.merge(uncoded_symbols)
|
|
283
283
|
end
|
|
284
284
|
|
|
285
|
+
# Alias for Kanjidic::all_symbols
|
|
286
|
+
#
|
|
287
|
+
# See Kanjidic::all_symbols
|
|
288
|
+
def self.symbols
|
|
289
|
+
all_symbols
|
|
290
|
+
end
|
|
291
|
+
|
|
285
292
|
# Returns a hash of all symbols and their String representations
|
|
286
293
|
def self.coded_symboles
|
|
287
294
|
dictionaries.to_a.map { |e|
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: kanjidic
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.4.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Sylvain Leclercq
|
|
@@ -12,10 +12,12 @@ date: 2016-10-26 00:00:00.000000000 Z
|
|
|
12
12
|
dependencies: []
|
|
13
13
|
description: A gem to extract and explore the KANJIDIC (http://ftp.monash.edu.au/pub/nihongo/kanjidic.html)
|
|
14
14
|
email: maisbiensurqueoui@gmail.com
|
|
15
|
-
executables:
|
|
15
|
+
executables:
|
|
16
|
+
- kanjidic
|
|
16
17
|
extensions: []
|
|
17
18
|
extra_rdoc_files: []
|
|
18
19
|
files:
|
|
20
|
+
- bin/kanjidic
|
|
19
21
|
- lib/kanjidic.rb
|
|
20
22
|
homepage: http://www.github.com/de-passage/kanjidic
|
|
21
23
|
licenses:
|
|
@@ -37,7 +39,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
37
39
|
version: '0'
|
|
38
40
|
requirements: []
|
|
39
41
|
rubyforge_project:
|
|
40
|
-
rubygems_version: 2.4.
|
|
42
|
+
rubygems_version: 2.4.8
|
|
41
43
|
signing_key:
|
|
42
44
|
specification_version: 4
|
|
43
45
|
summary: Extract and explore the KANJIDIC
|