How to use the wanakana.stripOkurigana function in wanakana

To help you get started, we’ve selected a few wanakana examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Kaniwani / kw-frontend / app / common / components / Ruby / utils.js View on Github external
export function basicFuri(word = '', reading = '') {
  if (!word) {
    return [];
  }
  if (word && isEmpty(reading)) {
    return [['', word]];
  }
  // NOTE: with weird combos like 缶ビール and ハート型
  // it's better to just render entire reading if no furi provided
  if ([...word].some(isKanji) && [...word].some(isKatakana)) {
    return [[reading, word]];
  }
  const mainLength = stripOkurigana(word).length - word.length || reading.length;
  const mainReading = [reading.slice(0, mainLength), stripOkurigana(word)];
  const okurigana = word.slice(mainLength);
  return okurigana ? [mainReading, ['', okurigana]] : [mainReading];
}
github Kaniwani / kw-frontend / app / common / components / Ruby / utils.js View on Github external
export function basicFuri(word = '', reading = '') {
  if (!word) {
    return [];
  }
  if (word && isEmpty(reading)) {
    return [['', word]];
  }
  // NOTE: with weird combos like 缶ビール and ハート型
  // it's better to just render entire reading if no furi provided
  if ([...word].some(isKanji) && [...word].some(isKatakana)) {
    return [[reading, word]];
  }
  const mainLength = stripOkurigana(word).length - word.length || reading.length;
  const mainReading = [reading.slice(0, mainLength), stripOkurigana(word)];
  const okurigana = word.slice(mainLength);
  return okurigana ? [mainReading, ['', okurigana]] : [mainReading];
}
github Kaniwani / kw-frontend / app / common / utils / splitSentenceByMatch.js View on Github external
...inflectVerb(base, verbType)
        .map(({ form }) => form)
        .sort((a, b) => b.length - a.length)
    );
  } else if (adjType) {
    matchers.push(
      ...inflectAdjective(base, adjType)
        .map(({ form }) => form)
        .sort((a, b) => b.length - a.length)
    );
    // basic stem matching fallback if no verbType or adjType provided
  } else if (reading) {
    // 'づけ' => 'づ' via 漬け
    matchers.push(stripOkurigana(base, { matchKanji: word }));
    // 'おかね' => 'かね' via お金
    matchers.push(stripOkurigana(base, { matchKanji: word, leading: true }));
    // 'つけ' => 'ツケ'
    matchers.push(toKatakana(base));
  } else {
    matchers.push(stripOkurigana(base)); // '飛び込む' => '飛び込'
    matchers.push(stripOkurigana(base, { leading: true })); // 'お金' => '金'
  }

  return [...new Set(matchers)];
}
github Kaniwani / kw-frontend / app / common / utils / splitSentenceByMatch.js View on Github external
matchers.push(
      ...inflectAdjective(base, adjType)
        .map(({ form }) => form)
        .sort((a, b) => b.length - a.length)
    );
    // basic stem matching fallback if no verbType or adjType provided
  } else if (reading) {
    // 'づけ' => 'づ' via 漬け
    matchers.push(stripOkurigana(base, { matchKanji: word }));
    // 'おかね' => 'かね' via お金
    matchers.push(stripOkurigana(base, { matchKanji: word, leading: true }));
    // 'つけ' => 'ツケ'
    matchers.push(toKatakana(base));
  } else {
    matchers.push(stripOkurigana(base)); // '飛び込む' => '飛び込'
    matchers.push(stripOkurigana(base, { leading: true })); // 'お金' => '金'
  }

  return [...new Set(matchers)];
}
github Kaniwani / kw-frontend / app / utils / splitSentenceByMatch.js View on Github external
export default function splitSentenceByMatch(sentence = '', word = '', reading = '') {
  const stripKana = (k) => k.replace(tokenize(cleanChars).pop(), '') || k;
  const hasChars = !!word.length;
  const hasKana = !!reading.length;
  let cleanChars;
  let strippedChars;
  let onlyChars;
  let cleanKana;
  let cleanKata;
  let strippedKana;

  if (hasChars) {
    cleanChars = stripTilde(word); // '〜漬け' => '漬け'
    strippedChars = stripOkurigana(cleanChars); // '飛び込む' => '飛び込'
    onlyChars = stripOkurigana(cleanChars, { all: true }); // '売り上げ' => '売上'
  }

  const charRegex = hasChars ? joinPipe([cleanChars, strippedChars, onlyChars]) : '';

  if (hasKana) {
    cleanKana = stripTilde(reading); // '〜つけ' => 'つけ'
    cleanKata = toKatakana(cleanKana); // '〜つけ' => 'ツケ'
    strippedKana = stripKana(cleanKana); // '〜つけ' => 'つ'
  }

  const kanaRegex = hasKana ? `${joinPipe([cleanKana, cleanKata, strippedKana])}` : '';

  // '売り上げ' => /(.*?)(売り上げ|売り上|売上|うりあげ|ウリアゲ|うりあ)(.*)/
  const regex = new RegExp(`(.*?)(${charRegex}${hasChars && hasKana ? '|' : ''}${kanaRegex})(.*)`);
github Kaniwani / kw-frontend / app / utils / splitSentenceByMatch.js View on Github external
export default function splitSentenceByMatch(sentence = '', word = '', reading = '') {
  const stripKana = (k) => k.replace(tokenize(cleanChars).pop(), '') || k;
  const hasChars = !!word.length;
  const hasKana = !!reading.length;
  let cleanChars;
  let strippedChars;
  let onlyChars;
  let cleanKana;
  let cleanKata;
  let strippedKana;

  if (hasChars) {
    cleanChars = stripTilde(word); // '〜漬け' => '漬け'
    strippedChars = stripOkurigana(cleanChars); // '飛び込む' => '飛び込'
    onlyChars = stripOkurigana(cleanChars, { all: true }); // '売り上げ' => '売上'
  }

  const charRegex = hasChars ? joinPipe([cleanChars, strippedChars, onlyChars]) : '';

  if (hasKana) {
    cleanKana = stripTilde(reading); // '〜つけ' => 'つけ'
    cleanKata = toKatakana(cleanKana); // '〜つけ' => 'ツケ'
    strippedKana = stripKana(cleanKana); // '〜つけ' => 'つ'
  }

  const kanaRegex = hasKana ? `${joinPipe([cleanKana, cleanKata, strippedKana])}` : '';

  // '売り上げ' => /(.*?)(売り上げ|売り上|売上|うりあげ|ウリアゲ|うりあ)(.*)/
  const regex = new RegExp(`(.*?)(${charRegex}${hasChars && hasKana ? '|' : ''}${kanaRegex})(.*)`);

  const failSafe = ['', sentence, '', ''];