From a539c86d015c3eb9819cf38d1ccb04edb1461fe2 Mon Sep 17 00:00:00 2001 From: Yorke Lee Date: Thu, 18 Apr 2013 16:12:34 -0700 Subject: Allow name matching for contacts with numbers in their name For SmartDialTrie, also include numbers as valid characters when calculating indexes when generating the byte array. For SmartDialNameMatcher, include '0'-'9' as valid latin characters, and handle them appropriately after remapping accented characters. Also fixed a subtle matching bug that would manifest itself when matching against multiple tokens with similar initials - E.g. "Dr.Dredd" Bug 8659001 Change-Id: If461d2760a723ef7fd03dda0c1a1515cd7b44cf6 --- .../dialer/dialpad/SmartDialNameMatcherTest.java | 24 +++++++++- .../android/dialer/dialpad/SmartDialTrieTest.java | 54 ++++++++++++++++++++++ 2 files changed, 77 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/src/com/android/dialer/dialpad/SmartDialNameMatcherTest.java b/tests/src/com/android/dialer/dialpad/SmartDialNameMatcherTest.java index 3c481d0c7..83b856059 100644 --- a/tests/src/com/android/dialer/dialpad/SmartDialNameMatcherTest.java +++ b/tests/src/com/android/dialer/dialpad/SmartDialNameMatcherTest.java @@ -89,10 +89,21 @@ public class SmartDialNameMatcherTest extends TestCase { checkMatches("William-John Smith", "95646", true, 0, 1, 8, 12); // jsmi matches William (J)ohn-(Smi)th checkMatches("William John-Smith", "5764", true, 8, 9, 13, 16); + // wsmi matches (W)illiam John (Smi)th + checkMatches("William John-Smith", "9764", true, 0, 1, 13, 16); // make sure multiple spaces don't mess things up checkMatches("William John---Smith", "5764", true, 15, 16, 22, 25); - + // match tokens that are located directly after a non-space separator (studio) checkMatches("Berkeley Hair-Studio", "788346", true, 14, 20); + // match tokens with same initials + checkMatches("H.Harold", "427653", true, 2, 8); + // various matching combinations of tokens with similar initials + checkMatches("Yo-Yoghurt Land", "964487", true, 3, 9); + checkMatches("Yo-Yoghurt Land", "96448785263", true, 3, 15); + checkMatches("Yo-Yoghurt Land", "95263", true, 3, 4, 11, 15); + checkMatches("Yo-Yoghurt Land", "995263", true, 0, 1, 3, 4, 11, 15); + + checkMatches("ab zz ef", "23", true, 0, 1, 6, 7); } public void testMatches_repeatedSeparators() { @@ -117,6 +128,17 @@ public class SmartDialNameMatcherTest extends TestCase { checkMatches("ÄÖÜäöü", "268268", true, 0, 6); } + public void testMatches_NumberInName() { + // Number used as display name + checkMatches("+1-123-456-6789", "1234566789", true, 3, 15); + // Mix of numbers and letters + checkMatches("3rd Grade Teacher", "373", true, 0, 3); + checkMatches("1800 Win A Prize", "1800", true, 0, 4); + checkMatches("1800 Win A Prize", "1800946277493", true, 0, 16); + checkMatches("1800 Win A Prize", "977493", true, 5, 6, 11, 16); + } + + // TODO: Great if it was treated as "s" or "ss. Figure out if possible without prefix trie? @Suppress public void testMatches_germanSharpS() { diff --git a/tests/src/com/android/dialer/dialpad/SmartDialTrieTest.java b/tests/src/com/android/dialer/dialpad/SmartDialTrieTest.java index 7f55263e1..cd87b6613 100644 --- a/tests/src/com/android/dialer/dialpad/SmartDialTrieTest.java +++ b/tests/src/com/android/dialer/dialpad/SmartDialTrieTest.java @@ -106,6 +106,14 @@ public class SmartDialTrieTest extends TestCase{ assertTrue(checkContains(trie, martinjuniorharry, "6542")); // 542 corresponds to jha = "Martin (J)r (Ha)rry" assertTrue(checkContains(trie, martinjuniorharry, "542")); + // 642 corresponds to mha = "(M)artin Jr (Ha)rry" + assertTrue(checkContains(trie, martinjuniorharry, "642")); + // 6542779 (M)artin (J)r (Harry) + assertTrue(checkContains(trie, martinjuniorharry, "6542779")); + // 65742779 (M)artin (Jr) (Harry) + assertTrue(checkContains(trie, martinjuniorharry, "65742779")); + // 542779 Martin (J)r (Harry) + assertTrue(checkContains(trie, martinjuniorharry, "542779")); // 547 doesn't match assertFalse(checkContains(trie, martinjuniorharry, "547")); // 655 doesn't match @@ -114,6 +122,39 @@ public class SmartDialTrieTest extends TestCase{ assertFalse(checkContains(trie, martinjuniorharry, "653")); // 6543 doesn't match assertFalse(checkContains(trie, martinjuniorharry, "6543")); + // 7(2^3 -1) entries for the name, and 1 for the number + assertEquals(8, trie.numEntries()); + } + + public void testPutForInitialMatchesCombinations() { + final SmartDialTrie trie = new SmartDialTrie(); + final ContactNumber alphabet = new ContactNumber(0, "abc def ghi jkl mno pqrs tuv wxyz", + "1", "1", 2); + trie.put(alphabet); + // 255 (2^8 - 1) combinations for the name, and 1 for the number + assertEquals(256, trie.numEntries()); + + // Test every single combination of the leading initials of each name token by generating + // strings consisting of all combinations of the digits 2-9. + final StringBuilder sb = new StringBuilder(); + + // Create an array of bit positions 0b10000000, 0b01000000, 0b00100000, ... + final int[] pos = new int[8]; + for (int i = 2; i <= 9; i++) { + pos[i - 2] = 1 << (9 - i); + } + for (int i = 1; i < 256; i++) { + sb.setLength(0); + // If the bit at nth position is set to true, then add the nth initial to the target + // string + for (int j = 2; j <= 9; j++) { + if ((i & pos[j - 2]) > 0) { + sb.append(j); + } + } + assertTrue(checkContains(trie, alphabet, sb.toString())); + } + } public void testSeparators() { @@ -141,6 +182,19 @@ public class SmartDialTrieTest extends TestCase{ assertTrue(checkContains(trie, bronte, "276683")); } + public void testNumbersInName() { + final SmartDialTrie trie = new SmartDialTrie(); + final ContactNumber contact = new ContactNumber(0, "12345678", "0", "0", 1); + final ContactNumber teacher = new ContactNumber(1, "1st Grade Teacher", "0", "1", 2); + trie.put(contact); + trie.put(teacher); + assertTrue(checkContains(trie, contact, "12345678")); + // (1st Grade) Teacher + assertTrue(checkContains(trie, teacher, "17847233")); + // (1)st (G)rade (Tea)cher + assertTrue(checkContains(trie, teacher, "14832")); + } + public void testPutForNumbers() { final SmartDialTrie trie = new SmartDialTrie(); final ContactNumber contactno1 = new ContactNumber(0, "James", "510-527-2357", "0", 1); -- cgit v1.2.3