| 1 | // License: GPL. For details, see LICENSE file.
|
|---|
| 2 | package org.openstreetmap.josm.data;
|
|---|
| 3 |
|
|---|
| 4 | import static org.junit.Assert.assertEquals;
|
|---|
| 5 |
|
|---|
| 6 | import org.junit.BeforeClass;
|
|---|
| 7 | import org.junit.Test;
|
|---|
| 8 | import org.openstreetmap.josm.data.validation.tests.SimilarNamedWays;
|
|---|
| 9 |
|
|---|
| 10 | public class SimilarNamesTest {
|
|---|
| 11 |
|
|---|
| 12 | private static SimilarNamedWays similarity_;
|
|---|
| 13 |
|
|---|
| 14 | /**
|
|---|
| 15 | * Setup SimilarityRules.
|
|---|
| 16 | */
|
|---|
| 17 | @BeforeClass
|
|---|
| 18 | public static void init() {
|
|---|
| 19 | similarity_ = new SimilarNamedWays();
|
|---|
| 20 | similarity_.addRegExprRule("\\d+", "0");
|
|---|
| 21 | similarity_.addRegExprRule("\\d+(st|nd|rd|th)", "0st");
|
|---|
| 22 | similarity_.addSynonyms("east", "west", "north", "south");
|
|---|
| 23 | similarity_.addSynonyms("first", "second", "third");
|
|---|
| 24 | }
|
|---|
| 25 |
|
|---|
| 26 | @Test
|
|---|
| 27 | public void testSimilarNames() {
|
|---|
| 28 | checkSimilarity("same string", "Testname", "Testname", false);
|
|---|
| 29 | checkSimilarity("different case", "Testname", "TestName", true);
|
|---|
| 30 | checkSimilarity("typo", "Testname", "Testxame", true);
|
|---|
| 31 | checkSimilarity("missing char", "Testname", "Testame", true);
|
|---|
| 32 | checkSimilarity("additional char", "Testname", "Testxname", true);
|
|---|
| 33 | checkSimilarity("2 changes", "Testname", "Tostxname", true);
|
|---|
| 34 | checkSimilarity("3 changes", "Testname", "Tostxnam", false);
|
|---|
| 35 |
|
|---|
| 36 | // regular expression rule
|
|---|
| 37 | checkSimilarity("same number", "track 1", "track 1", false);
|
|---|
| 38 | checkSimilarity("different number", "track 1", "track 2", false);
|
|---|
| 39 | checkSimilarity("different number length", "track 9", "track 10", false);
|
|---|
| 40 | checkSimilarity("multiple numbers", "track 8 - 9", "track 10 - 11", false);
|
|---|
| 41 |
|
|---|
| 42 | checkSimilarity("1st and 2nd", "1st Street", "2nd Street", false);
|
|---|
| 43 | checkSimilarity("1st case", "1St Street", "1st Street", true);
|
|---|
| 44 | checkSimilarity("1st and 2nd case", "1St Street", "2nd Street", true);
|
|---|
| 45 | checkSimilarity("3rd and 4th", "2rd Street", "4th Street", false);
|
|---|
| 46 |
|
|---|
| 47 | // synonyms
|
|---|
| 48 | checkSimilarity("east and west", "East Foothill Drive", "West Foothill Drive", false);
|
|---|
| 49 | checkSimilarity("east and west case", "east Foothill Drive", "West Foothill Drive", true);
|
|---|
| 50 | checkSimilarity("first and second", "First Street", "Second Street", false);
|
|---|
| 51 | checkSimilarity("first and second case", "First Street", "second Street", true);
|
|---|
| 52 | checkSimilarity("first and second typo", "Forst Street", "Second Street", true);
|
|---|
| 53 | checkSimilarity("first and second typo2", "First Street", "Socond Street", true);
|
|---|
| 54 | checkSimilarity("first and second 2 changes", "First Street", "Soconds Street", true);
|
|---|
| 55 | checkSimilarity("first and second 3 changes", "First Street", "Soconds Stret", false);
|
|---|
| 56 | }
|
|---|
| 57 |
|
|---|
| 58 | private void checkSimilarity(String message, String name1, String name2, boolean expected) {
|
|---|
| 59 | boolean actual = similarity_.similaryName(name1, name2);
|
|---|
| 60 | assertEquals(message, expected, actual);
|
|---|
| 61 |
|
|---|
| 62 | }
|
|---|
| 63 | }
|
|---|