zidian 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Manifest +5 -0
- data/README.mkd +20 -0
- data/Rakefile +14 -0
- data/lib/cedict_ts.u8 +86617 -0
- data/lib/zidian.rb +49 -0
- data/zidian.gemspec +30 -0
- metadata +67 -0
data/lib/zidian.rb
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
module Zidian
|
2
|
+
|
3
|
+
def self.find(expression)
|
4
|
+
$KCODE = 'UTF8'
|
5
|
+
case expression.class.name
|
6
|
+
when "Array"
|
7
|
+
expression.collect{|e| find(e) }.flatten.uniq
|
8
|
+
when "Integer", "Fixnum" then
|
9
|
+
Word.new(get_line(expression), expression)
|
10
|
+
when "String" then
|
11
|
+
find_word(expression).lines.to_a.collect{|line| Word.new(line) }
|
12
|
+
else
|
13
|
+
raise "Invalid find parameter(#{expression.class}). Only integers, strings accepted"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
protected
|
18
|
+
|
19
|
+
def self.find_word(word) #:nodoc:
|
20
|
+
# adding the -i option allows to search independently from the case, but it makes it very slow
|
21
|
+
`less #{File.dirname(__FILE__)}/cedict_ts.u8 | grep -n '[/\s]#{word.gsub(/\s/,"\s")}[/\s]'`
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.get_line(line_number) #:nodoc:
|
25
|
+
`sed -n '#{line_number}p' #{File.dirname(__FILE__)}/cedict_ts.u8`
|
26
|
+
end
|
27
|
+
|
28
|
+
class Word
|
29
|
+
|
30
|
+
attr_reader :id, :traditional, :simplified, :pinyin, :english
|
31
|
+
|
32
|
+
def initialize(line, id=nil)
|
33
|
+
@id = id
|
34
|
+
extract_attributes_from_string(line.strip!)
|
35
|
+
end
|
36
|
+
|
37
|
+
def extract_attributes_from_string(line)
|
38
|
+
if line =~ /^[0-9]*:/
|
39
|
+
@id = line.gsub!(/^[0-9]*:/).to_a.first.gsub(':','').to_i
|
40
|
+
end
|
41
|
+
@traditional = line.match(/^[^\s]+/)[0]
|
42
|
+
@simplified = line.match(/\s[^\s]+/)[0].strip
|
43
|
+
@pinyin = line.match(/\[.+?\]/)[0].gsub(/[\[\]]/,'')
|
44
|
+
@english = line.scan(/\/[^\/]+/).collect{|e| e.gsub(/[\/]/,'')}
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
data/zidian.gemspec
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{zidian}
|
5
|
+
s.version = "0.0.1"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["Bastien Vaucher"]
|
9
|
+
s.date = %q{2010-03-31}
|
10
|
+
s.description = %q{Chinese dictionary}
|
11
|
+
s.email = %q{bastien.vaucher@gmail.com}
|
12
|
+
s.extra_rdoc_files = ["README.mkd", "lib/cedict_ts.u8", "lib/zidian.rb"]
|
13
|
+
s.files = ["README.mkd", "Rakefile", "lib/cedict_ts.u8", "lib/zidian.rb", "Manifest", "zidian.gemspec"]
|
14
|
+
s.homepage = %q{http://github.com/bastien/zidian}
|
15
|
+
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Zidian", "--main", "README.mkd"]
|
16
|
+
s.require_paths = ["lib"]
|
17
|
+
s.rubyforge_project = %q{zidian}
|
18
|
+
s.rubygems_version = %q{1.3.5}
|
19
|
+
s.summary = %q{Chinese dictionary}
|
20
|
+
|
21
|
+
if s.respond_to? :specification_version then
|
22
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
23
|
+
s.specification_version = 3
|
24
|
+
|
25
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
26
|
+
else
|
27
|
+
end
|
28
|
+
else
|
29
|
+
end
|
30
|
+
end
|
metadata
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: zidian
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Bastien Vaucher
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2010-03-31 00:00:00 +02:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: Chinese dictionary
|
17
|
+
email: bastien.vaucher@gmail.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- README.mkd
|
24
|
+
- lib/cedict_ts.u8
|
25
|
+
- lib/zidian.rb
|
26
|
+
files:
|
27
|
+
- README.mkd
|
28
|
+
- Rakefile
|
29
|
+
- lib/cedict_ts.u8
|
30
|
+
- lib/zidian.rb
|
31
|
+
- Manifest
|
32
|
+
- zidian.gemspec
|
33
|
+
has_rdoc: true
|
34
|
+
homepage: http://github.com/bastien/zidian
|
35
|
+
licenses: []
|
36
|
+
|
37
|
+
post_install_message:
|
38
|
+
rdoc_options:
|
39
|
+
- --line-numbers
|
40
|
+
- --inline-source
|
41
|
+
- --title
|
42
|
+
- Zidian
|
43
|
+
- --main
|
44
|
+
- README.mkd
|
45
|
+
require_paths:
|
46
|
+
- lib
|
47
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - ">="
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: "0"
|
52
|
+
version:
|
53
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: "1.2"
|
58
|
+
version:
|
59
|
+
requirements: []
|
60
|
+
|
61
|
+
rubyforge_project: zidian
|
62
|
+
rubygems_version: 1.3.5
|
63
|
+
signing_key:
|
64
|
+
specification_version: 3
|
65
|
+
summary: Chinese dictionary
|
66
|
+
test_files: []
|
67
|
+
|