All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.taotao.boot.pinyin.support.data.PinyinData Maven / Gradle / Ivy

There is a newer version: 2025.01
Show newest version
/*
 * Copyright (c) 2020-2030, Shuigedeng ([email protected] & https://blog.taotaocloud.top/).
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.taotao.boot.pinyin.support.data;

import com.taotao.boot.common.utils.lang.StringUtils;
import com.taotao.boot.pinyin.spi.IPinyinData;

import java.util.Arrays;
import java.util.List;

/** 声母韵母 */
public class PinyinData implements IPinyinData {

    /** 零声母列表 a ai an ang ao e ê ei en eng er o ou */
    private static final List ZERO_SHENG_MU_LIST =
            Arrays.asList("a", "ai", "an", "ang", "ao", "e", "ê", "ei", "en", "eng", "er", "o", "ou");

    /** 双字母的声母 zh ch sh */
    private static final List DOUBLE_SHENG_MU_LIST = Arrays.asList("zh", "ch", "sh");

    @Override
    public String shengMu(String pinyinNormal) {
        if (isZeroShengMu(pinyinNormal)) {
            return StringUtils.EMPTY;
        }

        final String prefixDouble = pinyinNormal.substring(0, 2);
        if (DOUBLE_SHENG_MU_LIST.contains(prefixDouble)) {
            return prefixDouble;
        }

        // 默认返回第一个音节
        return pinyinNormal.substring(0, 1);
    }

    @Override
    public String yunMu(String pinyinNormal) {
        String shengMu = shengMu(pinyinNormal);
        return pinyinNormal.substring(shengMu.length());
    }

    @Override
    public boolean isZeroShengMu(String pinyinNormal) {
        return ZERO_SHENG_MU_LIST.contains(pinyinNormal);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy