GithubHelp home page GithubHelp logo

darts-java's Introduction

darts-java: Double-ARray Trie System Java implementation.

概要

Taku Kudo さんの Double Array Trie の C++ 実装 (*1) を MURAWAKI Yugo さんが Java ポーティングしたバージョン (*2) に対して、 より Java らしいインタフェースに変更し、また性能面も改善した Darts の Java 実装です。

元実装 (Java ポーティング版) からの改善点

  • インタフェースの改善
  • 文字列の char[] 表現や配列の多用を改め、より Java らしいインタフェースで、かつ手軽に利用できるインタフェースとしました。
  • 入力データによってエラーとなるケースへの対処
  • ヒープ消費量の改善
  • Trie 構築時、および構築後のヒープ消費量が少なくなるようにしました (元実装の約 26% のヒープ消費量)。
  • 実行速度の改善
  • Trie の構築 (約 2.6 倍) や exact match での検索 (約 1.7 倍)、common prefix での検索 (約 1.2 倍) それぞれについて処理性能を向上しました。

使い方

DoubleArrayTrie.java を単品でご利用ください(実装はこのファイル一つで完結しています)。

Benchmark

テストデータ

Ubuntu 12 の /usr/share/dict/words (916 KB、99171 語) をテストデータとして利用しています。

測定方法

  • ヒープ消費量
  • DoubleArrayTrie#build() の呼び出し前後それぞれにおいて、ヒープ消費量を Runtime#totalMemory() / Runtime#freeMemory() にて計測し、その差分をとることで 構築後のヒープ消費量を算出しています。
  • build() 処理時間
  • ファイルから読み込んだテストデータを build() で 50 回処理し、その平均と標準偏差を算出しています。
  • exactMatchSearch() 処理時間
  • テストデータをもとに構築された Trie に対して、テストデータの語句すべてを 順に exact match 検索する処理を 50 回実施し、その平均と標準偏差を算出しています。
  • commonPrefixSearch() 処理時間
  • exactMatchSearch() と同様に、テストデータをもとに構築された Trie に対して、 テストデータの語句すべてを順に common prefix 検索する処理を 50 回実施し、その平均と標準偏差を算出しています。
  • 元実装では、commonPrefixSearch() の結果を同メソッドに渡した int 配列で受け取るインタフェースと なっているため、検索結果の個数を求めるためと、実際の結果を受け取るためのそれぞれ1回ずつ (合計2回)、commonPrefixSearch() を呼び出しています。

測定結果

                              original     imploved
====================================================
ヒープ消費量 [byte]         62,287,864   16,780,160
----------------------------------------------------
build() [msec]                  165.68        64.26
  (標準偏差)                    (82.87)       (6.74)
----------------------------------------------------
exactMatchSearch() [msec]        10.88         6.24
  (標準偏差)                     (7.21)       (7.73)
----------------------------------------------------
commonPrefixSearch() [msec]      17.18        14.04
  (標準偏差)                     (4.68)       (4.75)
----------------------------------------------------

License

LGPL と修正 BSD のデュアルライセンスです。 各ライセンスの詳細は LGPL ファイル、BSD ファイルをご覧ください。

TODO

  • Javadoc を記述する。

darts-java's People

Contributors

komiya-atsushi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

darts-java's Issues

check key conflict

If the last two characters of the first string in the list are consecutive coding, then only the last character can be queried to return the correct result, which is different from the expected.

Code example:
//list add 123 or 234 or 345
//key = 3 or 4 or 5
//The results are all matchable
DoubleArrayTrie adt = new DoubleArrayTrie();
List list = new ArrayList();
list.add("123");
// 所有词必须先排序
Collections.sort(list);
// 构建DoubleArrayTrie
adt.build(list);
String key = "3";
// 检索key是否完全命中了词典中的某个词
int index = adt.exactMatchSearch(key);
System.out.println(index)
//print result 0

license: Can I just choose Modified BSD for my projects only?

Darts-java is a good implementation of DAT( double array trie), and I really appreciate your hard work. I developed a project, and some of its code based on your darts-java. darts-java is dual licensed, but I feel confused the words - " It is dual licensed, LGPL and Modified BSD." that comes from the website http://chasen.org/~taku/software/darts/. Can I just choose Modified BSD for my projects only?

Implementation of trie with double arrays. A port of Darts implemented in C++ to Java. Sen, who ported his old MeCab to Java, also has a DoubleArrayTrie with the same name, but since it was old and the license was forked from his LGPL-only state, it was not easy to use, so I rewrote it myself . . It is dual licensed, LGPL and Modified BSD.

copy error

In the function of resize,"System.arraycopy(used2, 0, used2, 0, allocSize)" should be "System.arraycopy(used, 0, used2, 0, allocSize)"

i find a bug

i find a bug
in the resize method have a bug;
bug code is
System.arraycopy(used2, 0, used2, 0, allocSize);
right code is
System.arraycopy(used, 0, used2, 0, allocSize);

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.