public class MarkovObject<T>
extends java.lang.Object
implements java.io.Serializable
MarkovTextLimited
.
Call analyze(Iterable)
or analyze(Object[])
once on a large sample Iterable or array where
sequences of items matter (this is called a corpus, and could be e.g. a List or an array), then you can call
chain(long)
many times to get "remixes" of the sample Iterable/array as a List. This is meant to allow easy
serialization of the necessary data to call chain(); if you can store the body
and processed
data
structures in some serialized form, then you can reassign them to the same fields to avoid calling analyze(). This
requires some way to serialize body, which is an Arrangement
of T, and so T must be serializable in some way
(not necessarily the Serializable
interface, but possibly that).
Modifier and Type | Field and Description |
---|---|
Arrangement<T> |
body
All unique T items that this encountered during the latest call to
analyze(Iterable) . |
java.util.ArrayList<IntVLA> |
processed
Complicated data that mixes probabilities and the indices of items in
body , generated during the latest
call to analyze(Iterable) . |
java.util.ArrayList<IntVLA> |
raw |
Constructor and Description |
---|
MarkovObject() |
Modifier and Type | Method and Description |
---|---|
void |
analyze(java.lang.Iterable<T> corpus)
This is the main necessary step before using a MarkovObject; you must call this method at some point before you
can call any other methods.
|
void |
analyze(T[] corpus)
This is the main necessary step before using a MarkovObject; you must call this method at some point before you
can call any other methods.
|
java.util.List<T> |
chain(long seed)
Generates a 32-element List of T based on the given seed and previously analyzed corpus data (using
analyze(Iterable) ). |
java.util.List<T> |
chain(long seed,
int maxLength,
boolean canStopEarly,
java.util.List<T> buffer)
Adds T items to buffer to fill it up to maxLength, based on the given seed and previously analyzed corpus
data (using
analyze(Iterable) ). |
MarkovObject<T> |
copy()
|
public Arrangement<T> body
analyze(Iterable)
.
Will be null if analyze() was never called.public java.util.ArrayList<IntVLA> processed
body
, generated during the latest
call to analyze(Iterable)
. Will be null if analyze() was never called.public java.util.ArrayList<IntVLA> raw
public void analyze(java.lang.Iterable<T> corpus)
null
to represent the start of a section (effectively treating any corpus as
starting with null prepended), and will not produce null as output from chain(long)
. If null is
encountered as part of corpus, it will be interpreted as a point to stop on and potentially start a new section.
Since the last item in the corpus could have no known items to produce after it, the end of the corpus is treated
as having null appended as well. When it finishes processing, it stores the results in body
and
processed
, which allows other methods to be called (they will throw a NullPointerException
if
analyze() hasn't been called).
MarkovTextLimited
, you can analyze multiple corpus Iterables by calling this method more than once.corpus
- a typically-large sample Iterable in the style that should be mimickedpublic void analyze(T[] corpus)
null
to represent the start of a section (effectively treating any corpus as
starting with null prepended), and will not produce null as output from chain(long)
. If null is
encountered as part of corpus, it will be interpreted as a point to stop on and potentially start a new section.
Since the last item in the corpus could have no known items to produce after it, the end of the corpus is treated
as having null appended as well. When it finishes processing, it stores the results in body
and
processed
, which allows other methods to be called (they will throw a NullPointerException
if
analyze() hasn't been called).
MarkovTextLimited
, you can analyze multiple corpus arrays by calling this method more than once.corpus
- a typically-large sample array of T in the style that should be mimickedpublic java.util.List<T> chain(long seed)
analyze(Iterable)
). This can't stop before generating a chain of 32 items unless analyze() hasn't been
called or it was called on an empty or invalid Iterable/array (i.e. all null).seed
- the seed for the random decisions this makes, as a long; any long can be usedpublic java.util.List<T> chain(long seed, int maxLength, boolean canStopEarly, java.util.List<T> buffer)
analyze(Iterable)
). If buffer is already at least as long as maxLength, if analyze() hasn't
been called or if it was called on an empty or invalid Iterable/array (i.e. all null), then this won't change
buffer and will return it as-is. If null was present in the analyzed corpus along with other items and
canStopEarly is true, then if null would be generated this will instead stop adding items to buffer and return
buffer as it is. If canStopEarly was false in the last case, the generated null would be discarded and a value
from the start of the corpus or following a null in the corpus would be used instead.seed
- the seed for the random decisions this makes, as a long; any long can be usedmaxLength
- the maximum length for the generated List, in itemscanStopEarly
- if true, this may add less than maxLength elements if null was present in the corpusbuffer
- a List of T that will have elements added until maxLength is reached; if it already is larger than
maxLength this won't do anythingpublic MarkovObject<T> copy()
body
and the int-based data structure processed
into a new MarkovObject.
None of the inner values, such as IntVLA values in processed, will be equivalent references, but the items in
body will be the same objects in both MarkovObject instances.Copyright © Eben Howard 2012–2022. All rights reserved.