class LocalOntology implements Ontology {

  @Override
  public Iterator synonyms(String queryKeyPhrase) {

    Map<?, ?> classMap = retrieve(queryKeyPhrase);

    Map<Object, Object> synonyms = new HashMap<>();

    Iterator<?> iter = classMap.keySet().iterator();
    while (iter.hasNext()) {
      OntResource resource = (OntResource) iter.next();

      //listLabels
      for (Iterator<?> i = resource.listLabels(null); i.hasNext();) {
        Literal l = (Literal) i.next();
        synonyms.put(l.toString(), "1");
      }

      if (resource instanceof Individual) {
        //get all individuals same as this one
        for (Iterator<?> i = resource.listSameAs(); i.hasNext();) {
          Individual individual = (Individual) i.next();
          //add labels
          for (Iterator<?> j = individual.listLabels(null); j.hasNext();) {
            Literal l = (Literal) i.next();
            synonyms.put(l.toString(), "1");
          }
        }
      } else if (resource instanceof OntClass) {
        //list equivalent classes
        for (Iterator<?> i = ((OntClass) resource).listEquivalentClasses(); i.hasNext();) {
          OntClass equivClass = (OntClass) i.next();
          //add labels
          for (Iterator<?> j = equivClass.listLabels(null); j.hasNext();) {
            Literal l = (Literal) j.next();
            synonyms.put(l.toString(), "1");
          }
        }
      }
    }

    return synonyms.keySet().iterator();
  }

  public  LocalOntology();

}