public void BuildTest() { { var matcher = Builder.Build(new[] { DiscreteMatchProvider.GetName() }, true); Assert.IsTrue(matcher.IsCaseSensitive); Assert.IsTrue(matcher.ProviderTypes.Count == 1); Assert.IsTrue(matcher.ProviderTypes[0] == DiscreteMatchProvider.GetName()); } { var matcher = Builder.Build(new[] { DiscreteMatchProvider.GetName(), ChineseZhCnPinYinMatchProvider.GetName() }, false); Assert.IsTrue(matcher.IsCaseSensitive == false); Assert.IsTrue(matcher.ProviderTypes.Count == 2); Assert.IsTrue(matcher.ProviderTypes.Any(x => x == DiscreteMatchProvider.GetName())); Assert.IsTrue(matcher.ProviderTypes.Any(x => x == ChineseZhCnPinYinMatchProvider.GetName())); } #if !NET45 { var matcher = Builder.Build(new[] { JapaneseRomajiProvider.GetName(), ChineseZhCnPinYinInitialsMatchProvider.GetName() }, true); Assert.IsTrue(matcher.IsCaseSensitive == true); Assert.IsTrue(matcher.ProviderTypes.Count == 2); Assert.IsTrue(matcher.ProviderTypes.Any(x => x == JapaneseRomajiProvider.GetName())); Assert.IsTrue(matcher.ProviderTypes.Any(x => x == ChineseZhCnPinYinInitialsMatchProvider.GetName())); } #endif }
private static void LoadProviders() { if (AvailableProviders.ContainsKey(DirectMatchProvider.GetName()) == false) { AvailableProviders.Add(DirectMatchProvider.GetName(), new DirectMatchProvider(false)); } if (AvailableProviders.ContainsKey(InitialsMatchProvider.GetName()) == false) { AvailableProviders.Add(InitialsMatchProvider.GetName(), new InitialsMatchProvider(false)); } if (AvailableProviders.ContainsKey(DiscreteMatchProvider.GetName()) == false) { AvailableProviders.Add(DiscreteMatchProvider.GetName(), new DiscreteMatchProvider(false)); } if (AvailableProviders.ContainsKey(ChineseZhCnPinYinInitialsMatchProvider.GetName()) == false) { AvailableProviders.Add(ChineseZhCnPinYinInitialsMatchProvider.GetName(), new ChineseZhCnPinYinInitialsMatchProvider(false)); } if (AvailableProviders.ContainsKey(ChineseZhCnPinYinMatchProvider.GetName()) == false) { AvailableProviders.Add(ChineseZhCnPinYinMatchProvider.GetName(), new ChineseZhCnPinYinMatchProvider(false)); } try { var files = Directory.GetFiles(Directory.GetParent(typeof(Builder).Assembly.Location).FullName, "*.dll"); foreach (var dllPath in files) { var assembly = Assembly.LoadFile(dllPath); var types = assembly.GetTypes(); var providers = types.Where(item => item.IsSubclassOf(typeof(MatchProviderBase)) && !item.IsAbstract) .Select(type => CreateProviderInstance(type, false)); foreach (var provider in providers.OrderBy(x => x.GetProviderDescription())) { var t = provider.GetProviderName(); if (AvailableProviders.ContainsKey(t) == false) { AvailableProviders.Add(t, provider); } } } } catch (Exception) { } }
public void GetProviderDescriptionTest() { { var dsp1 = Builder.GetProviderDescription(DirectMatchProvider.GetName()); var dsp2 = Builder.GetProviderDescriptionEn(DirectMatchProvider.GetName()); Assert.IsTrue(!string.IsNullOrEmpty(dsp1)); Assert.IsTrue(!string.IsNullOrEmpty(dsp2)); } { var dsp1 = Builder.GetProviderDescription(InitialsMatchProvider.GetName()); var dsp2 = Builder.GetProviderDescriptionEn(InitialsMatchProvider.GetName()); Assert.IsTrue(!string.IsNullOrEmpty(dsp1)); Assert.IsTrue(!string.IsNullOrEmpty(dsp2)); } { var dsp1 = Builder.GetProviderDescription(DiscreteMatchProvider.GetName()); var dsp2 = Builder.GetProviderDescriptionEn(DiscreteMatchProvider.GetName()); Assert.IsTrue(!string.IsNullOrEmpty(dsp1)); Assert.IsTrue(!string.IsNullOrEmpty(dsp2)); } { var dsp1 = Builder.GetProviderDescription(ChineseZhCnPinYinMatchProvider.GetName()); var dsp2 = Builder.GetProviderDescriptionEn(ChineseZhCnPinYinMatchProvider.GetName()); Assert.IsTrue(!string.IsNullOrEmpty(dsp1)); Assert.IsTrue(!string.IsNullOrEmpty(dsp2)); } { var dsp1 = Builder.GetProviderDescription(ChineseZhCnPinYinInitialsMatchProvider.GetName()); var dsp2 = Builder.GetProviderDescriptionEn(ChineseZhCnPinYinInitialsMatchProvider.GetName()); Assert.IsTrue(!string.IsNullOrEmpty(dsp1)); Assert.IsTrue(!string.IsNullOrEmpty(dsp2)); } #if !NET45 { var dsp1 = Builder.GetProviderDescription(JapaneseRomajiProvider.GetName()); var dsp2 = Builder.GetProviderDescriptionEn(JapaneseRomajiProvider.GetName()); Assert.IsTrue(!string.IsNullOrEmpty(dsp1)); Assert.IsTrue(!string.IsNullOrEmpty(dsp2)); } #endif }
public void MatchTest_String_SingleKeyword() { { var matcher = Builder.Build(new[] { DirectMatchProvider.GetName() }, false); string str = "HelloWorld 你好世界!"; Assert.IsTrue(matcher.Match(str, "llow").IsMatchAllKeywords == true); Assert.IsTrue(matcher.Match(str, "llOW").IsMatchAllKeywords == true); Assert.IsTrue(matcher.Match(str, "世界").IsMatchAllKeywords == true); Assert.IsTrue(matcher.Match(str, "!").IsMatchAllKeywords == true); Assert.IsTrue(matcher.Match(str, "!").IsMatchAllKeywords == false); Assert.IsTrue(matcher.Match(str, "He l").IsMatchAllKeywords == false); Assert.IsTrue(matcher.Match(str, " ").IsMatchAllKeywords == false); Assert.IsTrue(matcher.Match(str, "啊").IsMatchAllKeywords == false); Assert.IsTrue(matcher.Match(str, "X").IsMatchAllKeywords == false); } { var matcher = Builder.Build(new[] { DirectMatchProvider.GetName(), ChineseZhCnPinYinInitialsMatchProvider.GetName() }, false); string str = "HelloWorld 你好世界!"; Assert.IsTrue(matcher.Match(str, "llow").IsMatchAllKeywords == true); Assert.IsTrue(matcher.Match(str, "llOW").IsMatchAllKeywords == true); Assert.IsTrue(matcher.Match(str, "世界").IsMatchAllKeywords == true); Assert.IsTrue(matcher.Match(str, "!").IsMatchAllKeywords == true); Assert.IsTrue(matcher.Match(str, "NH").IsMatchAllKeywords == true); Assert.IsTrue(matcher.Match(str, " NH").IsMatchAllKeywords == true); Assert.IsTrue(matcher.Match(str, "nh").IsMatchAllKeywords == true); Assert.IsTrue(matcher.Match(str, " nH").IsMatchAllKeywords == true); Assert.IsTrue(matcher.Match(str, "ld nh").IsMatchAllKeywords == true); Assert.IsTrue(matcher.Match(str, "ld NH").IsMatchAllKeywords == true); Assert.IsTrue(matcher.Match(str, "!").IsMatchAllKeywords == false); Assert.IsTrue(matcher.Match(str, "He l").IsMatchAllKeywords == false); Assert.IsTrue(matcher.Match(str, " ").IsMatchAllKeywords == false); Assert.IsTrue(matcher.Match(str, "啊").IsMatchAllKeywords == false); Assert.IsTrue(matcher.Match(str, "X").IsMatchAllKeywords == false); } { var matcher = Builder.Build(new[] { DirectMatchProvider.GetName(), ChineseZhCnPinYinInitialsMatchProvider.GetName() }, true); string str = "HelloWorld 你好世界!"; Assert.IsTrue(matcher.Match(str, "llow").IsMatchAllKeywords == false); Assert.IsTrue(matcher.Match(str, "lloW").IsMatchAllKeywords == true); Assert.IsTrue(matcher.Match(str, "世界").IsMatchAllKeywords == true); Assert.IsTrue(matcher.Match(str, "!").IsMatchAllKeywords == true); Assert.IsTrue(matcher.Match(str, "NH").IsMatchAllKeywords == true); Assert.IsTrue(matcher.Match(str, " NH").IsMatchAllKeywords == true); Assert.IsTrue(matcher.Match(str, "nh").IsMatchAllKeywords == true); Assert.IsTrue(matcher.Match(str, " nH").IsMatchAllKeywords == true); Assert.IsTrue(matcher.Match(str, "ld nh").IsMatchAllKeywords == true); Assert.IsTrue(matcher.Match(str, "ld NH").IsMatchAllKeywords == true); Assert.IsTrue(matcher.Match(str, "lD nh").IsMatchAllKeywords == false); Assert.IsTrue(matcher.Match(str, "lD NH").IsMatchAllKeywords == false); Assert.IsTrue(matcher.Match(str, "!").IsMatchAllKeywords == false); Assert.IsTrue(matcher.Match(str, "He l").IsMatchAllKeywords == false); Assert.IsTrue(matcher.Match(str, " ").IsMatchAllKeywords == false); Assert.IsTrue(matcher.Match(str, "啊").IsMatchAllKeywords == false); Assert.IsTrue(matcher.Match(str, "X").IsMatchAllKeywords == false); } { var matcher = Builder.Build(new[] { DirectMatchProvider.GetName(), ChineseZhCnPinYinInitialsMatchProvider.GetName(), ChineseZhCnPinYinMatchProvider.GetName() }, false); string str = "HelloWorld 你好世界!"; Assert.IsTrue(matcher.Match(str, "llow").IsMatchAllKeywords == true); Assert.IsTrue(matcher.Match(str, "llOW").IsMatchAllKeywords == true); Assert.IsTrue(matcher.Match(str, "世界").IsMatchAllKeywords == true); Assert.IsTrue(matcher.Match(str, "SHIJIE").IsMatchAllKeywords == true); Assert.IsTrue(matcher.Match(str, "!").IsMatchAllKeywords == true); Assert.IsTrue(matcher.Match(str, "NH").IsMatchAllKeywords == true); Assert.IsTrue(matcher.Match(str, " NH").IsMatchAllKeywords == true); Assert.IsTrue(matcher.Match(str, "nh").IsMatchAllKeywords == true); Assert.IsTrue(matcher.Match(str, " nH").IsMatchAllKeywords == true); Assert.IsTrue(matcher.Match(str, "ld nh").IsMatchAllKeywords == true); Assert.IsTrue(matcher.Match(str, "ld NH").IsMatchAllKeywords == true); Assert.IsTrue(matcher.Match(str, "ld NIHA").IsMatchAllKeywords == true); Assert.IsTrue(matcher.Match(str, "ld NIHAo").IsMatchAllKeywords == true); Assert.IsTrue(matcher.Match(str, "!").IsMatchAllKeywords == false); Assert.IsTrue(matcher.Match(str, "He l").IsMatchAllKeywords == false); Assert.IsTrue(matcher.Match(str, " ").IsMatchAllKeywords == false); Assert.IsTrue(matcher.Match(str, "啊").IsMatchAllKeywords == false); Assert.IsTrue(matcher.Match(str, "X").IsMatchAllKeywords == false); } }
public void MatchTest_Cache_MultiKeywords() { { var matcher = Builder.Build(new[] { DirectMatchProvider.GetName(), ChineseZhCnPinYinInitialsMatchProvider.GetName() }, false); string str = "HelloWorld 你好世界!"; var cache = matcher.CreateStringCache(str); Assert.IsTrue(matcher.Match(cache, new[] { "llow", "NH" }).IsMatchAllKeywords == true); Assert.IsTrue(matcher.Match(cache, new[] { "llOW", "NH" }).IsMatchAllKeywords == true); Assert.IsTrue(matcher.Match(cache, new[] { "llOW", "世界" }).IsMatchAllKeywords == true); Assert.IsTrue(matcher.Match(cache, new[] { "lloW", "世界", "!" }).IsMatchAllKeywords == true); Assert.IsTrue(matcher.Match(cache, new[] { "nh", "!" }).IsMatchAllKeywords == true); Assert.IsTrue(matcher.Match(cache, new[] { "lloW", "世界", "!" }).IsMatchAllKeywords == false); Assert.IsTrue(matcher.Match(cache, new[] { "lloW", "X" }).IsMatchAllKeywords == false); Assert.IsTrue(matcher.Match(cache, new[] { "lloW", " " }).IsMatchAllKeywords == false); } { var matcher = Builder.Build(new[] { DirectMatchProvider.GetName(), ChineseZhCnPinYinInitialsMatchProvider.GetName() }, true); string str = "HelloWorld 你好世界!"; var cache = matcher.CreateStringCache(str); Assert.IsTrue(matcher.Match(cache, new[] { "llow", "NH" }).IsMatchAllKeywords == false); Assert.IsTrue(matcher.Match(cache, new[] { "llOW", "NH" }).IsMatchAllKeywords == false); Assert.IsTrue(matcher.Match(cache, new[] { "llOW", "世界" }).IsMatchAllKeywords == false); Assert.IsTrue(matcher.Match(cache, new[] { "lloW", "世界" }).IsMatchAllKeywords == true); Assert.IsTrue(matcher.Match(cache, new[] { "lloW", "世界", "!" }).IsMatchAllKeywords == true); Assert.IsTrue(matcher.Match(cache, new[] { "nh", "!" }).IsMatchAllKeywords == true); Assert.IsTrue(matcher.Match(cache, new[] { "lloW", "世界", "!" }).IsMatchAllKeywords == false); Assert.IsTrue(matcher.Match(cache, new[] { "lloW", "X" }).IsMatchAllKeywords == false); Assert.IsTrue(matcher.Match(cache, new[] { "lloW", " " }).IsMatchAllKeywords == false); } { var matcher = Builder.Build(new[] { DirectMatchProvider.GetName(), ChineseZhCnPinYinMatchProvider.GetName() }, false); string str = "HelloWorld 你好世界!"; var cache = matcher.CreateStringCache(str); Assert.IsTrue(matcher.Match(cache, new[] { "llow", "NH" }).IsMatchAllKeywords == false); Assert.IsTrue(matcher.Match(cache, new[] { "llOW", "NH" }).IsMatchAllKeywords == false); Assert.IsTrue(matcher.Match(cache, new[] { "llOW", "世界" }).IsMatchAllKeywords == true); Assert.IsTrue(matcher.Match(cache, new[] { "lloW", "世界", "!" }).IsMatchAllKeywords == true); Assert.IsTrue(matcher.Match(cache, new[] { "lloW", "SHIJIE", "!" }).IsMatchAllKeywords == true); Assert.IsTrue(matcher.Match(cache, new[] { "NI", "hao", "!" }).IsMatchAllKeywords == true); Assert.IsTrue(matcher.Match(cache, new[] { "NI", "hao", "w" }).IsMatchAllKeywords == true); Assert.IsTrue(matcher.Match(cache, new[] { "lloW", "世界", "!" }).IsMatchAllKeywords == false); Assert.IsTrue(matcher.Match(cache, new[] { "lloW", "X" }).IsMatchAllKeywords == false); Assert.IsTrue(matcher.Match(cache, new[] { "lloW", " " }).IsMatchAllKeywords == false); Assert.IsTrue(matcher.Match(cache, new[] { "a", " " }).IsMatchAllKeywords == false); Assert.IsTrue(matcher.Match(cache, new[] { "a" }).IsMatchAllKeywords == false); Assert.IsTrue(matcher.Match(cache, new[] { " " }).IsMatchAllKeywords == true); } }
public void MatchTest_MatchCache_SingleKeyword() { { var matcher = Builder.Build(new[] { DirectMatchProvider.GetName(), ChineseZhCnPinYinInitialsMatchProvider.GetName() }, false); string str = "HelloWorld 你好世界!"; var cache = matcher.CreateStringCache(str); Assert.IsTrue(matcher.Match(cache, "llow").IsMatchAllKeywords == true); Assert.IsTrue(matcher.Match(cache, "llOW").IsMatchAllKeywords == true); Assert.IsTrue(matcher.Match(cache, "世界").IsMatchAllKeywords == true); Assert.IsTrue(matcher.Match(cache, "!").IsMatchAllKeywords == true); Assert.IsTrue(matcher.Match(cache, "NH").IsMatchAllKeywords == true); Assert.IsTrue(matcher.Match(cache, " NH").IsMatchAllKeywords == true); Assert.IsTrue(matcher.Match(cache, "nh").IsMatchAllKeywords == true); Assert.IsTrue(matcher.Match(cache, " nH").IsMatchAllKeywords == true); Assert.IsTrue(matcher.Match(cache, "ld nh").IsMatchAllKeywords == true); Assert.IsTrue(matcher.Match(cache, "ld NH").IsMatchAllKeywords == true); Assert.IsTrue(matcher.Match(cache, "!").IsMatchAllKeywords == false); Assert.IsTrue(matcher.Match(cache, "He l").IsMatchAllKeywords == false); Assert.IsTrue(matcher.Match(cache, " ").IsMatchAllKeywords == false); Assert.IsTrue(matcher.Match(cache, "啊").IsMatchAllKeywords == false); Assert.IsTrue(matcher.Match(cache, "a").IsMatchAllKeywords == false); Assert.IsTrue(matcher.Match(cache, "X").IsMatchAllKeywords == false); } { var matcher = Builder.Build(new[] { DirectMatchProvider.GetName(), ChineseZhCnPinYinInitialsMatchProvider.GetName() }, true); string str = "HelloWorld 你好世界!"; var cache = matcher.CreateStringCache(str); Assert.IsTrue(matcher.Match(cache, "llow").IsMatchAllKeywords == false); Assert.IsTrue(matcher.Match(cache, "lloW").IsMatchAllKeywords == true); Assert.IsTrue(matcher.Match(cache, "世界").IsMatchAllKeywords == true); Assert.IsTrue(matcher.Match(cache, "!").IsMatchAllKeywords == true); Assert.IsTrue(matcher.Match(cache, "NH").IsMatchAllKeywords == true); Assert.IsTrue(matcher.Match(cache, " NH").IsMatchAllKeywords == true); Assert.IsTrue(matcher.Match(cache, "nh").IsMatchAllKeywords == true); Assert.IsTrue(matcher.Match(cache, " nH").IsMatchAllKeywords == true); Assert.IsTrue(matcher.Match(cache, "ld nh").IsMatchAllKeywords == true); Assert.IsTrue(matcher.Match(cache, "ld NH").IsMatchAllKeywords == true); Assert.IsTrue(matcher.Match(cache, "lD nh").IsMatchAllKeywords == false); Assert.IsTrue(matcher.Match(cache, "lD NH").IsMatchAllKeywords == false); Assert.IsTrue(matcher.Match(cache, "!").IsMatchAllKeywords == false); Assert.IsTrue(matcher.Match(cache, "He l").IsMatchAllKeywords == false); Assert.IsTrue(matcher.Match(cache, " ").IsMatchAllKeywords == false); Assert.IsTrue(matcher.Match(cache, "啊").IsMatchAllKeywords == false); Assert.IsTrue(matcher.Match(cache, "X").IsMatchAllKeywords == false); } }