Sha256: b69fb0fab9ab00cb7edf0d3c92e77764a8092e8f15901aa7fa6cf62e3f6d7151

Contents?: true

Size: 1.45 KB

Versions: 6

Compression:

Stored size: 1.45 KB

Contents

import marisa

keyset = marisa.Keyset()
keyset.push_back("cake")
keyset.push_back("cookie")
keyset.push_back("ice")
keyset.push_back("ice-cream")

trie = marisa.Trie()
trie.build(keyset)
print("no. keys: %d" % trie.num_keys())
print("no. tries: %d" % trie.num_tries())
print("no. nodes: %d" % trie.num_nodes())
print("size: %d" % trie.io_size())

agent = marisa.Agent()

agent.set_query("cake")
trie.lookup(agent)
print("%s: %d" % (agent.query_str(), agent.key_id()))

agent.set_query("cookie")
trie.lookup(agent)
print("%s: %d" % (agent.query_str(), agent.key_id()))

agent.set_query("cockoo")
if not trie.lookup(agent):
  print("%s: not found" % agent.query_str())

print("ice: %d" % trie.lookup("ice"))
print("ice-cream: %d" % trie.lookup("ice-cream"))
if trie.lookup("ice-age") == marisa.INVALID_KEY_ID:
  print("ice-age: not found")

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

agent.set_query(0)
trie.reverse_lookup(agent)
print("%d: %s" % (agent.query_id(), agent.key_str()))

agent.set_query(1)
trie.reverse_lookup(agent)
print("%d: %s" % (agent.query_id(), agent.key_str()))

print("2: %s" % trie.reverse_lookup(2))
print("3: %s" % trie.reverse_lookup(3))

trie.mmap("sample.dic")

agent.set_query("ice-cream soda")
while trie.common_prefix_search(agent):
  print("%s: %s (%d)" % (agent.query_str(), agent.key_str(), agent.key_id()))

agent.set_query("ic")
while trie.predictive_search(agent):
  print("%s: %s (%d)" % (agent.query_str(), agent.key_str(), agent.key_id()))

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
melisa-0.2.5 ext/marisa-0.2.4/bindings/python/sample.py
melisa-0.2.4 ext/marisa-0.2.4/bindings/python/sample.py
melisa-0.2.3 ext/marisa-0.2.4/bindings/python/sample.py
melisa-0.2.2 ext/marisa-0.2.4/bindings/python/sample.py
melisa-0.2.1 ext/marisa-0.2.4/bindings/python/sample.py
melisa-0.2.0 ext/marisa-0.2.4/bindings/python/sample.py