<commit_before>'use babel'

import childProcess from 'child_process'
import readline from 'readline'

const separatorPattern = /(?:\s|[,:])+/

export default class Hunspell {
  constructor () {
    this.process = childProcess.spawn('/usr/bin/hunspell', ['-a', '-t'])

    this.process.on('exit', (code) => {
      console.log(`Child exited with code ${code}`)
    })

    this.process.stdin.write('!\n') // Put into terse mode

    this.readline = readline.createInterface({
      input: this.process.stdout
    })
  }

  check (text) {
    if (text) {
      let foo = this.process
      let bar = this.readline
      return new Promise(function (resolve, reject) {
        let words = []
        function onLine (line) {
          if (line) {
            const parts = line.split(separatorPattern)
            console.log(parts)
            switch (parts[0]) {
              case '&':
                words.push({
                  original: parts[1],
                  offset: parseInt(parts[3], 10),
                  misses: parts.slice(4)
                })
                break
              case '#':
                words.push({
                  original: parts[1],
                  offset: parseInt(parts[2], 10),
                  misses: []
                })
            }
          } else {
            bar.removeListener('line', onLine)
            resolve(words)
          }
        }
        bar.on('line', onLine)
        foo.stdin.write(text + '\n')
      })
    } else {
      return []
    }
  }

}<commit_msg>Added command pattern<commit_after>'use babel'

import childProcess from 'child_process'
import readline from 'readline'

const separatorPattern = /(?:\s|[,:])+/
const commandPattern = /^[-*&@+~#!%`]/

export default class Hunspell {
  constructor () {
    this.process = childProcess.spawn('/usr/bin/hunspell', ['-a', '-t'])

    this.process.on('exit', (code) => {
      console.log(`Child exited with code ${code}`)
    })

    this.process.stdin.write('!\n') // Put into terse mode

    this.readline = readline.createInterface({
      input: this.process.stdout
    })
  }

  check (text) {
    if (text) {
      let foo = this.process
      let bar = this.readline
      return new Promise(function (resolve, reject) {
        let words = []
        function onLine (line) {
          if (line) {
            const parts = line.split(separatorPattern)
            console.log(parts)
            switch (parts[0]) {
              case '&':
                words.push({
                  original: parts[1],
                  offset: parseInt(parts[3], 10),
                  misses: parts.slice(4)
                })
                break
              case '#':
                words.push({
                  original: parts[1],
                  offset: parseInt(parts[2], 10),
                  misses: []
                })
            }
          } else {
            bar.removeListener('line', onLine)
            resolve(words)
          }
        }
        bar.on('line', onLine)
        foo.stdin.write(text.replace(commandPattern, '^$&') + '\n')
      })
    } else {
      return []
    }
  }

}
{'fraction_non_alphanumeric': 0.1409033078880407, 'fraction_numerical': 0.006361323155216285, 'mean_word_length': 1.5079744816586922, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '3167095', 'n_tokens_mistral': 938, 'n_tokens_neox': 895, 'n_words': 192}