<commit_before>/**
 * @fileOverview
 * Use a Markov Chain state engine in a trivial way to build names.
 */

var stateEngines = require("state-engines");

/**
 * Assuming that the state engine is working with StringStates, then
 * use it to build a name.
 * 
 * @return {string}
 *   A name.
 */
function generateName(stateEngine) {
  var name = "";
  stateEngine.setCurrentStateToUndefined();
  stateEngine.transition();
  while (!stateEngine.currentState.isUndefined) {
    name += stateEngine.currentState.representation;
    stateEngine.transition();
  }
  return name;
};

/**
 * A utility function for splitting a string into single-character states.
 * 
 * @param {string} string
 *   The string to convert.
 * @return {Array}
 *   An array of StringState objects.
 */
function stringToStringStateArray(str) {
  var array = str.split("");
  for (var index = 0; index < array.length; index++) {
    array[index] = stateEngines.stringState(array[index]);
  }
  return array;
};

// Some names to use as raw material in the state engine.
var names = [
  "Abbadon",
  "Adriel",
  "Ambriel",
  "<NAME>",
  "Arariel",
  "Ahriman",
  "Ariel",
  "Azazel",
  "Azrael",
  "Abymael",
  "Barachiel",
  "Cassiel",
  "Camael",
  "Darda'il",
  "Dumah",
  "Eremiel",
  "Gabriel",
  "Gadreel",
  "Gagiel",
  "Hadraniel",
  "Haniel",
  "Harut",
  "Hesediel",
  "<NAME>",
  "Israfel",
  "Jegudiel",
  "Jehoel",
  "Jequn",
  "Jerahmeel",
  "Jophiel",
  "Kasdeja",
  "<NAME>",
  "Kushiel",
  "Kosmiel",
  "Leliel",
  "Lucifer",
  "Maalik",
  "Malik",
  "Marut",
  "Metatron",
  "Michael",
  "Munkar",
  "Mu'aqqibat",
  "Muriel",
  "Nakir",
  "Nuriel",
  "Ophanim",
  "Orifiel",
  "Pahaliah",
  "Penemue",
  "Puriel",
  "Qaphsiel",
  "Raguel",
  "Raphael",
  "Raqib",
  "Raziel",
  "Remiel",
  "Ridwan",
  "Sachiel",
  "Samael",
  "Sandalphon",
  "Sariel",
  "Selaphiel",
  "Seraphiel",
  "Simiel",
  "Shamsiel",
  "Tzaphqiel",
  "Temeluchus",
  "Uriel",
  "Uzziel",
  "Yehudiel",
  "Yerachmiel",
  "Zabaniyah",
  "Zachariel",
  "Zadkiel",
  "Zephon",
  "Zophiel"
];

// Create the state engine and feed it the names.
var markovChainStateEngine = stateEngines.markovChainStateEngine();
for (var index = 0; index < names.length; index++) {
  markovChainStateEngine.addPath(stringToStringStateArray(names[index]));
}

// Generate new names.
for (var index = 0; index < 10; index++) {
  console.log(generateName(markovChainStateEngine));
}<commit_msg>Some minor tidying and improvement.<commit_after>/**
 * @fileOverview
 * Use a Markov Chain state engine in a trivial way to build names.
 */

var stateEngines = require("state-engines");

/**
 * Assuming that the state engine is working with suitable StringStates, 
 * then use it to build a name.
 * 
 * @param {StateEngine} engine
 *   A state engine instance.
 * @return {string}
 *   A name.
 */
function generateName(engine) {
  var name = "";
  engine.setCurrentStateToUndefined();
  engine.transition();
  while (!engine.currentState.isUndefined) {
    name += engine.currentState.representation;
    engine.transition();
  }
  return name;
};

/**
 * A utility function for splitting a string into single-character states.
 * 
 * @param {string} string
 *   The string to convert.
 * @return {Array}
 *   An array of StringState objects.
 */
function stringToStringStateArray(str) {
  return str.split("").map(function(element) {
    return stateEngines.stringState(element);
  });
};

// Some names to use as raw material in the state engine.
var names = [
  "abbadon",
  "adriel",
  "ambriel",
  "<NAME>",
  "arariel",
  "ahriman",
  "ariel",
  "azazel",
  "azrael",
  "abymael",
  "barachiel",
  "cassiel",
  "camael",
  "dumah",
  "eremiel",
  "gabriel",
  "gadreel",
  "gagiel",
  "hadraniel",
  "haniel",
  "harut",
  "hesediel",
  "israfel",
  "jegudiel",
  "jehoel",
  "jequn",
  "jerahmeel",
  "jophiel",
  "kasdeja",
  "<NAME>",
  "kushiel",
  "kosmiel",
  "leliel",
  "lucifer",
  "maalik",
  "malik",
  "marut",
  "metatron",
  "michael",
  "munkar",
  "muriel",
  "nakir",
  "nuriel",
  "ophanim",
  "orifiel",
  "pahaliah",
  "penemue",
  "puriel",
  "qaphsiel",
  "raguel",
  "raphael",
  "raqib",
  "raziel",
  "remiel",
  "ridwan",
  "sachiel",
  "samael",
  "sandalphon",
  "sariel",
  "selaphiel",
  "seraphiel",
  "simiel",
  "shamsiel",
  "tzaphqiel",
  "temeluchus",
  "uriel",
  "uzziel",
  "yehudiel",
  "yerachmiel",
  "zabaniyah",
  "zachariel",
  "zadkiel",
  "zephon",
  "zophiel"
];

// Create the state engine and feed it the names.
var markovChainStateEngine = stateEngines.markovChainStateEngine();
names.forEach(function(element) {
  markovChainStateEngine.addPath(stringToStringStateArray(element));
});

// Generate new names.
for (var index = 0; index < 10; index++) {
  console.log(generateName(markovChainStateEngine));
}
{'fraction_non_alphanumeric': 0.16788169131430952, 'fraction_numerical': 0.0016663195167673402, 'mean_word_length': 3.703232125367287, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5127078', 'n_tokens_mistral': 1906, 'n_tokens_neox': 1867, 'n_words': 417}