All Downloads are FREE. Search and download functionalities are using the official Maven repository.

it.tidalwave.bluebill.taxonomy.TaxonomyComparator Maven / Gradle / Ivy

There is a newer version: 1.0.18
Show newest version
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package it.tidalwave.bluebill.taxonomy;

import it.tidalwave.bluebill.taxonomy.Taxonomy;
import it.tidalwave.bluebill.taxonomy.TaxonomyConcept;
import it.tidalwave.bluebill.taxonomy.TaxonomyVisitController;
import it.tidalwave.bluebill.taxonomy.TaxonomyVisitorAdapter;
import javax.annotation.Nonnull;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import it.tidalwave.bluebill.taxonomy.TaxonDifferenceSet;

/**
 *
 * @author fritz
 */
public class TaxonomyComparator
  {
    private final List differenceList = new ArrayList();
    
    public TaxonomyComparator (@Nonnull final Taxonomy taxonomy,
                               @Nonnull final Taxonomy otherTaxonomy)
      {
        final TaxonomyVisitController visitController = new TaxonomyVisitController(taxonomy);
        visitController.visit(new TaxonomyVisitorAdapter()
          {
            @Override
            public void visit (@Nonnull final TaxonomyConcept concept)
              {
                // FIXME: drop cast, use Set
                final Collection synonyms = (Collection)concept.getSynonyms();

                if (synonyms.isEmpty())
                  {
                    // TODO: missing counterpart
                  }
                else if (synonyms.size() == 1)
                  {
                    final TaxonDifferenceSet taxonDifferenceSet = new TaxonDifferenceSet(concept, synonyms.iterator().next());

                    if (!taxonDifferenceSet.isEmpty())
                      {
                        differenceList.add(taxonDifferenceSet);
                      }
                  }
                else // FIXME: indeed you should only retain the one of the target taxonomy
                  {
                      System.err.println("WARNING Synonym count > 1 for " + concept.getDisplayName());
//                    throw new RuntimeException("Synonym count > 1: " + synonyms);
                  }
              }
          });
      }

    @Override
    public String toString()
      {
        final StringBuilder buffer = new StringBuilder();

        for (final TaxonDifferenceSet taxonDifference : differenceList)
          {
            buffer.append(taxonDifference.toString()).append("\n");
          }

        return buffer.toString();
      }
  }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy