summaryrefslogtreecommitdiff
path: root/RGens/src/main/java/bjc/rgens/text/markov/TextGenerator.java
diff options
context:
space:
mode:
authorbculkin2442 <bjculkin@mix.wvu.edu>2017-03-26 11:31:17 -0400
committerbculkin2442 <bjculkin@mix.wvu.edu>2017-03-26 11:31:17 -0400
commit2abf8d66776a61f7698830da3b80ab524d7318ef (patch)
treeb68cb7bea4e89a0d90b1832ea04d72a543774ae8 /RGens/src/main/java/bjc/rgens/text/markov/TextGenerator.java
parent3cb61c2aede328e2c302f8cfd030478727fca66c (diff)
Update
Diffstat (limited to 'RGens/src/main/java/bjc/rgens/text/markov/TextGenerator.java')
-rwxr-xr-xRGens/src/main/java/bjc/rgens/text/markov/TextGenerator.java47
1 files changed, 26 insertions, 21 deletions
diff --git a/RGens/src/main/java/bjc/rgens/text/markov/TextGenerator.java b/RGens/src/main/java/bjc/rgens/text/markov/TextGenerator.java
index 770acd9..7d20d79 100755
--- a/RGens/src/main/java/bjc/rgens/text/markov/TextGenerator.java
+++ b/RGens/src/main/java/bjc/rgens/text/markov/TextGenerator.java
@@ -10,16 +10,19 @@ import java.io.*;
*/
public class TextGenerator {
/**
+ * Main method.
+ *
* @param args
- * when used with three arguments, the first represents the
- * k-order of the Markov objects. The second represents the
- * number of characters to print out. The third represents
- * the file to be read.
+ * when used with three arguments, the first represents
+ * the k-order of the Markov objects. The second
+ * represents the number of characters to print out. The
+ * third represents the file to be read.
*
- * When used with two arguments, the first represents the
- * k-order of the Markov objects, and the second represents
- * the file to be read. The generated text will be the same
- * number of characters as the original file.
+ * When used with two arguments, the first represents the
+ * k-order of the Markov objects, and the second
+ * represents the file to be read. The generated text
+ * will be the same number of characters as the original
+ * file.
*/
public static void main(String[] args) {
int k = 0;
@@ -31,38 +34,40 @@ public class TextGenerator {
if (args.length == 3) {
k = Integer.parseInt(args[0]);
M = Integer.parseInt(args[1]);
+
file = args[2];
} else if (args.length == 2) {
k = Integer.parseInt(args[0]);
+
file = args[1];
} else {
- System.out
- .println("\n" + "Usage: java TextGenerator k M file");
- System.out.println(
- "where k is the markov order, M is the number");
- System.out.println(
- "of characters to be printed, and file is the");
- System.out.println(
- "name of the file to print from. M may be left out."
- + "\n");
+ System.out.println("\n" + "Usage: java TextGenerator k M file");
+ System.out.println("where k is the markov order, M is the number");
+ System.out.println("of characters to be printed, and file is the");
+ System.out.println("name of the file to print from. M may be left out." + "\n");
System.exit(1);
}
StandaloneMarkov markov = null;
try (FileReader reader = new FileReader(file)) {
- markov = StandaloneTextGenerator.generateMarkovMap(k,
- reader);
+ markov = StandaloneTextGenerator.generateMarkovMap(k, reader);
+
+ String generatedText = markov.generateTextFromMarkov(M);
+ String desiredText = generatedText.substring(0, Math.min(M, text.length()));
- System.out.println(markov.generateTextFromMarkov(M)
- .substring(0, Math.min(M, text.length())));
+ System.out.println(desiredText);
} catch (FileNotFoundException e) {
System.out.println("File not found.");
+
e.printStackTrace();
+
System.exit(1);
} catch (IOException ioex) {
System.out.println("IOException");
+
ioex.printStackTrace();
+
System.exit(1);
}
}