<commit_before>// // GET_USER.then(console.log)
document.querySelector('input[type=submit]').addEventListener('click', () => {
  let content = document.querySelector('textarea[name=content]').value;

  fetch('//web.ics.purdue.edu/~peter438/rfs/api.php/segment', {
    method: 'POST',
    body: JSON.stringify({
      text: content
    })
  })
    .then(response => response.json())
    .then(console.log);
});

// // t = title
// var t = $_POST["title"]
// var $txt = $t.".txt"
// // c = content
// var $c = $_POST["content"]
// // ic = invalid characters
// var $ic = array("\t",".","。"," ","　",",","、","!","！","?","？",";","；",":","：","\"","”","「","」","・","(","（","）",")","'","[","]","\n","\r\n","\r"," "," ")
// // nic = no invalid characters
// $nic = str_replace($ic, "", $c)
// $niclen = mb_strlen($nic)
// // jt = Japanese Text
// $jt = $_POST["jt"]
// // jchrc = Japanese Character Count
// $jchrc = 0
// // Mora Count
// $mc = 0

// file_put_contents($txt,$c)

// echo "Have your readers use your title (<b>".$t."</b>) to retreive this reading passage.<br><br>"

// echo "Total Character Count: <b>".$niclen."</b><br>"
// if ($jt == "jt"){
// 	$c = segment_jtext($c)
// 	$lines = explode("\n",$c)
// 	foreach($lines as $line){
// 		if(strpos($line, "記号") > 0 || $line == "EOS" || $line == ""){
// 			continue
// 		}
// 		else{
// 			$jchrc += 1
// 			// echo $line . "<br>"
// 			$readings = explode("\t",$line)
// 			$mc += mb_strlen($readings[1])
// 		}
// 	}
// 	echo "Total Mora Count: <b>".$mc."</b><br>"
// 	echo "Total Word Count: <b>".$jchrc."</b><br>(\"Words\" here are defined by a morphological analysis of the text using Purdue University's mecab service.)"
// }
// else {
// 	echo "Total Word Count: <b>".str_word_count($c)."</b><br>"
// }

// echo "<br><b>Title: ".$t."</b><br>"
// echo "<b><u>Text</u></b><br>".file_get_contents($txt)<commit_msg>Programmed Total Calculations (words, characters, morae)<commit_after>let getPassageTotals = (segmentsString) => {
  let words = segmentsString.split("\n");

  let totalWords = 0;
  let totalCharacters = 0;
  let totalMorae = 0;
  words.forEach((word) => {
    if (!word.includes("記号") && word !== "EOS" && word !== "" && !word.startsWith("...")) {
      totalWords++;
      let wordParts = word.split("\t");
      totalCharacters += wordParts[0].length;
      totalMorae += wordParts[1].length;

    }
  });

  return {
    words: totalWords,
    characters: totalCharacters,
    morae: totalMorae,
  }
};

document.querySelector("input[type=submit]").addEventListener("click", () => {
  let title = document.querySelector("input[name=title]").value;
  let passage = document.querySelector("textarea[name=content]").value;
  // let cleanPassage = passage.replace(/[\s\.\。\,\、\!\！\?\？\「\」\(\（\）\)\'\[\]\;\；\:\：\"\”\・]/gi, "");
  let isJapanese = document.querySelector("input[type=checkbox]").checked;
  // // GET_USER.then(console.log)
  fetch("//web.ics.purdue.edu/~peter438/rfs/api.php/segment", {
      method: "POST",
      body: JSON.stringify({
        text: passage
      })
    })
    .then(response => response.json())
    .then(json => {
      let totals = getPassageTotals(json.segments);
      console.log(totals);
    });
});
{'fraction_non_alphanumeric': 0.2683915211970075, 'fraction_numerical': 0.004987531172069825, 'mean_word_length': 3.098339719029374, 'pattern_counts': {'":': 1, '<': 29, '<?xml version=': 0, '>': 37, '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': '7564412', 'n_tokens_mistral': 1218, 'n_tokens_neox': 1185, 'n_words': 211}