/**
  * Create a boolean should query for composite tags containing multiple ontology terms
  *
  * @param multiOntologyTermIri
  * @return return a boolean should queryRule
  */
 public QueryRule createShouldQueryRule(String multiOntologyTermIri) {
   QueryRule shouldQueryRule = new QueryRule(new ArrayList<QueryRule>());
   shouldQueryRule.setOperator(Operator.SHOULD);
   for (String ontologyTermIri : multiOntologyTermIri.split(",")) {
     OntologyTerm ontologyTerm = ontologyService.getOntologyTerm(ontologyTermIri);
     List<String> queryTerms = parseOntologyTermQueries(ontologyTerm);
     Double termFrequency = termFrequencyService.getTermFrequency(ontologyTerm.getLabel());
     shouldQueryRule
         .getNestedRules()
         .add(createDisMaxQueryRuleForTermsWithBoost(queryTerms, termFrequency));
   }
   return shouldQueryRule;
 }
  @BeforeTest
  public void beforeTest() {
    ontologies = asList("1", "2");
    standingHeight =
        OntologyTerm.create(
            "http://onto/height", "Standing height", Arrays.asList("Standing height", "length"));
    bodyWeight =
        OntologyTerm.create(
            "http://onto/bmi", "Body weight", Arrays.asList("Body weight", "Mass in kilograms"));

    hypertension = OntologyTerm.create("http://onto/hyp", "Hypertension");
    maternalHypertension = OntologyTerm.create("http://onto/mhyp", "Maternal hypertension");
    ontologyTerms = asList(standingHeight, bodyWeight, hypertension, maternalHypertension);
    attribute = new DefaultAttributeMetaData("attr1");
  }
  public void collectOntologyTermQueryMap(
      Map<String, String> expanedQueryMap, OntologyTerm ontologyTerm) {
    if (ontologyTerm != null) {
      getOtLabelAndSynonyms(ontologyTerm)
          .forEach(
              term -> expanedQueryMap.put(stemmer.cleanStemPhrase(term), ontologyTerm.getLabel()));

      for (OntologyTerm childOntologyTerm : ontologyService.getChildren(ontologyTerm)) {
        getOtLabelAndSynonyms(childOntologyTerm)
            .forEach(
                term ->
                    expanedQueryMap.put(stemmer.cleanStemPhrase(term), ontologyTerm.getLabel()));
      }
    }
  }
  public Map<String, String> collectExpandedQueryMap(
      Set<String> queryTerms, Collection<OntologyTerm> ontologyTerms) {
    Map<String, String> expandedQueryMap = new LinkedHashMap<String, String>();

    queryTerms
        .stream()
        .filter(StringUtils::isNotBlank)
        .forEach(queryTerm -> expandedQueryMap.put(stemmer.cleanStemPhrase(queryTerm), queryTerm));

    for (OntologyTerm ontologyTerm : ontologyTerms) {
      if (!ontologyTerm.getIRI().contains(",")) {
        collectOntologyTermQueryMap(expandedQueryMap, ontologyTerm);
      } else {
        for (String ontologyTermIri : ontologyTerm.getIRI().split(",")) {
          collectOntologyTermQueryMap(
              expandedQueryMap, ontologyService.getOntologyTerm(ontologyTermIri));
        }
      }
    }
    return expandedQueryMap;
  }
 /**
  * A helper function to collect synonyms as well as label of ontologyterm
  *
  * @param ontologyTerm
  * @return a list of synonyms plus label
  */
 public Set<String> getOtLabelAndSynonyms(OntologyTerm ontologyTerm) {
   Set<String> allTerms = Sets.newLinkedHashSet(ontologyTerm.getSynonyms());
   allTerms.add(ontologyTerm.getLabel());
   return allTerms;
 }