mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-16 19:57:57 +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>
|
<PropertyGroup>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<PackageReference Include="ToolGood.Words.Pinyin" />
|
|
||||||
</ItemGroup>
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -2,25 +2,9 @@
|
|||||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||||
// See the LICENSE file in the project root for more information.
|
// See the LICENSE file in the project root for more information.
|
||||||
|
|
||||||
using System.Globalization;
|
|
||||||
|
|
||||||
namespace Common.Search.FuzzSearch;
|
namespace Common.Search.FuzzSearch;
|
||||||
|
|
||||||
public class MatchOption
|
public class MatchOption
|
||||||
{
|
{
|
||||||
public bool IgnoreCase { get; set; } = true;
|
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 System.Globalization;
|
||||||
|
|
||||||
using ToolGood.Words.Pinyin;
|
|
||||||
|
|
||||||
namespace Common.Search.FuzzSearch;
|
namespace Common.Search.FuzzSearch;
|
||||||
|
|
||||||
public class StringMatcher
|
public class StringMatcher
|
||||||
@@ -40,32 +38,12 @@ public class StringMatcher
|
|||||||
|
|
||||||
var bestResult = new MatchResult(false, score);
|
var bestResult = new MatchResult(false, score);
|
||||||
|
|
||||||
List<string> queryList = [query];
|
for (int startIndex = 0; startIndex < stringToCompare.Length; startIndex++)
|
||||||
List<string> stringToCompareList = [stringToCompare];
|
|
||||||
|
|
||||||
if (opt.ChinesePinYinSupport)
|
|
||||||
{
|
{
|
||||||
// Remove IME composition split characters.
|
MatchResult result = FuzzyMatch(query, stringToCompare, opt, startIndex);
|
||||||
var input = query.Replace("'", string.Empty);
|
if (result.Success && (!bestResult.Success || result.Score > bestResult.Score))
|
||||||
queryList.Add(WordsHelper.GetPinyin(input));
|
|
||||||
if (WordsHelper.HasChinese(stringToCompare))
|
|
||||||
{
|
{
|
||||||
stringToCompareList.Add(WordsHelper.GetPinyin(stringToCompare));
|
bestResult = result;
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user