mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-16 11:48:06 +01:00
Remove Chinese Pinyin matching functionality
Removed the `ToolGood.Words.Pinyin` package and all related logic from the `Common.Search` project. This includes the removal of the `ChinesePinYinSupport` property in the `MatchOption` class and the associated `IsSimplifiedChinese` method. Simplified the `StringMatcher` class by eliminating Pinyin-based transformations and focusing solely on direct fuzzy matching of input strings. These changes reduce dependencies and streamline the codebase.
This commit is contained in:
@@ -5,8 +5,4 @@
|
||||
<PropertyGroup>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="ToolGood.Words.Pinyin" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
||||
@@ -2,25 +2,9 @@
|
||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System.Globalization;
|
||||
|
||||
namespace Common.Search.FuzzSearch;
|
||||
|
||||
public class MatchOption
|
||||
{
|
||||
public bool IgnoreCase { get; set; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether to support Chinese PinYin.
|
||||
/// Defaults to true when the system UI culture is Simplified Chinese.
|
||||
/// </summary>
|
||||
public bool ChinesePinYinSupport { get; set; } = IsSimplifiedChinese();
|
||||
|
||||
private static bool IsSimplifiedChinese()
|
||||
{
|
||||
var culture = CultureInfo.CurrentUICulture;
|
||||
// Detect Simplified Chinese: zh-CN, zh-Hans, zh-Hans-*
|
||||
return culture.Name.StartsWith("zh-CN", StringComparison.OrdinalIgnoreCase)
|
||||
|| culture.Name.StartsWith("zh-Hans", StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,8 +4,6 @@
|
||||
|
||||
using System.Globalization;
|
||||
|
||||
using ToolGood.Words.Pinyin;
|
||||
|
||||
namespace Common.Search.FuzzSearch;
|
||||
|
||||
public class StringMatcher
|
||||
@@ -40,32 +38,12 @@ public class StringMatcher
|
||||
|
||||
var bestResult = new MatchResult(false, score);
|
||||
|
||||
List<string> queryList = [query];
|
||||
List<string> stringToCompareList = [stringToCompare];
|
||||
|
||||
if (opt.ChinesePinYinSupport)
|
||||
for (int startIndex = 0; startIndex < stringToCompare.Length; startIndex++)
|
||||
{
|
||||
// Remove IME composition split characters.
|
||||
var input = query.Replace("'", string.Empty);
|
||||
queryList.Add(WordsHelper.GetPinyin(input));
|
||||
if (WordsHelper.HasChinese(stringToCompare))
|
||||
MatchResult result = FuzzyMatch(query, stringToCompare, opt, startIndex);
|
||||
if (result.Success && (!bestResult.Success || result.Score > bestResult.Score))
|
||||
{
|
||||
stringToCompareList.Add(WordsHelper.GetPinyin(stringToCompare));
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var currentQuery in queryList)
|
||||
{
|
||||
foreach (var currentStringToCompare in stringToCompareList)
|
||||
{
|
||||
for (var startIndex = 0; startIndex < currentStringToCompare.Length; startIndex++)
|
||||
{
|
||||
MatchResult result = FuzzyMatch(currentQuery, currentStringToCompare, opt, startIndex);
|
||||
if (result.Success && (!bestResult.Success || result.Score > bestResult.Score))
|
||||
{
|
||||
bestResult = result;
|
||||
}
|
||||
}
|
||||
bestResult = result;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user