Class: Okura::Serializer::FormatInfo
- Inherits:
-
Object
- Object
- Okura::Serializer::FormatInfo
- Defined in:
- lib/okura/serializer.rb
Overview
辞書ファイルのコンパイル形式を表現し、コンパイルとロードの制御を担当する
Instance Attribute Summary collapse
-
#char_types ⇒ Object
Returns the value of attribute char_types.
-
#encoding ⇒ Object
Returns the value of attribute encoding.
-
#features ⇒ Object
Returns the value of attribute features.
-
#matrix ⇒ Object
Returns the value of attribute matrix.
-
#unk_dic ⇒ Object
Returns the value of attribute unk_dic.
-
#word_dic ⇒ Object
Returns the value of attribute word_dic.
Class Method Summary collapse
-
.create_tagger(bin_dir) ⇒ Object
指定されたディレクトリにあるコンパイル済み辞書をロードし、Taggerを作成する.
-
.load(io) ⇒ Object
シリアライズされたFormatInfoオブジェクトを復元する.
Instance Method Summary collapse
-
#compile(io) ⇒ Object
このFormatInfoオブジェクトをシリアライズする.
-
#compile_dict(src_dir, bin_dir) ⇒ Object
指定されたディレクトリにあるソースをコンパイルする.
- #create_tagger(bin_dir) ⇒ Object
-
#initialize ⇒ FormatInfo
constructor
A new instance of FormatInfo.
Constructor Details
#initialize ⇒ FormatInfo
Returns a new instance of FormatInfo.
9 10 11 12 13 14 15 16 |
# File 'lib/okura/serializer.rb', line 9 def initialize @word_dic=:DoubleArray @unk_dic=:Marshal @features=:Marshal @char_types=:Marshal @matrix=:Marshal @encoding='EUC-JP' end |
Instance Attribute Details
#char_types ⇒ Object
Returns the value of attribute char_types.
20 21 22 |
# File 'lib/okura/serializer.rb', line 20 def char_types @char_types end |
#encoding ⇒ Object
Returns the value of attribute encoding.
22 23 24 |
# File 'lib/okura/serializer.rb', line 22 def encoding @encoding end |
#features ⇒ Object
Returns the value of attribute features.
19 20 21 |
# File 'lib/okura/serializer.rb', line 19 def features @features end |
#matrix ⇒ Object
Returns the value of attribute matrix.
21 22 23 |
# File 'lib/okura/serializer.rb', line 21 def matrix @matrix end |
#unk_dic ⇒ Object
Returns the value of attribute unk_dic.
18 19 20 |
# File 'lib/okura/serializer.rb', line 18 def unk_dic @unk_dic end |
#word_dic ⇒ Object
Returns the value of attribute word_dic.
17 18 19 |
# File 'lib/okura/serializer.rb', line 17 def word_dic @word_dic end |
Class Method Details
.create_tagger(bin_dir) ⇒ Object
指定されたディレクトリにあるコンパイル済み辞書をロードし、Taggerを作成する
65 66 67 68 |
# File 'lib/okura/serializer.rb', line 65 def self.create_tagger bin_dir format_info=File.open(File.join(bin_dir,'format-info')){|f| self.load f } format_info.create_tagger bin_dir end |
.load(io) ⇒ Object
シリアライズされたFormatInfoオブジェクトを復元する
100 101 102 103 104 105 106 107 108 109 |
# File 'lib/okura/serializer.rb', line 100 def self.load io data=YAML.load(io) fi=FormatInfo.new fi.word_dic=data[:word_dic] fi.unk_dic=data[:unk_dic] fi.features=data[:features] fi.char_types=data[:char_types] fi.matrix=data[:matrix] fi end |
Instance Method Details
#compile(io) ⇒ Object
このFormatInfoオブジェクトをシリアライズする
90 91 92 93 94 95 96 97 98 |
# File 'lib/okura/serializer.rb', line 90 def compile io YAML.dump({ word_dic: word_dic, unk_dic: unk_dic, features: features, char_types: char_types, matrix: matrix },io) end |
#compile_dict(src_dir, bin_dir) ⇒ Object
指定されたディレクトリにあるソースをコンパイルする
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/okura/serializer.rb', line 25 def compile_dict src_dir,bin_dir open_dest(bin_dir,'format-info'){|dest| self.compile dest} features_l=open_src(src_dir,'left-id.def'){|src| open_dest(bin_dir,'left-id.bin'){|dest| serializer_for('Features',features).compile(src,dest) } } features_r=open_src(src_dir,'right-id.def'){|src| open_dest(bin_dir,'right-id.bin'){|dest| serializer_for('Features',features).compile(src,dest) } } word_src_files= Dir.chdir(src_dir){ Dir.glob('*.csv') }. map{|file|File.join(src_dir,file)} open_dest(bin_dir,'word_dic.bin'){|dest| serializer_for('WordDic',word_dic).compile(features_l,features_r,word_src_files,encoding,dest) } char_types=open_src(src_dir,'char.def'){|src| open_dest(bin_dir,'char_types.bin'){|dest| serializer_for('CharTypes',@char_types).compile(src,dest) } } open_src(src_dir,'unk.def'){|src| open_dest(bin_dir,'unk_dic.bin'){|dest| serializer_for('UnkDic',unk_dic).compile(char_types,features_l,features_r,src,dest) } } open_src(src_dir,'matrix.def'){|src| open_dest(bin_dir,'matrix.bin'){|dest| serializer_for('Matrix',matrix).compile(src,dest) } } end |
#create_tagger(bin_dir) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/okura/serializer.rb', line 69 def create_tagger bin_dir features_l=open_bin(bin_dir,'left-id.bin'){|bin| serializer_for('Features',features).load(bin) } features_r=open_bin(bin_dir,'right-id.bin'){|bin| serializer_for('Features',features).load(bin) } wd=open_bin(bin_dir,'word_dic.bin'){|f| serializer_for('WordDic',word_dic).load(f) } ud=open_bin(bin_dir,'unk_dic.bin'){|f| serializer_for('UnkDic',unk_dic).load(f) } mat=open_bin(bin_dir,'matrix.bin'){|f| serializer_for('Matrix',matrix).load(f) } dic=Okura::Dic.new wd,ud tagger=Okura::Tagger.new dic,mat tagger end |