Professional Documents
Culture Documents
Markov
Markov
java
//Author: Alexandra Comaduran
//Abstract: Markov.java is a Java program that implements
// a Markov chain for text generation. It reads from text
// files to create a model of word sequences and then
// generates new, stylistically similar sentences based on
// this model.
//Date: 11/14/23
package org.example;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Random;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.io.IOException;
public Markov() {
words.put(BEGINS_SENTENCE, new ArrayList<>());
}
if (endsWithPunctuation(word)) {
prevWord = BEGINS_SENTENCE;
} else {
prevWord = word;
}
}
public static boolean endsWithPunctuation(String word) {
return word.length() > 0 &&
PUNCTUATION_MARKS.contains(word.substring(word.length() - 1));
}
@Override
public String toString() {
return words.toString();
}
}