@Test void testCreateTargetAttributeQueryTerms() { Attribute targetAttribute_1 = attrMetaFactory.create().setName("targetAttribute 1"); targetAttribute_1.setDescription("Height"); Attribute targetAttribute_2 = attrMetaFactory.create().setName("targetAttribute 2"); targetAttribute_2.setLabel("Height"); Multimap<Relation, OntologyTerm> tags = LinkedHashMultimap.create(); OntologyTerm ontologyTerm1 = OntologyTerm.create( "http: "Standing height", "Description is not used", singletonList("body_length")); OntologyTerm ontologyTerm2 = OntologyTerm.create( "http: "Sitting height", "Description is not used", singletonList("sitting_length")); OntologyTerm ontologyTerm3 = OntologyTerm.create( "http: tags.put(Relation.isAssociatedWith, ontologyTerm1); tags.put(Relation.isRealizationOf, ontologyTerm2); tags.put(Relation.isDefinedBy, ontologyTerm3); QueryRule actualTargetAttributeQueryTerms_1 = semanticSearchServiceHelper.createDisMaxQueryRuleForAttribute( Sets.newLinkedHashSet(asList("targetAttribute 1", "Height")), tags.values()); String expecteddisMaxQueryRuleToString_1 = "DIS_MAX ('label' FUZZY_MATCH '1 targetattribute', 'description' FUZZY_MATCH '1 targetattribute', 'label' FUZZY_MATCH 'height', 'description' FUZZY_MATCH 'height', 'label' FUZZY_MATCH 'length body', 'description' FUZZY_MATCH 'length body', 'label' FUZZY_MATCH 'standing height', 'description' FUZZY_MATCH 'standing height', 'label' FUZZY_MATCH 'length sitting', 'description' FUZZY_MATCH 'length sitting', 'label' FUZZY_MATCH 'sitting height', 'description' FUZZY_MATCH 'sitting height', 'label' FUZZY_MATCH 'sature', 'description' FUZZY_MATCH 'sature', 'label' FUZZY_MATCH 'height', 'description' FUZZY_MATCH 'height')"; assertEquals(expecteddisMaxQueryRuleToString_1, actualTargetAttributeQueryTerms_1.toString()); QueryRule expecteddisMaxQueryRuleToString_2 = semanticSearchServiceHelper.createDisMaxQueryRuleForAttribute( Sets.newHashSet("Height"), tags.values()); String expectedTargetAttributeQueryTermsToString_2 = "DIS_MAX ('label' FUZZY_MATCH 'height', 'description' FUZZY_MATCH 'height', 'label' FUZZY_MATCH 'length body', 'description' FUZZY_MATCH 'length body', 'label' FUZZY_MATCH 'standing height', 'description' FUZZY_MATCH 'standing height', 'label' FUZZY_MATCH 'length sitting', 'description' FUZZY_MATCH 'length sitting', 'label' FUZZY_MATCH 'sitting height', 'description' FUZZY_MATCH 'sitting height', 'label' FUZZY_MATCH 'sature', 'description' FUZZY_MATCH 'sature', 'label' FUZZY_MATCH 'height', 'description' FUZZY_MATCH 'height')"; assertEquals( expectedTargetAttributeQueryTermsToString_2, expecteddisMaxQueryRuleToString_2.toString()); QueryRule expecteddisMaxQueryRuleToString_3 = semanticSearchServiceHelper.createDisMaxQueryRuleForAttribute( Sets.newHashSet("targetAttribute 3"), tags.values()); String expectedTargetAttributeQueryTermsToString_3 = "DIS_MAX ('label' FUZZY_MATCH '3 targetattribute', 'description' FUZZY_MATCH '3 targetattribute', 'label' FUZZY_MATCH 'length body', 'description' FUZZY_MATCH 'length body', 'label' FUZZY_MATCH 'standing height', 'description' FUZZY_MATCH 'standing height', 'label' FUZZY_MATCH 'length sitting', 'description' FUZZY_MATCH 'length sitting', 'label' FUZZY_MATCH 'sitting height', 'description' FUZZY_MATCH 'sitting height', 'label' FUZZY_MATCH 'sature', 'description' FUZZY_MATCH 'sature', 'label' FUZZY_MATCH 'height', 'description' FUZZY_MATCH 'height')"; assertEquals( expectedTargetAttributeQueryTermsToString_3, expecteddisMaxQueryRuleToString_3.toString()); }
public QueryRule createDisMaxQueryRuleForAttribute( Set<String> searchTerms, Collection<OntologyTerm> ontologyTerms) { List<String> queryTerms = new ArrayList<>(); if (searchTerms != null) { queryTerms.addAll( searchTerms.stream() .filter(StringUtils::isNotBlank) .map(this::processQueryString) .collect(Collectors.toList())); } ontologyTerms.stream() .filter(ontologyTerm -> !ontologyTerm.getIRI().contains(COMMA_CHAR)) .forEach(ot -> queryTerms.addAll(parseOntologyTermQueries(ot))); QueryRule disMaxQueryRule = createDisMaxQueryRuleForTerms(queryTerms); ontologyTerms.stream() .filter(ontologyTerm -> ontologyTerm.getIRI().contains(COMMA_CHAR)) .forEach(ot -> disMaxQueryRule.getNestedRules().add(createShouldQueryRule(ot.getIRI()))); return disMaxQueryRule; }
SemanticSearchServiceHelper { public QueryRule createDisMaxQueryRuleForAttribute( Set<String> searchTerms, Collection<OntologyTerm> ontologyTerms) { List<String> queryTerms = new ArrayList<>(); if (searchTerms != null) { queryTerms.addAll( searchTerms.stream() .filter(StringUtils::isNotBlank) .map(this::processQueryString) .collect(Collectors.toList())); } ontologyTerms.stream() .filter(ontologyTerm -> !ontologyTerm.getIRI().contains(COMMA_CHAR)) .forEach(ot -> queryTerms.addAll(parseOntologyTermQueries(ot))); QueryRule disMaxQueryRule = createDisMaxQueryRuleForTerms(queryTerms); ontologyTerms.stream() .filter(ontologyTerm -> ontologyTerm.getIRI().contains(COMMA_CHAR)) .forEach(ot -> disMaxQueryRule.getNestedRules().add(createShouldQueryRule(ot.getIRI()))); return disMaxQueryRule; } }
SemanticSearchServiceHelper { public QueryRule createDisMaxQueryRuleForAttribute( Set<String> searchTerms, Collection<OntologyTerm> ontologyTerms) { List<String> queryTerms = new ArrayList<>(); if (searchTerms != null) { queryTerms.addAll( searchTerms.stream() .filter(StringUtils::isNotBlank) .map(this::processQueryString) .collect(Collectors.toList())); } ontologyTerms.stream() .filter(ontologyTerm -> !ontologyTerm.getIRI().contains(COMMA_CHAR)) .forEach(ot -> queryTerms.addAll(parseOntologyTermQueries(ot))); QueryRule disMaxQueryRule = createDisMaxQueryRuleForTerms(queryTerms); ontologyTerms.stream() .filter(ontologyTerm -> ontologyTerm.getIRI().contains(COMMA_CHAR)) .forEach(ot -> disMaxQueryRule.getNestedRules().add(createShouldQueryRule(ot.getIRI()))); return disMaxQueryRule; } SemanticSearchServiceHelper(
      DataService dataService,
      OntologyService ontologyService,
      TermFrequencyService termFrequencyService); }
SemanticSearchServiceHelper { public QueryRule createDisMaxQueryRuleForAttribute( Set<String> searchTerms, Collection<OntologyTerm> ontologyTerms) { List<String> queryTerms = new ArrayList<>(); if (searchTerms != null) { queryTerms.addAll( searchTerms.stream() .filter(StringUtils::isNotBlank) .map(this::processQueryString) .collect(Collectors.toList())); } ontologyTerms.stream() .filter(ontologyTerm -> !ontologyTerm.getIRI().contains(COMMA_CHAR)) .forEach(ot -> queryTerms.addAll(parseOntologyTermQueries(ot))); QueryRule disMaxQueryRule = createDisMaxQueryRuleForTerms(queryTerms); ontologyTerms.stream() .filter(ontologyTerm -> ontologyTerm.getIRI().contains(COMMA_CHAR)) .forEach(ot -> disMaxQueryRule.getNestedRules().add(createShouldQueryRule(ot.getIRI()))); return disMaxQueryRule; } 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 createDisMaxQueryRuleForAttribute( Set<String> searchTerms, Collection<OntologyTerm> ontologyTerms) { List<String> queryTerms = new ArrayList<>(); if (searchTerms != null) { queryTerms.addAll( searchTerms.stream() .filter(StringUtils::isNotBlank) .map(this::processQueryString) .collect(Collectors.toList())); } ontologyTerms.stream() .filter(ontologyTerm -> !ontologyTerm.getIRI().contains(COMMA_CHAR)) .forEach(ot -> queryTerms.addAll(parseOntologyTermQueries(ot))); QueryRule disMaxQueryRule = createDisMaxQueryRuleForTerms(queryTerms); ontologyTerms.stream() .filter(ontologyTerm -> ontologyTerm.getIRI().contains(COMMA_CHAR)) .forEach(ot -> disMaxQueryRule.getNestedRules().add(createShouldQueryRule(ot.getIRI()))); return disMaxQueryRule; } 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; }