<commit_before>'use strict'

const Logger = use('Logger');

const pluralize = require('pluralize');

const ExternalWordService = use('App/Services/ExternalWordService');
const WordService = use('App/Services/WordService');
const Word = use('App/Models/Word');

class WordStorageService {

  static get MAX_SYNONYM_DEPTH() { return 1; }


  constructor() {
    this.wordService = new WordService;
    this.externalWordService = new ExternalWordService;
    this.newWords = [];
  }


  async addNewWords(text) {
    let words = this.splitIntoUsableWords(text);
    await words.forEach(async name => {
      await this._addNewWordWithSynonyms(name);
    });
  }


  /**
   * Parses individual words in a block of text. Depluralizes, removes duplicates, and unusable words
   * @param text
   * @returns {string[]}
   */
  splitIntoUsableWords(text) {
    let words;

    // Remove punctuation and split by space or new line
    words = text.replace(/[.,\/#!$%\^&\*;:{}=\-_`~()\d]/g, '').split(/[ \n]/);

    // Depluralize
    words = words.map((word) => {
      return pluralize.singular(word);
    });

    // Remove duplicates
    words = [...new Set(words)];

    // Remove empty entries
    words = words.filter(word => word)

    // Remove words with non-ascii characters
    // TODO: Should we really remove these?
    words = words.filter(word => !word.match(/[^\x00-\x7F]/g));

    // Remove words with punctuation
    // TODO: Should we really remove these?
    words = words.filter(word => !word.match(/['"]/g));

    Logger.info('Parsed words: ' + words);

    return words;
  }


  // Private methods

  async _addNewWordWithSynonyms(name) {<commit_msg>Remove ? from words<commit_after>'use strict'

const Logger = use('Logger');

const pluralize = require('pluralize');

const ExternalWordService = use('App/Services/ExternalWordService');
const WordService = use('App/Services/WordService');
const Word = use('App/Models/Word');

class WordStorageService {

  static get MAX_SYNONYM_DEPTH() { return 1; }


  constructor() {
    this.wordService = new WordService;
    this.externalWordService = new ExternalWordService;
    this.newWords = [];
  }


  async addNewWords(text) {
    let words = this.splitIntoUsableWords(text);
    await words.forEach(async name => {
      await this._addNewWordWithSynonyms(name);
    });
  }


  /**
   * Parses individual words in a block of text. Depluralizes, removes duplicates, and unusable words
   * @param text
   * @returns {string[]}
   */
  splitIntoUsableWords(text) {
    let words;

    // Remove punctuation and split by space or new line
    words = text.replace(/[.,\/#!$%\^&\*\?;:{}=\-_`~()\d]/g, '').split(/[ \n]/);

    // Depluralize
    words = words.map((word) => {
      return pluralize.singular(word);
    });

    // Remove duplicates
    words = [...new Set(words)];

    // Remove empty entries
    words = words.filter(word => word)

    // Remove words with non-ascii characters
    // TODO: Should we really remove these?
    words = words.filter(word => !word.match(/[^\x00-\x7F]/g));

    // Remove words with punctuation
    // TODO: Should we really remove these?
    words = words.filter(word => !word.match(/['"]/g));

    Logger.info('Parsed words: ' + words);

    return words;
  }


  // Private methods

  async _addNewWordWithSynonyms(name) {
{'fraction_non_alphanumeric': 0.15146970605878823, 'fraction_numerical': 0.0023995200959808036, 'mean_word_length': 3.0720390720390722, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, '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': '921324', 'n_tokens_mistral': 1093, 'n_tokens_neox': 1021, 'n_words': 258}