@Test void testCreateDisMaxQueryRule() { List<String> createdTargetAttributeQueries = asList( "Height", "Standing height in cm", "body_length", "Sitting height", "sitting_length", "Height", "sature"); QueryRule actualRule = semanticSearchServiceHelper.createDisMaxQueryRuleForTerms(createdTargetAttributeQueries); String expectedQueryRuleToString = "DIS_MAX ('label' FUZZY_MATCH 'Height', 'description' FUZZY_MATCH 'Height', 'label' FUZZY_MATCH 'Standing height in cm', 'description' FUZZY_MATCH 'Standing height in cm', 'label' FUZZY_MATCH 'body_length', 'description' FUZZY_MATCH 'body_length', 'label' FUZZY_MATCH 'Sitting height', 'description' FUZZY_MATCH 'Sitting height', 'label' FUZZY_MATCH 'sitting_length', 'description' FUZZY_MATCH 'sitting_length', 'label' FUZZY_MATCH 'Height', 'description' FUZZY_MATCH 'Height', 'label' FUZZY_MATCH 'sature', 'description' FUZZY_MATCH 'sature')"; assertEquals(DIS_MAX, actualRule.getOperator()); assertEquals(expectedQueryRuleToString, actualRule.toString()); List<String> createdTargetAttributeQueries2 = singletonList("(Height) [stand^~]"); QueryRule actualRule2 = semanticSearchServiceHelper.createDisMaxQueryRuleForTerms(createdTargetAttributeQueries2); String expectedQueryRuleToString2 = "DIS_MAX ('label' FUZZY_MATCH '\\(Height\\) \\[stand^\\~\\]', 'description' FUZZY_MATCH '\\(Height\\) \\[stand^\\~\\]')"; assertEquals(DIS_MAX, actualRule2.getOperator()); assertEquals(expectedQueryRuleToString2, actualRule2.toString()); }
public QueryRule createDisMaxQueryRuleForTerms(List<String> queryTerms) { List<QueryRule> rules = new ArrayList<>(); queryTerms.stream() .filter(StringUtils::isNotEmpty) .map(this::escapeCharsExcludingCaretChar) .forEach( query -> { rules.add(new QueryRule(AttributeMetadata.LABEL, Operator.FUZZY_MATCH, query)); rules.add(new QueryRule(AttributeMetadata.DESCRIPTION, Operator.FUZZY_MATCH, query)); }); QueryRule finalDisMaxQuery = new QueryRule(rules); finalDisMaxQuery.setOperator(Operator.DIS_MAX); return finalDisMaxQuery; }
SemanticSearchServiceHelper { public QueryRule createDisMaxQueryRuleForTerms(List<String> queryTerms) { List<QueryRule> rules = new ArrayList<>(); queryTerms.stream() .filter(StringUtils::isNotEmpty) .map(this::escapeCharsExcludingCaretChar) .forEach( query -> { rules.add(new QueryRule(AttributeMetadata.LABEL, Operator.FUZZY_MATCH, query)); rules.add(new QueryRule(AttributeMetadata.DESCRIPTION, Operator.FUZZY_MATCH, query)); }); QueryRule finalDisMaxQuery = new QueryRule(rules); finalDisMaxQuery.setOperator(Operator.DIS_MAX); return finalDisMaxQuery; } }
SemanticSearchServiceHelper { public QueryRule createDisMaxQueryRuleForTerms(List<String> queryTerms) { List<QueryRule> rules = new ArrayList<>(); queryTerms.stream() .filter(StringUtils::isNotEmpty) .map(this::escapeCharsExcludingCaretChar) .forEach( query -> { rules.add(new QueryRule(AttributeMetadata.LABEL, Operator.FUZZY_MATCH, query)); rules.add(new QueryRule(AttributeMetadata.DESCRIPTION, Operator.FUZZY_MATCH, query)); }); QueryRule finalDisMaxQuery = new QueryRule(rules); finalDisMaxQuery.setOperator(Operator.DIS_MAX); return finalDisMaxQuery; } SemanticSearchServiceHelper(
      DataService dataService,
      OntologyService ontologyService,
      TermFrequencyService termFrequencyService); }
