Package engine
Class Chain
- java.lang.Object
-
- engine.Chain
-
public final class Chain extends java.lang.Object
The Chain class provides short and elegant ways to store and get the token list and Markov-Chain data structures of a text. It has basic getters for each instance variable and enforces immutability for data safety. This class is NOT thread-safe and should not be used in parallel.- Since:
- Alpha 1.0
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static @NotNull Chain
createByNgrams(java.lang.String filteredText, int order)
Factory.static @NotNull Chain
createByWords(java.lang.String filteredText)
Factory.java.lang.String
jsonRepresentation()
Getterjava.util.Map<java.lang.String,java.util.List<java.lang.String>>
markovChain()
Gettervoid
save(@NotNull java.nio.file.Path directory)
Saves the jsonRepresentation String instance variable into a new json file.java.util.List<java.lang.String>
tokens()
Getter
-
-
-
Method Detail
-
createByNgrams
@Contract("_, _ -> new") @NotNull public static @NotNull Chain createByNgrams(java.lang.String filteredText, int order)
Factory. Creates a Markovener object by calling the private constructor.- Parameters:
filteredText
- to be tokenized and mapped.order
- to split the ngrams.- Returns:
- an instance of the Markovener class tokenized and mapped by ngrams.
-
createByWords
@NotNull public static @NotNull Chain createByWords(java.lang.String filteredText)
Factory. Creates a Markovener object by calling the private constructor.- Parameters:
filteredText
- to be tokenized and mapped.- Returns:
- an instance of the Markovener class tokenized and mapped by words.
-
tokens
public java.util.List<java.lang.String> tokens()
Getter- Returns:
- token list - instance variable.
-
markovChain
public java.util.Map<java.lang.String,java.util.List<java.lang.String>> markovChain()
Getter- Returns:
- markov-chain map - instance variable.
-
jsonRepresentation
public java.lang.String jsonRepresentation()
Getter- Returns:
- jsonRepresentation - instance variable.
-
save
public void save(@NotNull @NotNull java.nio.file.Path directory) throws java.io.IOException
Saves the jsonRepresentation String instance variable into a new json file.- Parameters:
directory
- to create a new json file- Throws:
java.io.IOException
- if some IOException occurs. Your path might be invalid or the directory is not accessible by the application.
-
-