<commit_before>const { tail, hasTail } = require('./tail')

// A Josa is one of:
//   - 은
//   + 는
//   - 이
//   + 가
//   - 을
//   + 를
//   - 과
//   + 와
//   - 이었
//   + 였
//   - 이어
//   + 여
//   - 이에요
//   + 예요
//   - 아
//   + 야
//   - 이?
//   - 으로
//   + 로

// A JosaPicker is a fuction: string -> Josa
//   - Determines josa for a given string.

// table : object
// State. Manages the josa-pickers.
const table = {}

// put : Josa * Josa * JosaPicker -> void
// Effect. Puts f into table with two given names josa1 and josa2.
const put = (josa1, josa2, f) => {
  table[josa1] = f

  if (josa2)
    table[josa2] = f
}

// get : Josa -> JosaPicker
// Given a josa, returns a josa-picker.
// Effect. Searches table for a josa-picker with name josa.
const get = josa => {
  const f = table[josa]

  if (!f)
    throw new Error(`Cannot handle this josa: ${josa}`)

  return f
}

// makeJosaPicker : Josa * Josa -> JosaPicker
// Given two josa options, produces a josa-picker.
const makeJosaPicker = (josa1, josa2) => w =>
  hasTail(w) ? josa1.replace(/\?$/, '') : josa2

// install : Josa * Josa * JosaPicker? -> void
//   - josa1 is for a word with a tail consonant.
//   - josa2 is for a word with no tail consonant.
//   - g is optional josa-picker for an exceptional case: '으로'
// Effect. Puts a josa-picker created from josa1 and josa2 into table.
const install = (josa1, josa2, g) => {
  const f = g || makeJosaPicker(josa1, josa2)

  put(josa1, josa2, f)
}

install('은', '는')
install('이', '가')
install('을', '를')
install('과', '와')
install('이었', '였')
install('이어', '여')
install('이에요', '예요')
install('아', '야')
install('이?', '')
install('으로', '로', w => tail(w) === 8 ? '로' : makeJosaPicker('으로', '로')(w))

module.exports = { makeJosaPicker
                 , get
                 }<commit_msg>chore<commit_after>const { tail, hasTail } = require('./tail')

// A Josa is one of:
//   - 은
//   + 는
//   - 이
//   + 가
//   - 을
//   + 를
//   - 과
//   + 와
//   - 이었
//   + 였
//   - 이어
//   + 여
//   - 이에요
//   + 예요
//   - 아
//   + 야
//   - 이?
//   - 으로
//   + 로

// A JosaPicker is a fuction: string -> Josa
//   - Determines josa for a given string.

// table : object
// State. Manages the josa-pickers.
const table = {}

// put : Josa * Josa * JosaPicker -> void
// Effect. Puts f into table with two given names josa1 and josa2.
const put = (josa1, josa2, f) => {
  table[josa1] = f

  if (josa2)
    table[josa2] = f
}

// get : Josa -> JosaPicker
// Given a josa, returns a josa-picker.
// Effect. Searches table for a josa-picker with name josa.
const get = josa => {
  const f = table[josa]

  if (!f)
    throw new Error(`Cannot handle this josa: ${josa}`)

  return f
}

// makeJosaPicker : Josa * Josa -> JosaPicker
// Given two josa options, produces a josa-picker.
const makeJosaPicker = (josa1, josa2) => w =>
  hasTail(w) ? josa1.replace(/\?$/, '') : josa2

// install : Josa * Josa * JosaPicker? -> void
//   - josa1 is for a word with a tail consonant.
//   - josa2 is for a word with no tail consonant.
//   - g is optional josa-picker for an exceptional case: '으로'
// Effect. Sets up a josa-picker that chooses between josa1 and josa2.
const install = (josa1, josa2, g) => {
  const f = g || makeJosaPicker(josa1, josa2)

  put(josa1, josa2, f)
}

install('은', '는')
install('이', '가')
install('을', '를')
install('과', '와')
install('이었', '였')
install('이어', '여')
install('이에요', '예요')
install('아', '야')
install('이?', '')
install('으로', '로', w => tail(w) === 8 ? '로' : makeJosaPicker('으로', '로')(w))

module.exports = { makeJosaPicker
                 , get
                 }
{'fraction_non_alphanumeric': 0.18648799553322165, 'fraction_numerical': 0.012283640424343942, 'mean_word_length': 2.201966041108132, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 25, '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': '5157380', 'n_tokens_mistral': 1484, 'n_tokens_neox': 1501, 'n_words': 430}