@Test void calculateScore() { assertEquals(100.0, stringMatching("hypertensive", "hypertensive")); assertEquals( NGramDistanceAlgorithm.stringMatching("hypertensive disorder", "hypertensive order"), 72.727, 0.001); assertEquals(0.0, stringMatching("hypertensive", "diabetes")); assertEquals(0.0, stringMatching("", "")); }
private static double calculateScore( Map<String, Integer> inputStringTokens, Map<String, Integer> ontologyTermTokens) { if (inputStringTokens.size() == 0 || ontologyTermTokens.size() == 0) { return (double) 0; } int totalToken = getTotalNumTokens(inputStringTokens) + getTotalNumTokens(ontologyTermTokens); int numMatchedToken = 0; for (Entry<String, Integer> token : inputStringTokens.entrySet()) { if (ontologyTermTokens.containsKey(token.getKey())) { numMatchedToken += Math.min(token.getValue(), ontologyTermTokens.get(token.getKey())); } } if (totalToken == 0) { return 0; } else { return 2.0 * numMatchedToken / totalToken * 100; } }
NGramDistanceAlgorithm { private static double calculateScore( Map<String, Integer> inputStringTokens, Map<String, Integer> ontologyTermTokens) { if (inputStringTokens.size() == 0 || ontologyTermTokens.size() == 0) { return (double) 0; } int totalToken = getTotalNumTokens(inputStringTokens) + getTotalNumTokens(ontologyTermTokens); int numMatchedToken = 0; for (Entry<String, Integer> token : inputStringTokens.entrySet()) { if (ontologyTermTokens.containsKey(token.getKey())) { numMatchedToken += Math.min(token.getValue(), ontologyTermTokens.get(token.getKey())); } } if (totalToken == 0) { return 0; } else { return 2.0 * numMatchedToken / totalToken * 100; } } }
NGramDistanceAlgorithm { private static double calculateScore( Map<String, Integer> inputStringTokens, Map<String, Integer> ontologyTermTokens) { if (inputStringTokens.size() == 0 || ontologyTermTokens.size() == 0) { return (double) 0; } int totalToken = getTotalNumTokens(inputStringTokens) + getTotalNumTokens(ontologyTermTokens); int numMatchedToken = 0; for (Entry<String, Integer> token : inputStringTokens.entrySet()) { if (ontologyTermTokens.containsKey(token.getKey())) { numMatchedToken += Math.min(token.getValue(), ontologyTermTokens.get(token.getKey())); } } if (totalToken == 0) { return 0; } else { return 2.0 * numMatchedToken / totalToken * 100; } } private  NGramDistanceAlgorithm(); }
NGramDistanceAlgorithm { private static double calculateScore( Map<String, Integer> inputStringTokens, Map<String, Integer> ontologyTermTokens) { if (inputStringTokens.size() == 0 || ontologyTermTokens.size() == 0) { return (double) 0; } int totalToken = getTotalNumTokens(inputStringTokens) + getTotalNumTokens(ontologyTermTokens); int numMatchedToken = 0; for (Entry<String, Integer> token : inputStringTokens.entrySet()) { if (ontologyTermTokens.containsKey(token.getKey())) { numMatchedToken += Math.min(token.getValue(), ontologyTermTokens.get(token.getKey())); } } if (totalToken == 0) { return 0; } else { return 2.0 * numMatchedToken / totalToken * 100; } } private  NGramDistanceAlgorithm(); static double stringMatching(String queryOne, String queryTwo); static Map<String, Integer> createNGrams(String inputQuery, boolean removeStopWords); }
NGramDistanceAlgorithm { private static double calculateScore( Map<String, Integer> inputStringTokens, Map<String, Integer> ontologyTermTokens) { if (inputStringTokens.size() == 0 || ontologyTermTokens.size() == 0) { return (double) 0; } int totalToken = getTotalNumTokens(inputStringTokens) + getTotalNumTokens(ontologyTermTokens); int numMatchedToken = 0; for (Entry<String, Integer> token : inputStringTokens.entrySet()) { if (ontologyTermTokens.containsKey(token.getKey())) { numMatchedToken += Math.min(token.getValue(), ontologyTermTokens.get(token.getKey())); } } if (totalToken == 0) { return 0; } else { return 2.0 * numMatchedToken / totalToken * 100; } } private  NGramDistanceAlgorithm(); static double stringMatching(String queryOne, String queryTwo); static Map<String, Integer> createNGrams(String inputQuery, boolean removeStopWords); static final Set<String> STOPWORDSLIST; }