diff options
| author | Benjamin J. Culkin <bjculkin@mix.wvu.edu> | 2017-10-11 22:25:09 -0300 |
|---|---|---|
| committer | Benjamin J. Culkin <bjculkin@mix.wvu.edu> | 2017-10-11 22:25:09 -0300 |
| commit | 924bcdc9a65c7f88004d6dbf8dfa138c9a125e5d (patch) | |
| tree | 396bcf7bb59e17091f268dadebbcdb42725e49c7 /RGens/src/main/java/bjc/rgens/text/markov | |
| parent | 9a0bf41772184f7072f76cfa94e520d022261e4f (diff) | |
Source cleanup
Diffstat (limited to 'RGens/src/main/java/bjc/rgens/text/markov')
4 files changed, 56 insertions, 42 deletions
diff --git a/RGens/src/main/java/bjc/rgens/text/markov/Markov.java b/RGens/src/main/java/bjc/rgens/text/markov/Markov.java index b4564c4..e21d60f 100644 --- a/RGens/src/main/java/bjc/rgens/text/markov/Markov.java +++ b/RGens/src/main/java/bjc/rgens/text/markov/Markov.java @@ -9,7 +9,6 @@ import java.util.*; * Can give a pseudo-random suffix character based on probability. * * @author Daniel Friedman (Fall 2011) - * */ public class Markov { String substring; @@ -21,7 +20,7 @@ public class Markov { * Constructs a Markov object from a given substring. * * @param substr - * the given substring. + * The given substring. */ public Markov(String substr) { this.substring = substr; @@ -38,9 +37,10 @@ public class Markov { * Suffix characters are stored in a TreeMap. * * @param substr - * the specified substring. + * The specified substring. + * * @param suffix - * the specified suffix. + * The specified suffix. */ public Markov(String substr, Character suffix) { this.substring = substr; @@ -62,7 +62,7 @@ public class Markov { * Adds a suffix character to the TreeMap. * * @param c - * the suffix character to be added. + * The suffix character to be added. */ public void add(char c) { add(); @@ -70,7 +70,9 @@ public class Markov { if (map.containsKey(c)) { int frequency = map.get(c); map.put(c, frequency + 1); - } else map.put(c, 1); + } else { + map.put(c, 1); + } } /** @@ -78,8 +80,10 @@ public class Markov { * of times the specified suffix follows the substring in a text. * * @param c - * the specified suffix. - * @return the frequency count. + * The specified suffix. + * + * @return + * The frequency count. */ public int getFrequencyCount(char c) { if (!map.containsKey(c)) { @@ -93,8 +97,11 @@ public class Markov { * Gives a percentage of frequency count / number of total suffixes. * * @param c - * @return the ratio of frequency count of a single character to the - * total number of suffixes + * The character to look for the frequency for. + * + * @return + * The ratio of frequency count of a single character to the total + * number of suffixes. */ public double getCharFrequency(char c) { if (getFrequencyCount(c) == -1) { @@ -108,8 +115,10 @@ public class Markov { * Finds whether or not the given suffix is in the TreeMap. * * @param c - * the given suffix. - * @return True if the suffix exists in the TreeMap, false otherwise. + * The given suffix. + * + * @return + * True if the suffix exists in the TreeMap, false otherwise. */ public boolean containsChar(char c) { if (!map.containsKey(c)) { @@ -122,7 +131,8 @@ public class Markov { /** * Gives the number of times this substring occurs in a text. * - * @return said number of times. + * @return + * Said number of times. */ public int count() { return count; @@ -131,7 +141,8 @@ public class Markov { /** * Gives the TreeMap. * - * @return the TreeMap. + * @return + * The TreeMap. */ public TreeMap<Character, Integer> getMap() { return map; @@ -141,14 +152,14 @@ public class Markov { * Using probability, returns a pseudo-random character to follow the * substring. * - * Character possibilities are added to an ArrayList - * (duplicates allowed), and a random number from 0 to the last index in - * the ArrayList is picked. Since more common suffixes occupy more - * indices in the ArrayList, the probability of getting a more common - * suffix is greater than the probability of getting a less common - * suffix. + * Character possibilities are added to an ArrayList (duplicates + * allowed), and a random number from 0 to the last index in the + * ArrayList is picked. Since more common suffixes occupy more indices + * in the ArrayList, the probability of getting a more common suffix is + * greater than the probability of getting a less common suffix. * - * @return the pseudo-random suffix. + * @return + * The pseudo-random suffix. */ public char random() { Character ret = null; @@ -178,7 +189,8 @@ public class Markov { /** * Gives a String representation of the Markov object. * - * @return said String representation. + * @return + * Said String representation. */ @Override public String toString() { diff --git a/RGens/src/main/java/bjc/rgens/text/markov/StandaloneMarkov.java b/RGens/src/main/java/bjc/rgens/text/markov/StandaloneMarkov.java index 29f8446..cebf2bc 100644 --- a/RGens/src/main/java/bjc/rgens/text/markov/StandaloneMarkov.java +++ b/RGens/src/main/java/bjc/rgens/text/markov/StandaloneMarkov.java @@ -6,25 +6,27 @@ import java.util.Map; * A standalone Markov generator. * * @author bjculkin - * */ public class StandaloneMarkov { + /* The order of the generator. */ private int ord; + /* The generators to use. */ private Map<String, Markov> hash; + /* The initial string. */ private String first; /** * Create a new standalone Markov generator. * * @param order - * The order of this generator. + * The order of this generator. * * @param markovHash - * The generators to use. + * The generators to use. * * @param firstSub - * The string to start out with. + * The string to start out with. */ public StandaloneMarkov(int order, Map<String, Markov> markovHash, String firstSub) { ord = order; @@ -36,9 +38,10 @@ public class StandaloneMarkov { * Generate random text from the markov generator. * * @param charsToGenerate - * The number of characters of text to generate. + * The number of characters of text to generate. * - * @return The randomly generate text. + * @return + * The randomly generate text. */ public String generateTextFromMarkov(int charsToGenerate) { StringBuilder text = new StringBuilder(); 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 c6eea0d..339e8d5 100644 --- a/RGens/src/main/java/bjc/rgens/text/markov/StandaloneTextGenerator.java +++ b/RGens/src/main/java/bjc/rgens/text/markov/StandaloneTextGenerator.java @@ -9,19 +9,19 @@ 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. * * @param order - * The markov order to use. + * The markov order to use. * * @param reader - * The source to seed the generator from. + * The source to seed the generator from. * - * @return The markov generator for the provided text. + * @return + * The markov generator for the provided text. */ public static StandaloneMarkov generateMarkovMap(int order, Reader reader) { Map<String, Markov> hash = new HashMap<>(); 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 0ec40df..f629d49 100644 --- a/RGens/src/main/java/bjc/rgens/text/markov/TextGenerator.java +++ b/RGens/src/main/java/bjc/rgens/text/markov/TextGenerator.java @@ -13,16 +13,15 @@ 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; @@ -71,4 +70,4 @@ public class TextGenerator { System.exit(1); } } -}
\ No newline at end of file +} |
