@Test void testIsSingleMatchHighQuality() { List<ExplainedQueryString> explanations1 = singletonList(ExplainedQueryString.create("height", "height", "standing height", 50.0)); assertFalse( semanticSearchService.isSingleMatchHighQuality( newHashSet("height"), newHashSet("height"), explanations1)); List<ExplainedQueryString> explanations2 = singletonList(ExplainedQueryString.create("body length", "body length", "height", 100)); assertTrue( semanticSearchService.isSingleMatchHighQuality( newHashSet("height in meter"), newHashSet("height in meter", "height"), explanations2)); List<ExplainedQueryString> explanations3 = asList( ExplainedQueryString.create("fasting", "fasting", "fasting", 100), ExplainedQueryString.create("glucose", "blood glucose", "blood glucose", 50)); assertFalse( semanticSearchService.isSingleMatchHighQuality( newHashSet("fasting glucose"), newHashSet("fasting glucose", "fasting", "blood glucose"), explanations3)); List<ExplainedQueryString> explanations4 = singletonList(ExplainedQueryString.create("number of", "number of", "number", 100)); assertFalse( semanticSearchService.isSingleMatchHighQuality( newHashSet("number of cigarette smoked"), newHashSet("number of cigarette smoked", "number of"), explanations4)); }
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; return (!ontologyTermQueries.isEmpty() && ontologyTermQueries.stream().allMatch(token -> isGoodMatch(matchedTags, token))); }
SemanticSearchServiceImpl implements SemanticSearchService { 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; return (!ontologyTermQueries.isEmpty() && ontologyTermQueries.stream().allMatch(token -> isGoodMatch(matchedTags, token))); } }
SemanticSearchServiceImpl implements SemanticSearchService { 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; return (!ontologyTermQueries.isEmpty() && ontologyTermQueries.stream().allMatch(token -> isGoodMatch(matchedTags, token))); } SemanticSearchServiceImpl(
      DataService dataService,
      OntologyService ontologyService,
      SemanticSearchServiceHelper semanticSearchServiceHelper,
      ElasticSearchExplainService elasticSearchExplainService,
      OntologyTagService ontologyTagService); }
SemanticSearchServiceImpl implements SemanticSearchService { 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; return (!ontologyTermQueries.isEmpty() && ontologyTermQueries.stream().allMatch(token -> isGoodMatch(matchedTags, token))); } SemanticSearchServiceImpl(
      DataService dataService,
      OntologyService ontologyService,
      SemanticSearchServiceHelper semanticSearchServiceHelper,
      ElasticSearchExplainService elasticSearchExplainService,
      OntologyTagService ontologyTagService); Hits<ExplainedAttribute> findAttributes(
      EntityType sourceEntityType, Set<String> queryTerms, Collection<OntologyTerm> ontologyTerms); @Override EntityTypeSearchResults findAttributes(
      EntityType sourceEntityType, EntityType targetEntityType, Set<String> searchTerms); @Override AttributeSearchResults findAttributes(
      EntityType sourceEntityType,
      EntityType targetEntityType,
      Attribute targetAttribute,
      Set<String> searchTerms); Set<String> createLexicalSearchQueryTerms(
      Attribute targetAttribute, Set<String> searchTerms); Set<ExplainedQueryString> convertAttributeToExplainedAttribute(
      Attribute attribute, Map<String, String> collectExpandedQueryMap, Query<Entity> query); @Override Hits<OntologyTerm> findOntologyTerms(
      Attribute attribute, Collection<Ontology> ontologies); }
SemanticSearchServiceImpl implements SemanticSearchService { 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; return (!ontologyTermQueries.isEmpty() && ontologyTermQueries.stream().allMatch(token -> isGoodMatch(matchedTags, token))); } SemanticSearchServiceImpl(
      DataService dataService,
      OntologyService ontologyService,
      SemanticSearchServiceHelper semanticSearchServiceHelper,
      ElasticSearchExplainService elasticSearchExplainService,
      OntologyTagService ontologyTagService); Hits<ExplainedAttribute> findAttributes(
      EntityType sourceEntityType, Set<String> queryTerms, Collection<OntologyTerm> ontologyTerms); @Override EntityTypeSearchResults findAttributes(
      EntityType sourceEntityType, EntityType targetEntityType, Set<String> searchTerms); @Override AttributeSearchResults findAttributes(
      EntityType sourceEntityType,
      EntityType targetEntityType,
      Attribute targetAttribute,
      Set<String> searchTerms); Set<String> createLexicalSearchQueryTerms(
      Attribute targetAttribute, Set<String> searchTerms); Set<ExplainedQueryString> convertAttributeToExplainedAttribute(
      Attribute attribute, Map<String, String> collectExpandedQueryMap, Query<Entity> query); @Override Hits<OntologyTerm> findOntologyTerms(
      Attribute attribute, Collection<Ontology> ontologies);  }