Skip to content

Commit

Permalink
PinyinMatch 添加 FindWithSpace方法
Browse files Browse the repository at this point in the history
  • Loading branch information
toolgood committed Apr 18, 2020
1 parent 8f23b55 commit 4ac062a
Show file tree
Hide file tree
Showing 13 changed files with 613 additions and 569 deletions.
90 changes: 85 additions & 5 deletions csharp/ToolGood.Words.Test/PinyinMatchTest/PinyinMatchTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace ToolGood.Words.Test
public class PinyinMatchTest
{
[Test]
public void test3()
public void test2()
{
string s = "北京|天津|河北|辽宁|吉林|黑龙江|山东|江苏|上海|浙江|安徽|福建|江西|广东|广西|海南|河南|湖南|湖北|山西|内蒙古|宁夏|青海|陕西|甘肃|新疆|四川|贵州|云南|重庆|西藏|香港|澳门|台湾";

Expand Down Expand Up @@ -49,9 +49,51 @@ public void test3()
Assert.AreEqual(0, all2[0]);
Assert.AreEqual(1, all.Count);

all = match.FindWithSpace("S 东");
Assert.AreEqual("山东", all[0]);

all = match.FindWithSpace("h 江");
Assert.AreEqual("黑龙江", all[0]);


all = match.FindWithSpace("京 北");
Assert.AreEqual(0, all.Count);

all = match.FindWithSpace("黑龙 龙江");
Assert.AreEqual(0, all.Count);

all = match.FindWithSpace("黑龙 江");
Assert.AreEqual("黑龙江", all[0]);

all = match.FindWithSpace("黑 龙 江");
Assert.AreEqual("黑龙江", all[0]);



}
[Test]
public void test3()
{
string s = "黑龙江|黑龙江123";

PinyinMatch match = new PinyinMatch();
match.SetKeywords(s.Split('|').ToList());

var all = match.FindWithSpace("黑龙 龙江");
Assert.AreEqual(0, all.Count);

all = match.FindWithSpace("江 黑");
Assert.AreEqual(0, all.Count);

all = match.FindWithSpace("黑龙 江");
Assert.AreEqual("黑龙江", all[0]);

all = match.FindWithSpace("黑 龙 江");
Assert.AreEqual("黑龙江", all[0]);

var all2 = match.FindIndexWithSpace("黑龙 江");
Assert.AreEqual(0, all2[0]);

all = match.Find("m");

}
[Test]
public void test4()
Expand Down Expand Up @@ -86,8 +128,46 @@ public void test4()
all = match.Find("S东");
Assert.AreEqual("山东", all[0]);



all = match.FindWithSpace("S 东");
Assert.AreEqual("山东", all[0]);

all = match.FindWithSpace("h 江");
Assert.AreEqual("黑龙江", all[0]);


all = match.FindWithSpace("京 北");
Assert.AreEqual(0, all.Count);

all = match.FindWithSpace("黑龙 龙江");
Assert.AreEqual(0, all.Count);

all = match.FindWithSpace("黑龙 江");
Assert.AreEqual("黑龙江", all[0]);

all = match.FindWithSpace("黑 龙 江");
Assert.AreEqual("黑龙江", all[0]);

}
[Test]
public void test5()
{
string s = "黑龙江|黑龙江123";

var match = new PinyinMatch<string>(s.Split('|'));
match.SetKeywordsFunc(q => q);

var all = match.FindWithSpace("黑龙 龙江");
Assert.AreEqual(0, all.Count);

all = match.FindWithSpace("江 黑");
Assert.AreEqual(0, all.Count);

all = match.FindWithSpace("黑龙 江");
Assert.AreEqual("黑龙江", all[0]);

all = match.FindWithSpace("黑 龙 江");
Assert.AreEqual("黑龙江", all[0]);

}

}
Expand Down
Loading

0 comments on commit 4ac062a

Please sign in to comment.