VariableKeywordMatcher is a C# lib for:
- English initials matching
- English discrete matching
- Chinese PinYin matching
- Japanese Romajin matching
- highlight multiple keywords in search
- pluggable for more spell matching for future. (e.g. Tongyong Pinyin, Korean Hangul ... )
Install from nuget:
(optional)MatcherProvider: ChineseZhCnPinYin
(optional)MatcherProvider: ChineseZhCnPinYinInitials
(optional)MatcherProvider: JapaneseRomaji
- Get the names of available matchers
var availableProviderNames = VariableKeywordMatcher.Builder.GetAvailableProviderNames().ToList();
- Make a list of which providers you want to use.
var enabledProviderNames = new ist<string>();
enabledProviderNames.AddavailableProviderNames[0]);
enabledProviderNames.AddavailableProviderNames[1]);
- Create the matcher(case sensitive = false)
var matcher = VariableKeywordMatcher.Builder.Build(enabledProviderNames);
- Build cache for original strings
var matchCache = matcher.CreateStringCache("Hello World");
- Match with the keywords
var result = matcher.Match(matchCache, new List<string>() { "he", "wo" });
- print result
if (result.IsMatchAllKeywords == true)
{
// print where should be high-light
for (int i = 0; i < result.HitFlags.Count; i++)
{
if (result.HitFlags[i] == true)
{
// highlight
Console.Write($"[{result.OriginalString[i]}]");
}
else
{
// normal
Console.Write($"{result.OriginalString[i]}");
}
Console.WriteLine();
}
}
else
{
Console.WriteLine("Not matched");
for (int i = 0; i < result.KeywordsMatchedFlags.Count; i++)
{
if (result.KeywordsMatchedFlags[i] == false)
{
Console.WriteLine($"{result.Keywords[i]} was not matched");
}
}
}
Demo project PRemoteM
- https://github.com/rvhuang/kmp-algorithm (MIT)
- https://github.com/toolgood/ToolGood.Words.Pinyin (MIT)
- https://github.com/Cutano/Kawazu (MIT)
- https://github.com/komutan/NMeCab (GPL 2.0 / LGPL 2.0)