forked from TencentBlueKing/bk-ci
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request TencentBlueKing#5225 from hingbong/issue-#5100
feat: 流水线页面 按名称A-Z 支持中文按拼音排序 TencentBlueKing#5100 替换汉字拼音转换工具 提高多音字正确率
- Loading branch information
Showing
7 changed files
with
74 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
...d/ci/core/common/common-util/src/main/kotlin/com/tencent/devops/common/util/PinyinUtil.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package com.tencent.devops.common.util | ||
|
||
import com.github.houbb.heaven.util.lang.CharUtil | ||
import com.github.houbb.heaven.util.lang.StringUtil | ||
import com.github.houbb.segment.support.segment.result.impl.SegmentResultHandlers | ||
import com.taptap.pinyin.ResourceLoad | ||
import com.taptap.pinyin.Word | ||
import com.taptap.pinyin.analyzer.WordAnalyzer | ||
import com.taptap.pinyin.utils.Utils | ||
import java.util.HashMap | ||
import java.util.StringJoiner | ||
|
||
object PinyinUtil { | ||
|
||
private val words: HashMap<String, Word> = ResourceLoad.loadCedict() | ||
private val wordAnalyzer = WordAnalyzer.newInstance() | ||
|
||
/** | ||
* com.taptap.pinyin.PinyinPlus#to(java.lang.String, boolean) 修改此方法逻辑, 改为词组之间不带分隔符 | ||
* 返回拼音字符串, 不存在拼音的返回原字符 | ||
*/ | ||
@Suppress("NestedBlockDepth") | ||
fun toPinyin(text: String): String { | ||
if (StringUtil.isBlank(text)) return text | ||
var word = words[text] | ||
return if (word != null) { | ||
Utils.trim(word.pinyinNoTone) | ||
} else { | ||
val joiner = StringJoiner("") | ||
val segmentResult = wordAnalyzer.segment(text, SegmentResultHandlers.word()) | ||
for (segmentStr in segmentResult) { | ||
word = words[segmentStr] | ||
if (word != null) { | ||
joiner.add(Utils.trim(word.pinyinNoTone)) | ||
} else { | ||
val characterList = StringUtil.toCharacterList(segmentStr) | ||
for (character in characterList) { | ||
if (CharUtil.isChinese(character)) { | ||
word = words[character.toString()] | ||
joiner.add(word!!.pinyinNoTone) | ||
} else { | ||
joiner.add(character.toString()) | ||
} | ||
} | ||
} | ||
} | ||
joiner.toString() | ||
} | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
.../core/common/common-util/src/test/kotlin/com/tencent/devops/common/util/PinyinUtilTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.tencent.devops.common.util | ||
|
||
import org.junit.Test | ||
|
||
class PinyinUtilTest { | ||
|
||
@Test | ||
fun test() { | ||
assert("chongzhiliushuixianzhuangtai TEST.テスト-jinめ_ceshi" == | ||
PinyinUtil.toPinyin("重置流水线状态 TEST.テスト-進め_測試")) | ||
assert("zhongyao zhongda" == PinyinUtil.toPinyin("重要 重大")) | ||
assert(PinyinUtil.toPinyin("奇偶") == "jiou") | ||
assert(PinyinUtil.toPinyin("奇怪奇异") == "qiguaiqiyi") | ||
assert(PinyinUtil.toPinyin("屏风 屏障 屏蔽") == "pingfeng pingzhang pingbi") | ||
assert(PinyinUtil.toPinyin("屏息 屏气") == "bingxi bingqi") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters