@Test public void testSimilarities() throws Exception { ScientificNameSimilarity sns = new ScientificNameSimilarity(); assertEquals(100d, sns.getSimilarity("A", "×A"), 0.01d); assertEquals(100d, sns.getSimilarity("Aa", "×Aa"), 0.01d); assertEquals(100d, sns.getSimilarity("Io", "×Io"), 0.01d); assertEquals(100d, sns.getSimilarity("Aus", "×Aus"), 0.01d); assertEquals(100d, sns.getSimilarity("Ausbus", "×Ausbus"), 0.01d); assertEquals(0d, sns.getSimilarity("Aus", "×Ausausaus"), 0.01d); assertEquals(0d, sns.getSimilarity("Ausausaus", "×Aus"), 0.01d); assertEquals(100d, sns.getSimilarity("abcdefg", "abcdefg"), 0.01d); assertEquals(80d, sns.getSimilarity("abcdefg", "amcdefg"), 0.01d); assertEquals(80d, sns.getSimilarity("abcdefg", "abcdeg"), 0.01d); assertEquals(0d, sns.getSimilarity("abcdefg", "zyxvwu"), 0.01d); assertEquals(0d, sns.getSimilarity("abcdefg", "amncdefg"), 0.01d); assertEquals(0d, sns.getSimilarity("abcdefg", "adefg"), 0.01d); assertEquals(0d, sns.getSimilarity("abcdefg", "aabbccddeeffgg"), 0.01d); assertEquals(100d, sns.getSimilarity("Aka abcdefg", "Aka aabbccddeeffgg"), 0.01d); assertEquals(100d, sns.getSimilarity("äöüæøåœđł", "aouaeoaoedl"), 0.01d); assertEquals(100d, sns.getSimilarity("xAus", "Aus"), 0.01d); assertEquals(100d, sns.getSimilarity("x Aus", "Aus"), 0.01d); assertEquals(100d, sns.getSimilarity("×Aus", "Aus"), 0.01d); assertEquals(100d, sns.getSimilarity("× Aus", "Aus"), 0.01d); assertEquals(100d, sns.getSimilarity("Abies alba", "Abies alba"), 0.01d); assertEquals(100d, sns.getSimilarity("Abies alba", "Abies albus"), 0.01d); assertEquals(5d, sns.getSimilarity("Abies alba", "Abies olba"), 0.01d); assertEquals(95d, sns.getSimilarity("Abies alba", "Abies alta"), 0.01d); assertEquals(100d, sns.getSimilarity("Abies ama", "Abies amus"), 0.01d); assertEquals(100d, sns.getSimilarity("Abies ama", "Abies amus"), 0.01d); assertEquals(100d, sns.getSimilarity("Abies ama", "Abies amum"), 0.01d); assertEquals(95d, sns.getSimilarity("Linaria pedunculata", "Linaria pedinculata"), 0.01d); assertEquals(90d, sns.getSimilarity("Linaria pedunculata", "Lunaria pedunculata"), 0.01d); assertEquals(85d, sns.getSimilarity("Linaria pedunculata", "Linariya pedonculata"), 0.01d); assertEquals(93.33d, sns.getSimilarity("Linaria pedunculata vulgaris", "Lunaria pedunculata vulgaris"), 0.01d); assertEquals(5d, sns.getSimilarity("Linaria pedunculata vulgaris", "Linaria pedunculata vandalis"), 0.01d); assertEquals(5d, sns.getSimilarity("Oreina elegans", "Orfelia elegans"), 0.01d); assertEquals(5d, sns.getSimilarity("Lucina scotti", "Lucina wattsi"), 0.01d); assertEquals(0d, sns.getSimilarity("scotti", "wattsi"), 0.01d); }
@Override public double getSimilarity(String x1, String x2) { if (x1.equals(x2)) return 100d; LOG.debug("‘{}’\twas previously {}% like ‘{}’", x1, mdl3.getSimilarity(x1, x2), x2); x1 = SciNameNormalizer.normalize(x1); x2 = SciNameNormalizer.normalize(x2); String[] x1s = x1.split(" "); String[] x2s = x2.split(" "); if (x1s.length != x2s.length) { double sim = mdl3.getSimilarity(x1, x2); LOG.debug("‘{}’\tis {}% like ‘{}’ (but lengths differ)\n", x1, sim, x2); return sim; } boolean bad = false; double overallSim = 0; int i; for (i = 0; i < x1s.length; i++) { double sim = similarity(x1s[i], x2s[i]); if (i == 0) { sim = Math.max(0, (2*sim - 100)); } overallSim += sim; if (sim == 0) bad = true; } overallSim = overallSim/i; if (bad && overallSim > 5) { overallSim = 5; } LOG.debug("‘{}’\tis {}% like ‘{}’\n", x1, overallSim, x2); return overallSim; }
ScientificNameSimilarity implements StringSimilarity { @Override public double getSimilarity(String x1, String x2) { if (x1.equals(x2)) return 100d; LOG.debug("‘{}’\twas previously {}% like ‘{}’", x1, mdl3.getSimilarity(x1, x2), x2); x1 = SciNameNormalizer.normalize(x1); x2 = SciNameNormalizer.normalize(x2); String[] x1s = x1.split(" "); String[] x2s = x2.split(" "); if (x1s.length != x2s.length) { double sim = mdl3.getSimilarity(x1, x2); LOG.debug("‘{}’\tis {}% like ‘{}’ (but lengths differ)\n", x1, sim, x2); return sim; } boolean bad = false; double overallSim = 0; int i; for (i = 0; i < x1s.length; i++) { double sim = similarity(x1s[i], x2s[i]); if (i == 0) { sim = Math.max(0, (2*sim - 100)); } overallSim += sim; if (sim == 0) bad = true; } overallSim = overallSim/i; if (bad && overallSim > 5) { overallSim = 5; } LOG.debug("‘{}’\tis {}% like ‘{}’\n", x1, overallSim, x2); return overallSim; } }
ScientificNameSimilarity implements StringSimilarity { @Override public double getSimilarity(String x1, String x2) { if (x1.equals(x2)) return 100d; LOG.debug("‘{}’\twas previously {}% like ‘{}’", x1, mdl3.getSimilarity(x1, x2), x2); x1 = SciNameNormalizer.normalize(x1); x2 = SciNameNormalizer.normalize(x2); String[] x1s = x1.split(" "); String[] x2s = x2.split(" "); if (x1s.length != x2s.length) { double sim = mdl3.getSimilarity(x1, x2); LOG.debug("‘{}’\tis {}% like ‘{}’ (but lengths differ)\n", x1, sim, x2); return sim; } boolean bad = false; double overallSim = 0; int i; for (i = 0; i < x1s.length; i++) { double sim = similarity(x1s[i], x2s[i]); if (i == 0) { sim = Math.max(0, (2*sim - 100)); } overallSim += sim; if (sim == 0) bad = true; } overallSim = overallSim/i; if (bad && overallSim > 5) { overallSim = 5; } LOG.debug("‘{}’\tis {}% like ‘{}’\n", x1, overallSim, x2); return overallSim; }  }
ScientificNameSimilarity implements StringSimilarity { @Override public double getSimilarity(String x1, String x2) { if (x1.equals(x2)) return 100d; LOG.debug("‘{}’\twas previously {}% like ‘{}’", x1, mdl3.getSimilarity(x1, x2), x2); x1 = SciNameNormalizer.normalize(x1); x2 = SciNameNormalizer.normalize(x2); String[] x1s = x1.split(" "); String[] x2s = x2.split(" "); if (x1s.length != x2s.length) { double sim = mdl3.getSimilarity(x1, x2); LOG.debug("‘{}’\tis {}% like ‘{}’ (but lengths differ)\n", x1, sim, x2); return sim; } boolean bad = false; double overallSim = 0; int i; for (i = 0; i < x1s.length; i++) { double sim = similarity(x1s[i], x2s[i]); if (i == 0) { sim = Math.max(0, (2*sim - 100)); } overallSim += sim; if (sim == 0) bad = true; } overallSim = overallSim/i; if (bad && overallSim > 5) { overallSim = 5; } LOG.debug("‘{}’\tis {}% like ‘{}’\n", x1, overallSim, x2); return overallSim; }  @Override double getSimilarity(String x1, String x2); }
ScientificNameSimilarity implements StringSimilarity { @Override public double getSimilarity(String x1, String x2) { if (x1.equals(x2)) return 100d; LOG.debug("‘{}’\twas previously {}% like ‘{}’", x1, mdl3.getSimilarity(x1, x2), x2); x1 = SciNameNormalizer.normalize(x1); x2 = SciNameNormalizer.normalize(x2); String[] x1s = x1.split(" "); String[] x2s = x2.split(" "); if (x1s.length != x2s.length) { double sim = mdl3.getSimilarity(x1, x2); LOG.debug("‘{}’\tis {}% like ‘{}’ (but lengths differ)\n", x1, sim, x2); return sim; } boolean bad = false; double overallSim = 0; int i; for (i = 0; i < x1s.length; i++) { double sim = similarity(x1s[i], x2s[i]); if (i == 0) { sim = Math.max(0, (2*sim - 100)); } overallSim += sim; if (sim == 0) bad = true; } overallSim = overallSim/i; if (bad && overallSim > 5) { overallSim = 5; } LOG.debug("‘{}’\tis {}% like ‘{}’\n", x1, overallSim, x2); return overallSim; }  @Override double getSimilarity(String x1, String x2);  }