Updated README.md documentation

This commit is contained in:
robert-bor 2015-09-23 08:39:13 +02:00
parent e365689391
commit a46177415f
2 changed files with 42 additions and 3 deletions

View File

@ -95,8 +95,8 @@ If you want the algorithm to only check for whole words, you can tell the Trie t
In this case, it will only find one match, whereas it would normally find four. The sugarcane/canesugar words
are discarded because they are partial matches.
Some text are WrItTeN in combinations of lowercase and uppercase and therefore hard to identify. You can instruct
the Trie to lowercase the entire searchtext to ease the matching process.
Some text is WrItTeN in a combination of lowercase and uppercase and therefore hard to identify. You can instruct
the Trie to lowercase the entire searchtext to ease the matching process. The lower-casing extends to keywords as well.
```java
Trie trie = Trie.builder()
@ -110,6 +110,41 @@ Normally, this match would not be found. With the caseInsensitive settings the e
before the matching begins. Therefore it will find exactly one match. Since you still have control of the original
search text and you will know exactly where the match was, you can still utilize the original casing.
It is also possible to just ask whether the text matches any of the keywords, or just to return the first match it
finds.
```java
Trie trie = Trie.builder().removeOverlaps()
.addKeyword("ab")
.addKeyword("cba")
.addKeyword("ababc")
.build();
Emit firstMatch = trie.firstMatch("ababcbab");
```
The firstMatch will now be "ababc" found at position 0.
If you just want the barebones Aho-Corasick algorithm (ie, no dealing with case insensitivity, overlaps and whole
words) and you prefer to add your own handler to the mix, that is also possible.
```java
Trie trie = Trie.builder()
.addKeyword("hers")
.addKeyword("his")
.addKeyword("she")
.addKeyword("he")
.build();
final List<Emit> emits = new ArrayList<>();
EmitHandler emitHandler = new EmitHandler() {
@Override
public void emit(Emit emit) {
emits.add(emit);
}
};
```
In many cases you may want to do useful stuff with both the non-matching and the matching text. In this case, you
might be better served by using the Trie.tokenize(). It allows you to loop over the entire text and deal with
matches as soon as you encounter them. Let's look at an example where we want to highlight words from HGttG in HTML:
@ -139,6 +174,10 @@ matches as soon as you encounter them. Let's look at an example where we want to
System.out.println(html);
```
Releases
--------
Information on the aho-corasick [releases](https://github.com/robert-bor/aho-corasick/releases).
License
-------
Licensed under the Apache License, Version 2.0 (the "License");

View File

@ -3,7 +3,7 @@
<groupId>org.ahocorasick</groupId>
<artifactId>ahocorasick</artifactId>
<version>0.3.0</version>
<version>0.3.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Aho-CoraSick algorithm for efficient string matching</name>
<description>Java library for efficient string matching against a large set of keywords</description>