<commit_before>import Strings from '../../src/coaching-chatbot/strings.json';
import CommunicationMethods
 from '../../src/coaching-chatbot/communication-methods.json';

const Formatter = {
  format,
  formatFromTemplate,
  createProfile,
  getCommunicationMethods,
  matchCommunicationMethod,
};

export default Formatter;

function formatFromTemplate(template, context) {
  let s = Strings[template];

  if (Array.isArray(s)) {
    s = s[Math.floor(Math.random() * s.length)];
  }

  return format(s, context);
}

function format(template, context) {
  let s = template;

  if (context.name) {
    s = s.replace('{name}', context.name);
  }

  if (context.job) {
    s = s.replace('{job}', context.job);
  }

  if (context.age) {
    s = s.replace('{age}', context.age);
  }

  if (context.place) {
    s = s.replace('{place}', context.place);
  }

  s = s.replace('{profile}', createProfile(context));

  return s;
}

function createProfile(context) {
  return [context.name, context.job,
      context.age, context.place,
    ]
    .filter((val) => val)
    .join(', ');
}

function matchCommunicationMethod(input) {
  for(let i = 0; i < CommunicationMethods.length; i++) {
    if(CommunicationMethods[i].name === input) {
      return CommunicationMethods[i].infoRequestText;
    }
  }
}
<commit_msg>Make format dynamic instead of hardcoded<commit_after>import Strings from '../../src/coaching-chatbot/strings.json';
import CommunicationMethods
 from '../../src/coaching-chatbot/communication-methods.json';

const Formatter = {
  format,
  formatFromTemplate,
  createProfile,
  getCommunicationMethods,
  matchCommunicationMethod,
};

export default Formatter;

function formatFromTemplate(template, context) {
  let s = Strings[template];

  if (Array.isArray(s)) {
    s = s[Math.floor(Math.random() * s.length)];
  }

  return format(s, context);
}

function format(template, context) {
  let s = template;

  return s.replace(
    /{(\w+)}/g,
    (match, name) => {
      if (name === 'profile') {
        return createProfile(context);
      }
      return context[name] != undefined ? context[name] : name;
    }
  );
}

function createProfile(context) {
  return [context.name, context.job,
      context.age, context.place,
    ]
    .filter((val) => val)
    .join(', ');
}

function matchCommunicationMethod(input) {
  for(let i = 0; i < CommunicationMethods.length; i++) {
    if(CommunicationMethods[i].name === input) {
      return CommunicationMethods[i].infoRequestText;
    }
  }
}

{'fraction_non_alphanumeric': 0.1556264964086193, 'fraction_numerical': 0.0007980845969672786, 'mean_word_length': 3.517117117117117, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 6, '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': '5101237', 'n_tokens_mistral': 831, 'n_tokens_neox': 808, 'n_words': 165}