public class WordCache
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
WordCache.Dictionary |
Modifier and Type | Field and Description |
---|---|
private static OrderedScoreMap<java.lang.StringBuilder> |
commonWords |
private static int |
commonWordsMaxSize |
private static int |
commonWordsMinLength |
(package private) java.util.Map<java.lang.String,WordCache.Dictionary> |
dictionaries |
private java.io.File |
dictionaryPath |
private static ConcurrentLog |
log |
Constructor and Description |
---|
WordCache(java.io.File dictionaryPath)
create a new dictionary
This loads all files that ends with '.words'
The files must have one word per line
Comment lines may be given and are encoded as line starting with '#'
|
Modifier and Type | Method and Description |
---|---|
static void |
clearCommonWords() |
boolean |
contains(java.lang.StringBuilder s)
check if the library contains the given word
|
java.util.Map<java.lang.String,WordCache.Dictionary> |
getDictionaries() |
boolean |
isRelevant(int minimumWords)
a property that is used during the construction of recommendation:
if the dictionary is too small, then the non-existence of constructed words
is not relevant for the construction of artificially constructed words
If this property returns true, all other words must be in the dictionary
|
static void |
learn(java.util.Collection<java.lang.String> wordset) |
static void |
learn(java.lang.StringBuilder word)
add a word to the generic dictionary
|
java.util.Set<java.lang.StringBuilder> |
recommend(java.lang.StringBuilder string)
read the dictionary and construct a set of recommendations to a given string
|
void |
reload()
scan the input directory and load all dictionaries (again)
|
private static java.lang.StringBuilder |
reverse(java.lang.StringBuilder s) |
int |
size()
the size of the dictionary
|
static int |
sizeCommonWords() |
boolean |
supports(java.lang.StringBuilder string)
check if the library supports the given word
A word is supported, if the library contains a word
that starts or ends with the given word
|
private static final ConcurrentLog log
private static final int commonWordsMaxSize
private static final int commonWordsMinLength
private static OrderedScoreMap<java.lang.StringBuilder> commonWords
private final java.io.File dictionaryPath
final java.util.Map<java.lang.String,WordCache.Dictionary> dictionaries
public WordCache(java.io.File dictionaryPath)
dictionaryPath
- path to a directory with library filespublic java.util.Map<java.lang.String,WordCache.Dictionary> getDictionaries()
public static void learn(java.lang.StringBuilder word)
word
- public static void learn(java.util.Collection<java.lang.String> wordset)
public void reload()
private static java.lang.StringBuilder reverse(java.lang.StringBuilder s)
public java.util.Set<java.lang.StringBuilder> recommend(java.lang.StringBuilder string)
s
- input value that is used to match recommendationspublic boolean contains(java.lang.StringBuilder s)
s
- the given wordpublic boolean supports(java.lang.StringBuilder string)
s
- the given wordpublic int size()
public static int sizeCommonWords()
public static void clearCommonWords()
public boolean isRelevant(int minimumWords)
minimumWords
-