diff options
| author | bculkin2442 <bjculkin@mix.wvu.edu> | 2017-03-26 11:31:17 -0400 |
|---|---|---|
| committer | bculkin2442 <bjculkin@mix.wvu.edu> | 2017-03-26 11:31:17 -0400 |
| commit | 2abf8d66776a61f7698830da3b80ab524d7318ef (patch) | |
| tree | b68cb7bea4e89a0d90b1832ea04d72a543774ae8 /RGens/src/main/java/bjc/rgens/text/markov/StandaloneTextGenerator.java | |
| parent | 3cb61c2aede328e2c302f8cfd030478727fca66c (diff) | |
Update
Diffstat (limited to 'RGens/src/main/java/bjc/rgens/text/markov/StandaloneTextGenerator.java')
| -rw-r--r-- | RGens/src/main/java/bjc/rgens/text/markov/StandaloneTextGenerator.java | 42 |
1 files changed, 24 insertions, 18 deletions
diff --git a/RGens/src/main/java/bjc/rgens/text/markov/StandaloneTextGenerator.java b/RGens/src/main/java/bjc/rgens/text/markov/StandaloneTextGenerator.java index 92bc653..17cd670 100644 --- a/RGens/src/main/java/bjc/rgens/text/markov/StandaloneTextGenerator.java +++ b/RGens/src/main/java/bjc/rgens/text/markov/StandaloneTextGenerator.java @@ -5,19 +5,25 @@ import java.io.Reader; import java.util.HashMap; import java.util.Map; +/** + * Create a Markov generate from a provided source. + * + * @author bjculkin + * + */ public class StandaloneTextGenerator { - /** - * Build a markov generator from a provided source + * Build a markov generator from a provided source. + * + * @param order + * The markov order to use. * - * @param k - * The markov order to use * @param reader - * The source to seed the generator from - * @return The markov generator for the provided text + * The source to seed the generator from. + * + * @return The markov generator for the provided text. */ - public static StandaloneMarkov generateMarkovMap(int k, - Reader reader) { + public static StandaloneMarkov generateMarkovMap(int order, Reader reader) { Map<String, Markov> hash = new HashMap<>(); Character next = null; @@ -25,9 +31,10 @@ public class StandaloneTextGenerator { try { next = (char) reader.read(); } catch (IOException e1) { - System.out - .println("IOException in stepping through the reader"); + System.out.println("IOException in stepping through the reader"); + e1.printStackTrace(); + System.exit(1); } @@ -40,19 +47,19 @@ public class StandaloneTextGenerator { try { next = (char) reader.read(); } catch (IOException e) { - System.out.println( - "IOException in stepping through the reader"); + System.out.println("IOException in stepping through the reader"); + e.printStackTrace(); } } String origFile = origFileBuffer.toString(); - String firstSub = origFile.substring(0, k); + String firstSub = origFile.substring(0, order); - for (int i = 0; i < origFile.length() - k; i++) { - String sub = origFile.substring(i, i + k); - Character suffix = origFile.charAt(i + k); + for (int i = 0; i < origFile.length() - order; i++) { + String sub = origFile.substring(i, i + order); + Character suffix = origFile.charAt(i + order); if (hash.containsKey(sub)) { Markov marvin = hash.get(sub); @@ -64,7 +71,6 @@ public class StandaloneTextGenerator { } } - return new StandaloneMarkov(k, hash, firstSub); + return new StandaloneMarkov(order, hash, firstSub); } - } |
