use of org.molgenis.semanticsearch.explain.bean.ExplainedQueryString in project molgenis by molgenis.
the class SemanticSearchServiceImpl method isSingleMatchHighQuality.
boolean isSingleMatchHighQuality(Collection<String> queryTerms, Collection<String> ontologyTermQueries, Iterable<ExplainedQueryString> explanations) {
Map<String, Double> matchedTags = new HashMap<>();
for (ExplainedQueryString explanation : explanations) {
matchedTags.put(explanation.getTagName().toLowerCase(), explanation.getScore());
}
ontologyTermQueries.removeAll(queryTerms);
if (!queryTerms.isEmpty() && queryTerms.stream().anyMatch(token -> isGoodMatch(matchedTags, token)))
return true;
if (!ontologyTermQueries.isEmpty() && ontologyTermQueries.stream().allMatch(token -> isGoodMatch(matchedTags, token)))
return true;
return false;
}
use of org.molgenis.semanticsearch.explain.bean.ExplainedQueryString in project molgenis by molgenis.
the class ElasticSearchExplainServiceImplTest method testReverseSearchQueryStrings.
@Test
public void testReverseSearchQueryStrings() {
Explanation explanation_2 = Explanation.match(Float.valueOf("3.6267629"), "sum of:", Explanation.match(Float.valueOf("2.0587344"), "weight(label:high in 328) [PerFieldSimilarity], result of:"), Explanation.match(Float.valueOf("1.5680285"), "weight(label:blood in 328) [PerFieldSimilarity], result of:"));
Explanation explanation_3 = Explanation.match(Float.valueOf("1.754909"), "max of:", Explanation.match(Float.valueOf("1.754909"), "weight(label:medication in 328) [PerFieldSimilarity], result of:"));
Explanation explanation_1 = Explanation.match(Float.valueOf("5.381672"), "sum of:", explanation_2, explanation_3);
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");
Set<ExplainedQueryString> reverseSearchQueryStrings = elasticSearchExplainService.findQueriesFromExplanation(expanedQueryMap, explanation_1);
Iterator<ExplainedQueryString> iterator = reverseSearchQueryStrings.iterator();
ExplainedQueryString first = iterator.next();
assertEquals(first.getMatchedWords(), "high blood");
assertEquals(first.getQueryString(), "high blood pressure");
assertEquals(first.getTagName(), "hypertension");
assertEquals((int) first.getScore(), 73);
ExplainedQueryString second = iterator.next();
assertEquals(second.getMatchedWords(), "medication");
assertEquals(second.getQueryString(), "medication");
assertEquals(second.getTagName(), "medication");
assertEquals((int) second.getScore(), 100);
}
Aggregations