<commit_before>/* jshint strict: true, quotmark: false */
/* global $: false, JSZip: false */

var EUCopyright = EUCopyright || {};

(function(){
  "use strict";

EUCopyright.parseCSV = function( strData, strDelimiter ){
  /*
  This code taken from:
  http://stackoverflow.com/a/1293163/114462
  under CC-By-SA 3.0
  */
  // This will parse a delimited string into an array of
  // arrays. The default delimiter is the comma, but this
  // can be overriden in the second argument.
  // Check to see if the delimiter is defined. If not,
  // then default to comma.
  strDelimiter = (strDelimiter || ",");
  var strMatchedValue, strMatchedDelimiter;

  // Create a regular expression to parse the CSV values.
  var objPattern = new RegExp(
    (
      // Delimiters.
      "(\\" + strDelimiter + "|\\r?\\n|\\r|^)" +

      // Quoted fields.
      "(?:\"([^\"]*(?:\"\"[^\"]*)*)\"|" +

      // Standard fields.
      "([^\"\\" + strDelimiter + "\\r\\n]*))"
    ),
    "gi"
    );


  // Create an array to hold our data. Give the array
  // a default empty first row.
  var arrData = [[]];

  // Create an array to hold our individual pattern
  // matching groups.
  var arrMatches = null;


  // Keep looping over the regular expression matches
  // until we can no longer find a match.
  arrMatches = objPattern.exec(strData);
  while (arrMatches){

    // Get the delimiter that was found.
    strMatchedDelimiter = arrMatches[ 1 ];

    // Check to see if the given delimiter has a length
    // (is not the start of string) and if it matches
    // field delimiter. If id does not, then we know
    // that this delimiter is a row delimiter.
    if (
      strMatchedDelimiter.length &&
      (strMatchedDelimiter != strDelimiter)
      ){

      // Since we have reached a new row of data,
      // add an empty row to our data array.
      arrData.push( [] );

    }


    // Now that we have our delimiter out of the way,
    // let's check to see which kind of value we
    // captured (quoted or unquoted).
    if (arrMatches[ 2 ]){

      // We found a quoted value. When we capture
      // this value, unescape any double quotes.
      strMatchedValue = arrMatches[ 2 ].replace(/""/g, '"');

    } else {
      // We found a non-quoted value.
      strMatchedValue = arrMatches[ 3 ];

    }
    // Now that we have our value string, let's add
    // it to the data array.
    arrData[arrData.length - 1].push(strMatchedValue);
    arrMatches = objPattern.exec(strData);
  }

  // Return the parsed data.
  return arrData ;
};

EUCopyright.compile = function(){
  var escapeXML = function(str){
    return str.replace(/&/g, '&amp;')
               .replace(/</g, '&lt;')
               .replace(/>/g, '&gt;')
               .replace(/"/g, '&quot;')
               .replace(/'/g, '&apos;');
  };

  var replaceParagraph = function(doc, key, value){
    return doc.replace(
      new RegExp('(<text:p text:style-name="' + key + '">)[^<]*(</text:p>)'),
      '$1' + escapeXML(value) + '$2'
    );
  };

  var insertTextPropertiesStyle = function(doc, key, style){
    var re = new RegExp('(<style:style style:name="' + key + '"[^>]*>(?:<style:paragraph-properties[^/]*/>)?<style:text-properties)([^/]*/></style:style>)');
    if (!re.test(doc)) {
      var re2 = new RegExp('(<style:style style:name="' + key + '"[^>]*>(?:<style:paragraph-properties[^/]*/>)?)(</style:style>)');
      if (!re2.test(doc)) {
        throw new Error('could not underline at ' + key);
      }
      return doc.replace(
        re2,
        '$1<style:text-properties ' + style + '/>$2'
      );
    }
    return doc.replace(
      re,
      '$1 ' + style + '$2'
    );
  };

  var underline = function(doc, key){
    return insertTextPropertiesStyle(doc, key, 'style:text-underline-style="solid" style:text-underline-width="auto" style:text-underline-color="font-color"');
  };

  var bold = function(doc, key){
    return insertTextPropertiesStyle(doc, key, 'fo:font-weight="bold" style:font-weight-asian="bold" style:font-weight-complex="bold"');
  };

  var applyOdf = function(text, odf, paste) {
    if (odf.action == 'mark') {
      text = underline(text, odf.key);
      text = bold(text, odf.key);
    } else if (odf.action == 'remove') {
      text = replaceParagraph(text, odf.key, '');
    } else if (odf.action == 'paste' && paste) {
      text = replaceParagraph(text, odf.key, paste);
    }
    return text;
  };

  var applyOdfs = function(text, odfs, paste) {
    if (!odfs) {
      return text;
    }
    for (var i = 0; i < odfs.length; i += 1) {
      text = applyOdf(text, odfs[i], paste);
    }
    return text;
  };

  var processQuestions = function(text) {
    var question, j, paste, radio;

    for (var i = 0; i < EUCopyright.questions.length; i += 1) {
      question = EUCopyright.questions[i];

      if (question.type === 'multiple_choice' && question.options) {
        for (j = 0; j < question.options.length; j += 1) {
          radio = $('#q-' + question.num + '-' + j);
          if (radio.prop('checked')) {
            paste = '';
            if (question.options[j].fulltext) {
              paste = $('#q-' + question.num + '-' + j + '-text').val();
            }
            text = applyOdfs(text, question.options[j].odf, paste);
          }
        }
      } else if (question.type == 'open_question') {
        paste = $('#q-' + question.num + '-text').val();
        text = applyOdfs(text, question.odf, paste);
      }
    }
    return text;
  };

  var constructContents = function(zip){
    var d = $.Deferred();
    $.get(EUCopyright.baseurl + '/data/content.xml').done(function(parsed, mes, xhr){
      var text = xhr.responseText;

      var name = $('#name').val();
      if (name) {
        text = replaceParagraph(text, 'P288', name);
        text = replaceParagraph(text, 'P289', '');
      } else {
        text = underline(text, 'P316');
      }
<commit_msg>Check no opinion if nothing else given<commit_after>/* jshint strict: true, quotmark: false */
/* global $: false, JSZip: false */

var EUCopyright = EUCopyright || {};
EUCopyright.settings = EUCopyright.settings || {};
EUCopyright.settings.defaultToNoOpinion = EUCopyright.settings.defaultToNoOpinion === undefined ? true : EUCopyright.settings.defaultToNoOpinion;

(function(){
  "use strict";

EUCopyright.parseCSV = function( strData, strDelimiter ){
  /*
  This code taken from:
  http://stackoverflow.com/a/1293163/114462
  under CC-By-SA 3.0
  */
  // This will parse a delimited string into an array of
  // arrays. The default delimiter is the comma, but this
  // can be overriden in the second argument.
  // Check to see if the delimiter is defined. If not,
  // then default to comma.
  strDelimiter = (strDelimiter || ",");
  var strMatchedValue, strMatchedDelimiter;

  // Create a regular expression to parse the CSV values.
  var objPattern = new RegExp(
    (
      // Delimiters.
      "(\\" + strDelimiter + "|\\r?\\n|\\r|^)" +

      // Quoted fields.
      "(?:\"([^\"]*(?:\"\"[^\"]*)*)\"|" +

      // Standard fields.
      "([^\"\\" + strDelimiter + "\\r\\n]*))"
    ),
    "gi"
    );


  // Create an array to hold our data. Give the array
  // a default empty first row.
  var arrData = [[]];

  // Create an array to hold our individual pattern
  // matching groups.
  var arrMatches = null;


  // Keep looping over the regular expression matches
  // until we can no longer find a match.
  arrMatches = objPattern.exec(strData);
  while (arrMatches){

    // Get the delimiter that was found.
    strMatchedDelimiter = arrMatches[ 1 ];

    // Check to see if the given delimiter has a length
    // (is not the start of string) and if it matches
    // field delimiter. If id does not, then we know
    // that this delimiter is a row delimiter.
    if (
      strMatchedDelimiter.length &&
      (strMatchedDelimiter != strDelimiter)
      ){

      // Since we have reached a new row of data,
      // add an empty row to our data array.
      arrData.push( [] );

    }


    // Now that we have our delimiter out of the way,
    // let's check to see which kind of value we
    // captured (quoted or unquoted).
    if (arrMatches[ 2 ]){

      // We found a quoted value. When we capture
      // this value, unescape any double quotes.
      strMatchedValue = arrMatches[ 2 ].replace(/""/g, '"');

    } else {
      // We found a non-quoted value.
      strMatchedValue = arrMatches[ 3 ];

    }
    // Now that we have our value string, let's add
    // it to the data array.
    arrData[arrData.length - 1].push(strMatchedValue);
    arrMatches = objPattern.exec(strData);
  }

  // Return the parsed data.
  return arrData ;
};

EUCopyright.compile = function(){
  var escapeXML = function(str){
    return str.replace(/&/g, '&amp;')
               .replace(/</g, '&lt;')
               .replace(/>/g, '&gt;')
               .replace(/"/g, '&quot;')
               .replace(/'/g, '&apos;');
  };

  var replaceParagraph = function(doc, key, value){
    return doc.replace(
      new RegExp('(<text:p text:style-name="' + key + '">)[^<]*(</text:p>)'),
      '$1' + escapeXML(value) + '$2'
    );
  };

  var insertTextPropertiesStyle = function(doc, key, style){
    var re = new RegExp('(<style:style style:name="' + key + '"[^>]*>(?:<style:paragraph-properties[^/]*/>)?<style:text-properties)([^/]*/></style:style>)');
    if (!re.test(doc)) {
      var re2 = new RegExp('(<style:style style:name="' + key + '"[^>]*>(?:<style:paragraph-properties[^/]*/>)?)(</style:style>)');
      if (!re2.test(doc)) {
        throw new Error('could not underline at ' + key);
      }
      return doc.replace(
        re2,
        '$1<style:text-properties ' + style + '/>$2'
      );
    }
    return doc.replace(
      re,
      '$1 ' + style + '$2'
    );
  };

  var underline = function(doc, key){
    return insertTextPropertiesStyle(doc, key, 'style:text-underline-style="solid" style:text-underline-width="auto" style:text-underline-color="font-color"');
  };

  var bold = function(doc, key){
    return insertTextPropertiesStyle(doc, key, 'fo:font-weight="bold" style:font-weight-asian="bold" style:font-weight-complex="bold"');
  };

  var applyOdf = function(text, odf, paste) {
    if (odf.action == 'mark') {
      text = underline(text, odf.key);
      text = bold(text, odf.key);
    } else if (odf.action == 'remove') {
      text = replaceParagraph(text, odf.key, '');
    } else if (odf.action == 'paste' && paste) {
      text = replaceParagraph(text, odf.key, paste);
    }
    return text;
  };

  var applyOdfs = function(text, odfs, paste) {
    if (!odfs) {
      return text;
    }
    for (var i = 0; i < odfs.length; i += 1) {
      text = applyOdf(text, odfs[i], paste);
    }
    return text;
  };

  var processQuestions = function(text) {
    var question, j, paste, radio, checked;

    for (var i = 0; i < EUCopyright.questions.length; i += 1) {
      question = EUCopyright.questions[i];

      if (question.type === 'multiple_choice' && question.options) {
        checked = false;
        for (j = 0; j < question.options.length; j += 1) {
          radio = $('#q-' + question.num + '-' + j);
          if (radio.prop('checked')) {
            paste = '';
            checked = true;
            if (question.options[j].fulltext) {
              paste = $('#q-' + question.num + '-' + j + '-text').val();
            }
            text = applyOdfs(text, question.options[j].odf, paste);
          }
        }
        if (!checked && EUCopyright.settings.defaultToNoOpinion) {
          // Check no opinion, if not filled in
          text = applyOdfs(text, question.options[2].odf, '');
        }
      } else if (question.type == 'open_question') {
        paste = $('#q-' + question.num + '-text').val();
        text = applyOdfs(text, question.odf, paste);
      }
    }
    return text;
  };

  var constructContents = function(zip){
    var d = $.Deferred();
    $.get(EUCopyright.baseurl + '/data/content.xml').done(function(parsed, mes, xhr){
      var text = xhr.responseText;

      var name = $('#name').val();
      if (name) {
        text = replaceParagraph(text, 'P288', name);
        text = replaceParagraph(text, 'P289', '');
      } else {
        text = underline(text, 'P316');
      }

{'fraction_non_alphanumeric': 0.1673728813559322, 'fraction_numerical': 0.007252281616688397, 'mean_word_length': 2.3969000830334903, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '6465078', 'n_tokens_mistral': 4105, 'n_tokens_neox': 3951, 'n_words': 1085}