1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 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 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
|
=begin
= Sary Ruby Binding Reference
== Suffix Array Ѥ
ե filename Ф pattern ǸԤ̤иֽ˥Ȥñ̤ɽǤ
#!/usr/local/bin/ruby
require 'sary'
pattern = ARGV.shift
ARGV.each {|filename|
searcher = Sary::Saercher.new(filename)
if searcher.search(pattern)
searcher.sort_occurrences
searcher.each_context_line {|text| print text, "\n" }
end
}
== Suffix Array
Ƭ˥ǥå ݥȤƤǤ
#!/usr/local/bin/ruby
require 'sary'
filename = ARGV.shift
arrayname = filename + ".ary"
text = open(filename, "r")
array = open(arrayname, "w")
offset = 0
text.each {|line|
array.print [offset].pack('N')
offset += line.length
}
text.close
array.close
builder = Sary::Builder.new(filename, arrayname)
builder.block_sort
== Sary module
Sary::Searcher Sary::Builder 2ĤΥ饹ޤߤޤ
== Searcher class
array եʤȥƥȥեˤΥ饹Ǥ
Searcher#count_occurrences ʳΥåɤ˲Ūʥå
Ǥ
--- Searcher.new(filename[,arrayname])
Τ˥ƥȥե array եޤ
˥ƥȥե̾ array ե̾ꤷޤ
array ե̾ά ((|filename|)).ary Ȥޤ
Ԥ (({IOError})) 㳰ȯޤ
--- Searcher#search(pattern)
ɸԤʤޤ
(({true}))Ԥ (({false})) ֤ޤ
--- Searcher#isearch(pattern, len)
Ψɤ븡Ԥʤޤ
((|pattern|)) ꤷơ((|len|)) ͤ ((|pattern|))Ĺ
ޤǽ 礭ʤϢ³ƸƤӽФȤˤꥤ
ޤ
((<Searcher#sort_occurrences>)) ȤʻѤϤǤޤ
(({true}))Ԥ (({false})) ֤ޤ
--- Searcher#isearch_reset
((<Searcher#isearch>)) Ѥ֤ꥻåȤޤ
pattern ((<Searcher#isearch>)) ƤӽФȤϡˤ
δؿ¹Ԥ֤ꥻåȤƤ
--- Searcher#icase_search(pattern)
ե٥åȤʸʸ̤ʤԤʤޤ
(({true}))Ԥ (({false})) ֤ޤ
--- Searcher#multi_search(pattern_array)
((|pattern_array|)) ΥɤޤȤư٤˸ޤ.
--- Searcher#get_next_context_line
θ̤ñ̤ǼФޤ
δؿϢ³ƸƤ֤ȡ٤Ƥθ̤ޤĤθ
̤ʤȤ (({nil})) ֤ޤ
--- Searcher#get_next_context_lines([bkwrd, frwrd])
θ̤ƥȹñ(ľ((|bkwrd|))ԡľ
((|frwrd|)))ǼФޤ
δؿϢ³ƸƤ֤ȡ٤Ƥθ̤ޤĤθ
̤ʤȤ (({nil})) ֤ޤ
--- Searcher#each_context_line{|text| ...}
̤ޤԤФ륤ƥ졼
--- Searcher#each_context_lines([bkwrd, frwrd]){|text| ...}
̤ޤॳƥȹԤФ륤ƥ졼
--- Searcher#get_next_context_region(start_tag, end_tag)
θ̤ ((|start_tag|)) ((|end_tag|)) ǰϤޤ줿ΰȤ
ƼФޤ(((|start_tag|)) ((|end_tag|)) ޤߤޤ)
δؿϢ³ƸƤ֤ȡ٤Ƥθ̤ޤĤθ
̤ʤȤ (({nil})) ֤ޤ
--- Searcher#get_offsets
̤եƬΥեåͤȤƼޤ
--- Searcher#get_line_by_offset(offset)
եΥեåͤ1ʬʸȤƼޤ
--- Searcher#get_ranges
̤եϰ(Range֥)ȤƼޤ
--- Searcher#get_line_by_range(range)
rangeǻꤵ줿եϰ(Range֥)ʸȤƼ
ޤ
--- Searcher#count_occurrences
Υҥåȿ֤ޤ
--- Searcher#sort_occurrences
̤иֽ˥Ȥޤ
--- Searcher#enable_cache
å嵡Ưޤ̤å夷Ʊѥ
2ܰʹߤθ®ޤ
--- Searcher.array_sort(filename)
((|filename|)).ary եȤޤ
Ԥ (({IOError})) 㳰ȯޤ
== Builder class
Suffix Array 뤿Υ饹Ǥ
--- Builder.new(filename[,arrayname])
˥ƥȥե̾ array ե̾ꤷޤ
array ե̾ά ((|filename|)).ary Ȥޤ
Ԥ (({IOError})) 㳰ȯޤ
--- Builder#sort [{|task, current, total, is_finished|...}]
Suffix Array ΥȤԤʤޤ
ץ쥹Сɽ뤿Υ֥åϤȤǤޤ
Ԥ (({RuntimeError})) 㳰ȯޤ
--- Builder#block_sort [{|task, current, total, is_finished|...}]
Suffix Array ΥȤԤʤޤ֥åñ̤ǥȤԤʤ
ᡢǤޤ
ץ쥹Сɽ뤿Υ֥åϤȤǤޤ
Ԥ (({RuntimeError})) 㳰ȯޤ
--- Builder#set_block_size(size)
((<Builder#block_sort>)) ΤΥ֥åꤷޤ
--- Builder#set_nthread(n)
((<Builder#block_sort>)) ԤʤȤΥåɤοꤷޤ
CPU ʣǤ®٤夷ޤ
=end
$Id: Reference.ja.rd,v 1.2 2005/03/29 04:20:50 knok Exp $
|