@Beta public class GenericTrieMatcher<T> extends Object
| Modifier and Type | Class and Description |
|---|---|
static class |
GenericTrieMatcher.GenericTrieMatch<K>
Struct returned by
TrieMatcher#match(String) to represent a match. |
static interface |
GenericTrieMatcher.MatchValidator<K>
An interface that represents whether a match for a given string is "valid"
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
begins(List<T> s) |
static <TOKEN> GenericTrieMatcher<TOKEN> |
compile(List<? extends List<TOKEN>> searches,
List<? extends List<TOKEN>> replacements)
This is not the cheapest of operations.
|
static <TOKEN> GenericTrieMatcher<TOKEN> |
compile(List<? extends List<TOKEN>> searches,
List<? extends List<TOKEN>> replacements,
Class<TOKEN> tokenClass)
This is not the cheapest of operations.
|
boolean |
containedIn(List<T> s) |
List<T> |
findIn(List<T> s,
int start)
Find the next match in
s. |
GenericTrieMatcher.GenericTrieMatch<T> |
match(List<T> s,
int offset)
See if the given string matches any of the given words in the Trie
|
static <T> List<T> |
replaceMultiple(List<T> s,
GenericTrieMatcher<T> trieMatcher)
Search and replace multiple strings in
s given the the words and replacements given in
TrieMatcher. |
static <T> List<T> |
replaceMultiple(List<T> s,
GenericTrieMatcher<T> trieMatcher,
GenericTrieMatcher.MatchValidator<T> validator)
Search and replace multiple strings in
s given the the words and replacements given in
TrieMatcher and a validation strategy |
public static <TOKEN> GenericTrieMatcher<TOKEN> compile(List<? extends List<TOKEN>> searches, List<? extends List<TOKEN>> replacements)
searches - this is the list of words that make up the Trie.
It is assumed that the lists are not modified once passed into the Triereplacements - the list of words that can be used to replace those words.
It is assumed that the lists are not modified once passed into the Triepublic static <TOKEN> GenericTrieMatcher<TOKEN> compile(List<? extends List<TOKEN>> searches, List<? extends List<TOKEN>> replacements, Class<TOKEN> tokenClass)
searches - this is the list of words that make up the Trie.
It is assumed that the lists are not modified once passed into the Triereplacements - the list of words that can be used to replace those words.
It is assumed that the lists are not modified once passed into the TrietokenClass - based on the class, a more efficient trie map can be generatedpublic static final <T> List<T> replaceMultiple(List<T> s, GenericTrieMatcher<T> trieMatcher)
s given the the words and replacements given in
TrieMatcher.
Note, using a Trie for matching multiple strings can be much faster than the using
#replace(String, String[], String[]), however, due to the cost of creating the Trie, this is best used
when 1) you will reuse the Trie many times 2) you have a large set of strings your are searching on
Note, regexes aren't supported by this, see #replace(String, String[], String[]).
s - the text you are searching intrieMatcher - the trie representing the words to search and replace forpublic static final <T> List<T> replaceMultiple(List<T> s, GenericTrieMatcher<T> trieMatcher, GenericTrieMatcher.MatchValidator<T> validator)
s given the the words and replacements given in
TrieMatcher and a validation strategy
s - the text you are searching intrieMatcher - the trie representing the words to search and replace forvalidator - the optional code that validates whether a match should be accepted or not.public boolean containedIn(List<T> s)
s - the term to search for the terms of the trie inspublic boolean begins(List<T> s)
s - the term to see if it starts with any terms of the triepublic List<T> findIn(List<T> s, int start)
s.s - the term to search for the terms of the trie instart - the 0-based position to start the search from.public GenericTrieMatcher.GenericTrieMatch<T> match(List<T> s, int offset)
offset - where to start looking inside of the given String.Copyright (c) 2016-2017, Salesforce.com, Inc. All rights reserved. Licensed under the BSD 3-Clause license. For full license text, see the LICENSE.txt file in the repository.