LingoSimilarity { public static float calculate(Map<String, Integer> features1, Map<String, Integer> features2) { TreeSet<String> keys = new TreeSet<String>(features1.keySet()); keys.addAll(features2.keySet()); float sum = 0.0f; for (String key : keys) { Integer c1 = features1.get(key); Integer c2 = features2.get(key); c1 = c1 == null ? 0 : c1; c2 = c2 == null ? 0 : c2; sum += 1.0 - Math.abs(c1 - c2) / (c1 + c2); } return sum / keys.size(); } private  LingoSimilarity(); static float calculate(Map<String, Integer> features1, Map<String, Integer> features2);  }
@Test public void testLingoSim() throws Exception { IAtomContainer mol1 = TestMoleculeFactory.makeIndole(); IAtomContainer mol2 = TestMoleculeFactory.makeIndole(); addImplicitHydrogens(mol1); addImplicitHydrogens(mol2); AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(mol1); AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(mol2); LingoFingerprinter fingerprinter = new LingoFingerprinter(); Map<String, Integer> bs1 = fingerprinter.getRawFingerprint(mol1); Map<String, Integer> bs2 = fingerprinter.getRawFingerprint(mol2); float lingosim = LingoSimilarity.calculate(bs1, bs2); Assert.assertEquals(1.0, lingosim, 0.01); }