Package com.gengoai.hermes.lexicon
Class TrieLexicon
- java.lang.Object
-
- com.gengoai.hermes.lexicon.Lexicon
-
- com.gengoai.hermes.lexicon.TrieLexicon
-
- All Implemented Interfaces:
Extractor
,PrefixSearchable
,WordList
,Serializable
,Iterable<String>
,Predicate<HString>
public class TrieLexicon extends Lexicon
Implementation of
Lexicon
usng a Trie data structure.- Author:
- David B. Bracewell
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description TrieLexicon(String name, boolean caseSensitive)
Instantiates a new TrieLexicon.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
add(@NonNull LexiconEntry lexiconEntry)
Adds an entry to the lexiconboolean
contains(String string)
Is the String contained in the WordListSet<LexiconEntry>
entries()
Set<LexiconEntry>
get(String word)
Returns theLexiconEntry
associated with a given word in the Lexicon or an empty set if there are none.int
getMaxLemmaLength()
int
getMaxTokenLength()
@NonNull String
getName()
boolean
isCaseSensitive()
Is the Lexicon case sensitive or notboolean
isPrefixMatch(HString hString)
Check if a prefix matches the givenHString
boolean
isPrefixMatch(String string)
Check if a prefix matches the given Stringboolean
isProbabilistic()
Is the Lexicon case sensitive or notIterator<String>
iterator()
List<LexiconEntry>
match(HString string)
Gets the matched entries for a givenHString
List<LexiconEntry>
match(String hString)
Returns theLexiconEntry
associated with a given word in the Lexicon or an empty set if there are none.Set<String>
prefixes(String string)
Gets the prefixes that match the given stringint
size()
The number of lexical items in the lexiconMap<String,Integer>
suggest(String element)
Suggest map.Map<String,Integer>
suggest(String element, int maxCost)
Suggest map.Map<String,Integer>
suggest(String element, int maxCost, int substitutionCost)
Suggest map.-
Methods inherited from class com.gengoai.hermes.lexicon.Lexicon
addAll, extract, getProbability, getProbability, getProbability, getProbability, getTag, getTag, normalize, test
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
Constructor Detail
-
TrieLexicon
public TrieLexicon(String name, boolean caseSensitive)
Instantiates a new TrieLexicon.- Parameters:
name
- the namecaseSensitive
- True - if case matters, False case does not matter
-
-
Method Detail
-
add
public void add(@NonNull @NonNull LexiconEntry lexiconEntry)
Description copied from class:Lexicon
Adds an entry to the lexicon
-
contains
public boolean contains(String string)
Description copied from interface:WordList
Is the String contained in the WordList- Parameters:
string
- the string to lookup- Returns:
- True if the string is in the WordList, False otherwise
-
entries
public Set<LexiconEntry> entries()
-
get
public Set<LexiconEntry> get(String word)
Description copied from class:Lexicon
Returns theLexiconEntry
associated with a given word in the Lexicon or an empty set if there are none.- Specified by:
get
in classLexicon
- Parameters:
word
- the word in the lexicon whose entries we want- Returns:
- the
LexiconEntry
associated with a given word in the Lexicon or an empty set if there are none.
-
getMaxLemmaLength
public int getMaxLemmaLength()
- Specified by:
getMaxLemmaLength
in classLexicon
- Returns:
- the max lemma length
-
getMaxTokenLength
public int getMaxTokenLength()
- Specified by:
getMaxTokenLength
in classLexicon
- Returns:
- the max token length
-
getName
@NonNull public @NonNull String getName()
-
isCaseSensitive
public boolean isCaseSensitive()
Description copied from class:Lexicon
Is the Lexicon case sensitive or not- Specified by:
isCaseSensitive
in classLexicon
- Returns:
- True if the lexicon is case sensitive, False if not
-
isPrefixMatch
public boolean isPrefixMatch(HString hString)
Description copied from interface:PrefixSearchable
Check if a prefix matches the givenHString
- Parameters:
hString
- theHString
to check for a prefix match- Returns:
- True if a prefix matches, False otherwise
-
isPrefixMatch
public boolean isPrefixMatch(String string)
Description copied from interface:PrefixSearchable
Check if a prefix matches the given String- Parameters:
string
- the String to check for a prefix match- Returns:
- True if a prefix matches, False otherwise
-
isProbabilistic
public boolean isProbabilistic()
Description copied from class:Lexicon
Is the Lexicon case sensitive or not- Specified by:
isProbabilistic
in classLexicon
- Returns:
- True if the lexicon is case sensitive, False if not
-
match
public List<LexiconEntry> match(HString string)
Description copied from class:Lexicon
Gets the matched entries for a givenHString
-
match
public List<LexiconEntry> match(String hString)
Description copied from class:Lexicon
Returns theLexiconEntry
associated with a given word in the Lexicon or an empty set if there are none.- Specified by:
match
in classLexicon
- Parameters:
hString
- the word in the lexicon whose entries we want- Returns:
- the
LexiconEntry
associated with a given word in the Lexicon or an empty set if there are none.
-
prefixes
public Set<String> prefixes(String string)
Description copied from interface:PrefixSearchable
Gets the prefixes that match the given string- Parameters:
string
- the string- Returns:
- the set of matching prefixes
-
size
public int size()
Description copied from class:Lexicon
The number of lexical items in the lexicon
-
suggest
public Map<String,Integer> suggest(String element)
Suggest map.- Parameters:
element
- the element- Returns:
- the map
-
suggest
public Map<String,Integer> suggest(String element, int maxCost)
Suggest map.- Parameters:
element
- the elementmaxCost
- the max cost- Returns:
- the map
-
-