@Test void testFindQuery() { QueryRule queryRule_1 = new QueryRule(AttributeMetadata.LABEL, Operator.FUZZY_MATCH, "hypertension"); QueryRule queryRule_2 = new QueryRule(AttributeMetadata.LABEL, Operator.FUZZY_MATCH, "hypertensive disorder"); QueryRule queryRule_3 = new QueryRule(AttributeMetadata.LABEL, Operator.FUZZY_MATCH, "high blood pressure"); QueryRule queryRule_4 = new QueryRule(AttributeMetadata.LABEL, Operator.FUZZY_MATCH, "drug"); QueryRule queryRule_5 = new QueryRule(AttributeMetadata.LABEL, Operator.FUZZY_MATCH, "medication"); QueryRule queryRule_6 = new QueryRule(AttributeMetadata.LABEL, Operator.FUZZY_MATCH, "pill"); QueryRule disMaxQueryRule_1 = new QueryRule(Arrays.asList(queryRule_1, queryRule_2, queryRule_3)); disMaxQueryRule_1.setOperator(Operator.DIS_MAX); QueryRule disMaxQueryRule_2 = new QueryRule(Arrays.asList(queryRule_4, queryRule_5, queryRule_6)); disMaxQueryRule_2.setOperator(Operator.DIS_MAX); QueryRule shouldQueryRule = new QueryRule(Arrays.asList(disMaxQueryRule_1, disMaxQueryRule_2)); shouldQueryRule.setOperator(Operator.SHOULD); QueryRule finalDisMaxQueryRule = new QueryRule(Arrays.asList(shouldQueryRule)); finalDisMaxQueryRule.setOperator(Operator.DIS_MAX); Map<String, String> expanedQueryMap = new HashMap<>(); expanedQueryMap.put("hypertension", "hypertension"); expanedQueryMap.put("hypertensive disorder", "hypertension"); expanedQueryMap.put("high blood pressure", "hypertension"); expanedQueryMap.put("medication", "medication"); expanedQueryMap.put("drug", "medication"); expanedQueryMap.put("pill", "medication"); Map<String, Double> findMatchQueries = explainServiceHelper.findMatchQueries("blood high", expanedQueryMap); assertEquals(findMatchQueries.get("high blood pressure"), 73.333, 0.001); }
Map<String, Double> findMatchQueries( String matchedWordsString, Map<String, String> collectExpandedQueryMap) { Map<String, Double> qualifiedQueries = new HashMap<>(); Set<String> matchedWords = splitIntoTerms(matchedWordsString); for (Entry<String, String> entry : collectExpandedQueryMap.entrySet()) { Set<String> wordsInQuery = splitIntoTerms(entry.getKey()); if (wordsInQuery.containsAll(matchedWords)) { qualifiedQueries.put( entry.getKey(), NGramDistanceAlgorithm.stringMatching(matchedWordsString, entry.getKey())); } } return qualifiedQueries; }
ExplainServiceHelper { Map<String, Double> findMatchQueries( String matchedWordsString, Map<String, String> collectExpandedQueryMap) { Map<String, Double> qualifiedQueries = new HashMap<>(); Set<String> matchedWords = splitIntoTerms(matchedWordsString); for (Entry<String, String> entry : collectExpandedQueryMap.entrySet()) { Set<String> wordsInQuery = splitIntoTerms(entry.getKey()); if (wordsInQuery.containsAll(matchedWords)) { qualifiedQueries.put( entry.getKey(), NGramDistanceAlgorithm.stringMatching(matchedWordsString, entry.getKey())); } } return qualifiedQueries; } }
ExplainServiceHelper { Map<String, Double> findMatchQueries( String matchedWordsString, Map<String, String> collectExpandedQueryMap) { Map<String, Double> qualifiedQueries = new HashMap<>(); Set<String> matchedWords = splitIntoTerms(matchedWordsString); for (Entry<String, String> entry : collectExpandedQueryMap.entrySet()) { Set<String> wordsInQuery = splitIntoTerms(entry.getKey()); if (wordsInQuery.containsAll(matchedWords)) { qualifiedQueries.put( entry.getKey(), NGramDistanceAlgorithm.stringMatching(matchedWordsString, entry.getKey())); } } return qualifiedQueries; }  }
ExplainServiceHelper { Map<String, Double> findMatchQueries( String matchedWordsString, Map<String, String> collectExpandedQueryMap) { Map<String, Double> qualifiedQueries = new HashMap<>(); Set<String> matchedWords = splitIntoTerms(matchedWordsString); for (Entry<String, String> entry : collectExpandedQueryMap.entrySet()) { Set<String> wordsInQuery = splitIntoTerms(entry.getKey()); if (wordsInQuery.containsAll(matchedWords)) { qualifiedQueries.put( entry.getKey(), NGramDistanceAlgorithm.stringMatching(matchedWordsString, entry.getKey())); } } return qualifiedQueries; }   }
ExplainServiceHelper { Map<String, Double> findMatchQueries( String matchedWordsString, Map<String, String> collectExpandedQueryMap) { Map<String, Double> qualifiedQueries = new HashMap<>(); Set<String> matchedWords = splitIntoTerms(matchedWordsString); for (Entry<String, String> entry : collectExpandedQueryMap.entrySet()) { Set<String> wordsInQuery = splitIntoTerms(entry.getKey()); if (wordsInQuery.containsAll(matchedWords)) { qualifiedQueries.put( entry.getKey(), NGramDistanceAlgorithm.stringMatching(matchedWordsString, entry.getKey())); } } return qualifiedQueries; }    }