SemanticSearchServiceHelper { public QueryRule createDisMaxQueryRuleForTerms(List<String> queryTerms) { List<QueryRule> rules = new ArrayList<>(); queryTerms.stream() .filter(StringUtils::isNotEmpty) .map(this::escapeCharsExcludingCaretChar) .forEach( query -> { rules.add(new QueryRule(AttributeMetadata.LABEL, Operator.FUZZY_MATCH, query)); rules.add(new QueryRule(AttributeMetadata.DESCRIPTION, Operator.FUZZY_MATCH, query)); }); QueryRule finalDisMaxQuery = new QueryRule(rules); finalDisMaxQuery.setOperator(Operator.DIS_MAX); return finalDisMaxQuery; } SemanticSearchServiceHelper(
      DataService dataService,
      OntologyService ontologyService,
      TermFrequencyService termFrequencyService); QueryRule createDisMaxQueryRuleForAttribute(
      Set<String> searchTerms, Collection<OntologyTerm> ontologyTerms); QueryRule createDisMaxQueryRuleForTerms(List<String> queryTerms); QueryRule createBoostedDisMaxQueryRuleForTerms(
      List<String> queryTerms, Double boostValue); QueryRule createShouldQueryRule(String multiOntologyTermIri); List<String> parseOntologyTermQueries(OntologyTerm ontologyTerm); Set<String> getOtLabelAndSynonyms(OntologyTerm ontologyTerm); Map<String, String> collectExpandedQueryMap(
      Set<String> queryTerms, Collection<OntologyTerm> ontologyTerms); void collectOntologyTermQueryMap(
      Map<String, String> expanedQueryMap, OntologyTerm ontologyTerm); List<String> getAttributeIdentifiers(EntityType sourceEntityType); List<OntologyTerm> findTags(String description, List<String> ontologyIds); String processQueryString(String queryString); String parseBoostQueryString(String queryString, double boost); String escapeCharsExcludingCaretChar(String string); Set<String> removeStopWords(String description); }
SemanticSearchServiceHelper { public QueryRule createDisMaxQueryRuleForTerms(List<String> queryTerms) { List<QueryRule> rules = new ArrayList<>(); queryTerms.stream() .filter(StringUtils::isNotEmpty) .map(this::escapeCharsExcludingCaretChar) .forEach( query -> { rules.add(new QueryRule(AttributeMetadata.LABEL, Operator.FUZZY_MATCH, query)); rules.add(new QueryRule(AttributeMetadata.DESCRIPTION, Operator.FUZZY_MATCH, query)); }); QueryRule finalDisMaxQuery = new QueryRule(rules); finalDisMaxQuery.setOperator(Operator.DIS_MAX); return finalDisMaxQuery; } SemanticSearchServiceHelper(
      DataService dataService,
      OntologyService ontologyService,
      TermFrequencyService termFrequencyService); QueryRule createDisMaxQueryRuleForAttribute(
      Set<String> searchTerms, Collection<OntologyTerm> ontologyTerms); QueryRule createDisMaxQueryRuleForTerms(List<String> queryTerms); QueryRule createBoostedDisMaxQueryRuleForTerms(
      List<String> queryTerms, Double boostValue); QueryRule createShouldQueryRule(String multiOntologyTermIri); List<String> parseOntologyTermQueries(OntologyTerm ontologyTerm); Set<String> getOtLabelAndSynonyms(OntologyTerm ontologyTerm); Map<String, String> collectExpandedQueryMap(
      Set<String> queryTerms, Collection<OntologyTerm> ontologyTerms); void collectOntologyTermQueryMap(
      Map<String, String> expanedQueryMap, OntologyTerm ontologyTerm); List<String> getAttributeIdentifiers(EntityType sourceEntityType); List<OntologyTerm> findTags(String description, List<String> ontologyIds); String processQueryString(String queryString); String parseBoostQueryString(String queryString, double boost); String escapeCharsExcludingCaretChar(String string); Set<String> removeStopWords(String description); static final int MAX_NUM_TAGS; }