[[FrontPage]]

This is a Ruby 1.8/1.9 binding of Tx, a library for a compact trie data structure.

For details of Tx, see: [[Tx: Succinct Trie Data structure:http://www-tsujii.is.s.u-tokyo.ac.jp/~hillbig/tx.htm]]

#contents

** How to install [#y0d82ffb]

 $ gem install tx

Or

 $ wget http://gimite.net/archive/tx-ruby-0.0.5.tar.gz
 $ tar xvzf tx-ruby-*.tar.gz
 $ cd tx-ruby
 $ sudo ruby setup.rb

- If your Ruby is 1.8.x mswin32, you don't need compilers (binary is bundled).
- Tx library is bundled, so you don't need to install it separately.

** Document [#b2f21339]

- [[Document in RDoc format:http://gimite.net/gimite/rubymess/tx-ruby/]]
- Usage example of simple index:

  require "rubygems"
  require "tx"
  
  # Builds an index and saves it to a file.
  builder = Tx::Builder.new
  builder.add_all(["foo", "ho", "hog", "hoga", "hoge", "hogeshi"])
  builder.build("test.index")
  
  # Loads an index.
  index = Tx::Index.open("test.index")
  
  # Simple lookup.
  index.include?("hoge")           #=> true
  index.include?("bar")            #=> false
  
  # Searches prefixes of the word.
  index.longest_prefix("hogeeee") #=> 4 (which means "hoge" is in the index)
  index.search_prefixes("hoge")   #=> ["ho", "hog", "hoge"]
  
  # Searches words which begin with the string.
  index.search_expansions("hog")  #=> ["hog", "hoga", "hoge", "hogeshi"]
  
  # Finds all occurences of words in the index.
  index.scan("hogefugafoo")       #=> [["hoge", 0], ["foo", 8]]
  
  # Replaces words in the index.
  index.gsub("hogefugafoo"){ |s, i| s.upcase }
                                  #=> "HOGEfugaFOO"

- Usage example of Hash-like index:

  require "tx"
  
  # Builds an index and saves it to a file.
  builder = Tx::MapBuilder.new
  builder.add("ho", "foo")
  builder.add("hoge", "bar")
  builder.build("test")
  
  # Loads an index.
  map = Tx::Map.open("test")
  
  # Simple lookup.
  map.has_key?("hoge")                     #=> true
  map["hoge"]                             #=> "bar"
  map["fuga"]                             #=> nil
  
  # Searches prefixes/expansion of the word in keys.
  map.key_index.longest_prefix("hogeeee") #=> 4 (which means the index has a key "hoge")
  map.key_index.search_prefixes("hoge")   #=> ["ho", "hoge"]
  map.key_index.search_expansions("ho")   #=> ["ho", "hoge"]
  
  # Finds all occurences of keys in the index.
  index.scan("hogehoga")                  #=> [["hoge", 0, "bar"], ["ho", 4, "foo"]]

** License [#ldb17bfc]

New BSD License.

** History [#x9b5a3e1]

- 0.0.5
-- Based on Tx 0.13.
-- Fixed compilation error in recent Ubuntu (thanks to ROBA).
-- Supported Ruby 1.9.x.
-- Added Set/Hash-like methods to Tx::Index and Tx::Map.
- 0.0.4
-- Based on Tx 0.09.
-- Added Hash-like interface: Tx::Map and Tx::MapBuilder.
- 0.0.3
-- Added Tx::Index#scan and Tx::Index#gsub.
-- Fixed a bug that Ruby crashes when opening non-existing index file.
- 0.0.2
-- ''(Incompatible with 0.0.1)'' Result of Tx::Index#search_expansions now includes str itself if it's in the index.
-- Fixed performance problem.
- 0.0.1
-- First version. Based on Tx 0.0.4.

** How to hack [#kb362ca2]

Source code is on [[Github:http://github.com/gimite/tx-ruby]].

Some hints:
- This library is implemented with SWIG (So I guess it's easy to generate binding for other script languages). You need to install SWIG to regenerate ext/tx_swig_wrap.cxx if you edit ext/tx_swig.{h,i}.
- To generate ext/tx_swig_wrap.cxx which works on Ruby 1.9, you need to apply ext/swig.patch to SWIG.
- To build lib/i386-msvcrt/tx_core.so, follow [[instruction here:http://d.hatena.ne.jp/Gimite/searchdiary?word=cygwin]] (Japanese).

** Comments [#j6538610]

#comment

トップ   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS