Sha256: 492a8447383a578bd3be25bc7fb52afd5c084980432783ede6efff8539c64e6a

Contents?: true

Size: 1.5 KB

Versions: 1

Compression:

Stored size: 1.5 KB

Contents

require "marisa"

keyset = Marisa::Keyset.new
keyset.push_back("cake")
keyset.push_back("cookie")
keyset.push_back("ice")
keyset.push_back("ice-cream")

trie = Marisa::Trie.new
trie.build(keyset)
print("no. keys: ", trie.num_keys(), "\n")
print("no. tries: ", trie.num_tries(), "\n")
print("no. nodes: ", trie.num_nodes(), "\n")
print("size: ", trie.io_size(), "\n")

agent = Marisa::Agent.new

agent.set_query("cake")
trie.lookup(agent)
print(agent.query_str(), ": ", agent.key_id(), "\n")

agent.set_query("cookie")
trie.lookup(agent)
print(agent.query_str(), ": ", agent.key_id(), "\n")

agent.set_query("cockoo")
if not trie.lookup(agent)
  print(agent.query_str(), ": not found\n")
end

print("ice: ", trie.lookup("ice"), "\n")
print("ice-cream: ", trie.lookup("ice-cream"), "\n")
if trie.lookup("ice-age") == Marisa::INVALID_KEY_ID
  print("ice-age: not found\n")
end

trie.save("sample.dic")
trie.load("sample.dic")

agent.set_query(0)
trie.reverse_lookup(agent)
print(agent.query_id(), ": ", agent.key_str(), "\n")

agent.set_query(1)
trie.reverse_lookup(agent)
print(agent.query_id(), ": ", agent.key_str(), "\n")

print("2: ", trie.reverse_lookup(2), "\n")
print("3: ", trie.reverse_lookup(3), "\n")

trie.mmap("sample.dic")

agent.set_query("ice-cream soda")
while trie.common_prefix_search(agent)
  print(agent.query_str(), ": ", agent.key_str(), " (", agent.key_id(), ")\n")
end

agent.set_query("ic")
while trie.predictive_search(agent)
  print(agent.query_str(), ": ", agent.key_str(), " (", agent.key_id(), ")\n")
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
marisa-0.2.6 ext/marisa/sample.rb