/ src / locale / ja / resources / Tokenizer.php
<?php
/**
 * SeekQuarry/Yioop --
 * Open Source Pure PHP Search Engine, Crawler, and Indexer
 *
 * Copyright (C) 2009 - 2026  Chris Pollett chris@pollett.org
 *
 * LICENSE:
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 *
 * @author Chris Pollett chris@pollett.org
 * @license https://www.gnu.org/licenses/ GPL3
 * @link https://www.seekquarry.com/
 * @copyright 2009 - 2026
 * @filesource
 */
namespace seekquarry\yioop\locale\ja\resources;

/**
 * Japanese specific tokenization code. Typically, tokenizer.php
 * either contains a stemmer for the language in question or
 * it specifies how many characters in a char gram
 *
 * @author Chris Pollett
 */
class Tokenizer
{
    /**
     * A list of frequently occurring terms for this locale which should
     * be excluded from certain kinds of queries. This is also used
     * for language detection
     * @var array
     */
    public static $stop_words = ['ใ‚ˆใ†ใซ', '็งใฏ', 'ๅฝผใฎ', 'ใใฎ', 'ๅฝผ',
    'ใŸ', 'ใŸใ‚ใซ', 'ไธŠใฎ', 'ใ‚ขใƒผใƒซ', 'ใจใจใ‚‚ใซ', 'ๅฝผใ‚‰', 'ใ‚ใ‚‹', 'ใ‚ขใƒƒใƒˆ',
    'ไธ€ใค', 'ๆŒใฃใฆใ„ใ‚‹', 'ใ“ใฎ', 'ใ‹ใ‚‰', 'ใƒใ‚ค', 'ใƒ›ใƒƒใƒˆ', '่จ€่‘‰', 'ใ—ใ‹ใ—', 'ไฝ•',
    'ใ„ใใคใ‹ใฎ', 'ใงใ™', 'ใใ‚Œ', 'ใ‚ใชใŸ', 'ใพใŸใฏ', 'ๆŒใฃใฆใ„ใŸ', 'ใ‚คใƒณใ‚ฏใƒซใƒผใƒ‰', 'ใฎ',
    'ใธ', 'ใใ—ใฆ', 'ใฏ', 'ใง', 'ๆˆ‘ใ€…', '็ผถ', 'ใ‚ขใ‚ฆใƒˆ', 'ใใฎไป–', 'ใ ใฃใŸ',
    'ใ“ใ‚Œ', 'ใ‚„ใ‚‹', 'ใใ‚Œใ‚‰ใฎ', 'ๆ™‚้–“', 'ใ‚‚ใ—', 'ๆ„ๅฟ—', 'ๆ–นๆณ•', 'ๅ‰่จ˜', 'ใฎ',
    'ใใ‚Œใžใ‚Œ', '่จ€ใ†', 'ใ—', 'ใ‚ปใƒƒใƒˆ', 'ๅ€‹', 'ๆฌฒใ—ใ„', '็ฉบๆฐ—', 'ใ‚ˆใ',
    'ใพใŸ', '้Šใถ', 'ๅฐใ•ใ„', '็ต‚ใ‚ใ‚Š', '็ฝฎใ', 'ใƒ›ใƒผใƒ ', '่ชญใ‚€', 'ๆ‰‹',
    'ใƒใƒผใƒˆ', 'ๅคงใใ„', 'ใ‚นใƒšใƒซ', 'ๅŠ ใˆใ‚‹', 'ใ•ใ‚‰ใซ', 'ๅœŸๅœฐ', 'ใ“ใ“ใซ',
    'ใ—ใชใ‘ใ‚Œใฐใชใ‚‰ใชใ„', 'ๅคงใใ„', '้ซ˜ใ„', 'ใใฎใ‚ˆใ†ใช', '็ถšใ', '่กŒ็‚บ',
    'ใชใœ', '้ ผใ‚€', 'ไบบใ€…', 'ๅค‰ๆ›ด', '่กŒใฃใฆใใพใ—ใŸ', 'ๅ…‰', '็จฎ้กž', 'ใ‚ชใƒ•',
    'ๅฟ…่ฆ', 'ๅฎถ', '็ตต', '่ฉฆใ™', '็งใŸใก', 'ๅ†ใณ', 'ๅ‹•็‰ฉ', 'ใƒใ‚คใƒณใƒˆ', 'ๆฏ',
    'ไธ–็•Œ', '่ฟ‘ใ', 'ใƒ“ใƒซใƒ‰', '่‡ชๅทฑ', 'ๅœฐ็ƒ', '็ˆถ'];
    /**
     * How many characters in a char gram for this locale
     * @var int
     */
    public static $char_gram_len = 3;
    /**
     * Removes the stop words from the page (used for Word Cloud generation
     * and language detection)
     *
     * @param mixed $data either a string or an array of string to remove
     *      stop words from
     * @return mixed $data with no stop words
     */
    public static function stopwordsRemover($data)
    {
        static $pattern = "";
        if (empty($pattern)) {
            $pattern = '/(' . implode('|', self::$stop_words) . ')/u';
        }
        $data = preg_replace($pattern, '', $data);
        return $data;
    }
}
X