String searching algorithms in Java

前端 未结 5 2070
不知归路
不知归路 2021-01-01 07:29

I am doing string matching with big amount of data.

EDIT: I am matching words contained in a big list with some ontology text files. I take each file from ontology,

5条回答
  •  庸人自扰
    2021-01-01 08:01

    You might find Suffix Trees useful (they are similar in concept to Tries).

    Each string, you prepend with ^ and end with $ and create a suffix tree of all the strings appended. Space usage will be O(n) and will be probably worse than what you had for the trie.

    If you now need to search for a string s, you can easily do in O(|s|) time, just like a trie and the match you get will be a substring match (basically, you will be matching some suffix of some string).

    Sorry, I don't have a reference to a Java implementation handy.

    Found a useful stackoverflow answer: Generalized Suffix Tree Java Implementation

    Which has: http://illya-keeplearning.blogspot.com/2009/04/suffix-trees-java-ukkonens-algorithm.html

    Which in turn has: Source Code: http://illya.yolasite.com/resources/suffix-tree.zip

提交回复
热议问题