Updated README.md documentation
This commit is contained in:
parent
e365689391
commit
a46177415f
43
README.md
43
README.md
@ -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
|
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.
|
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
|
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 Trie to lowercase the entire searchtext to ease the matching process. The lower-casing extends to keywords as well.
|
||||||
|
|
||||||
```java
|
```java
|
||||||
Trie trie = Trie.builder()
|
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
|
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.
|
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
|
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
|
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:
|
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);
|
System.out.println(html);
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Releases
|
||||||
|
--------
|
||||||
|
Information on the aho-corasick [releases](https://github.com/robert-bor/aho-corasick/releases).
|
||||||
|
|
||||||
License
|
License
|
||||||
-------
|
-------
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
|||||||
2
pom.xml
2
pom.xml
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
<groupId>org.ahocorasick</groupId>
|
<groupId>org.ahocorasick</groupId>
|
||||||
<artifactId>ahocorasick</artifactId>
|
<artifactId>ahocorasick</artifactId>
|
||||||
<version>0.3.0</version>
|
<version>0.3.1-SNAPSHOT</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
<name>Aho-CoraSick algorithm for efficient string matching</name>
|
<name>Aho-CoraSick algorithm for efficient string matching</name>
|
||||||
<description>Java library for efficient string matching against a large set of keywords</description>
|
<description>Java library for efficient string matching against a large set of keywords</description>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user