1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Python から MARISA Trie を使えるライブラリを複数環境対応にしました。

1
Last updated at Posted at 2026-02-17

C++ 製 Trie ライブラリ MARISA Trie を、より多くの環境で Python から利用できるようにしました。

Python 3.10〜3.14 に対応し、Linux・Windows・macOS 環境でビルド済みのバイナリを利用できます。

必要なのは pip install marisa-bindings だけです。処理本体は C++ 実装のため、高速に動作します。

できること

Marisa Trie は、コンパクトで高速な Trie データ構造の実装です。構築した Trie に対して、次の検索操作を実行できます。

  • Lookup (完全一致検索)
  • Reverse lookup (ID による逆引き検索)
  • Common prefix search (前方一致検索)
  • Predictive search (予測検索)

marisa-bindings を利用すると、これらのネイティブ API を Python からそのまま呼び出せます。

利用方法

基本的な利用の流れは、次の 3 ステップです。

  1. Keyset (文字列の集合) を作成する。
  2. Keyset から Trie (辞書) を構築する。
  3. 検索する。
from marisa_bindings import marisa

# Keyset を作成する。
keyset = marisa.Keyset()

for word in ["apple", "app", "banana"]:
    keyset.push_back(word)

# Keyset から Trie (辞書) を構築する。
trie = marisa.Trie()
trie.build(keyset)

# 完全一致検索する。
print(trie.lookup("apple"))

# 前方一致検索する。
agent = marisa.Agent()
agent.set_query("app")

while trie.common_prefix_search(agent):
    print(agent.key_str())

今回の変更点

今回の更新では、配布対象環境と動作保証の範囲を大きく拡張しました。

  • Python 3.10〜3.14 に対応した Linux・Windows・macOS 環境向けのビルド済み wheel を追加しました。
  • ビルド済み wheel を提供していない環境向けに sdist も引き続き配布しています。
  • CI を整備し、wheel・sdist 共に各環境で配布前にビルドとテストを実施しています。

これにより、MARISA Trie をより多くの環境で Python から利用できるようになりました。

リポジトリ

ソースコードや CI 構成も GitHub で OSS として公開しています。

https://github.com/juno-rmks/marisa-bindings

スターで応援していただけると励みになります。

補足事項

本ライブラリは、非公認のプロジェクトであり、MARISA Trie 本体の作者とは無関係です。

問題報告や改善提案があれば、本ライブラリの Issue へ報告いただけると助かります。

1
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?