/** Tests the method {@link org.apache.calcite.util.BitSets#closure(java.util.SortedMap)}. */
  @Test
  public void testClosure() {
    final SortedMap<Integer, ImmutableBitSet> empty = Maps.newTreeMap();
    assertThat(ImmutableBitSet.closure(empty), equalTo(empty));

    // Currently you need an entry for each position, otherwise you get an NPE.
    // We should fix that.
    final SortedMap<Integer, ImmutableBitSet> map = Maps.newTreeMap();
    map.put(0, ImmutableBitSet.of(3));
    map.put(1, ImmutableBitSet.of());
    map.put(2, ImmutableBitSet.of(7));
    map.put(3, ImmutableBitSet.of(4, 12));
    map.put(4, ImmutableBitSet.of());
    map.put(5, ImmutableBitSet.of());
    map.put(6, ImmutableBitSet.of());
    map.put(7, ImmutableBitSet.of());
    map.put(8, ImmutableBitSet.of());
    map.put(9, ImmutableBitSet.of());
    map.put(10, ImmutableBitSet.of());
    map.put(11, ImmutableBitSet.of());
    map.put(12, ImmutableBitSet.of());
    final String original = map.toString();
    final String expected =
        "{0={3, 4, 12}, 1={}, 2={7}, 3={3, 4, 12}, 4={4, 12}, 5={}, 6={}, 7={7}, 8={}, 9={}, 10={}, 11={}, 12={4, 12}}";
    assertThat(ImmutableBitSet.closure(map).toString(), equalTo(expected));
    assertThat("argument modified", map.toString(), equalTo(original));

    // Now a similar map with missing entries. Same result.
    final SortedMap<Integer, ImmutableBitSet> map2 = Maps.newTreeMap();
    map2.put(0, ImmutableBitSet.of(3));
    map2.put(2, ImmutableBitSet.of(7));
    map2.put(3, ImmutableBitSet.of(4, 12));
    map2.put(9, ImmutableBitSet.of());
    final String original2 = map2.toString();
    assertThat(ImmutableBitSet.closure(map2).toString(), equalTo(expected));
    assertThat("argument modified", map2.toString(), equalTo(original2));
  }
Beispiel #2
0
  /** show some statistics at the end of the collector process */
  public void showStatistics() {
    // TODO nur fuer mich die folgenden stats...haben in eval
    // erstmal! nix verloren
    String stat = "";
    if (!model.isEvaluating()) {
      stat += "\n****************************** START STATS ******************************\n";
      stat += "!ALL! DETECTED NOTES AND THEIR LENGTHS IN ms: (just for stats)\n";
      stat += midiKeySammlerInsgesamt.toString() + "\n\n";

      stat += "AbcNotes-Backup: \n" + notesAsString + "\n";

      stat += "YIN/MPM - STATS:\n";
      float sum = yin_cnt + mpm_cnt;
      stat += "YIN: " + yin_cnt / sum * 100 + "% - MPM: " + mpm_cnt / sum * 100 + "%\n";
      stat += "****************************** END STATS ******************************\n\n";
      jAM.log(stat, false);
    } else evaluator.evaluateCurrentTranscription(evaluationSammler, PITCHDETECTOR, notesAsString);
  }
  private IntegerCounter internal_check_species_presence_in_sbml_models(
      String outputFilename, String modelsContainingDirectory, boolean recursively) {

    final SortedMap<String, Integer> countBySpecies = new TreeMap<String, Integer>();

    final IntegerCounter analyzedModels = new IntegerCounter();

    DotUtilAction<File> action =
        new DotUtilAction<File>() {

          @Override
          public void apply(File element) {

            Model model = null;
            SBMLDocument document = null;

            try {
              document = (new SBMLReader()).readSBML(element);
            } catch (FileNotFoundException e) {
            } catch (XMLStreamException e) {
            } catch (Exception e) {
            }

            if (document != null) {

              analyzedModels.increment();

              model = document.getModel();

              for (Species species : model.getListOfSpecies()) {

                String id =
                    (species.getId()
                            + "-("
                            + species.getName()
                            + ")"
                            + "-("
                            + species.getCompartment()
                            + ")")
                        .toUpperCase(new Locale("(all)"));

                if (countBySpecies.containsKey(id)) {
                  int value = countBySpecies.get(id);
                  countBySpecies.remove(id);
                  countBySpecies.put(id, value + 1);
                } else {
                  countBySpecies.put(id, 1);
                }
              }
            }
          }
        };

    DotFileUtilHandler.mapOnAllFilesInFolder(modelsContainingDirectory, action, recursively);

    // now we can generate the output file
    Writer writer;
    try {
      writer =
          new FileWriter(
              DotFileUtilHandler.dotOutputFolderPathName()
                  .concat(outputFilename)
                  .concat(DotFileUtilHandler.getPlainTextFilenameExtensionToken()));

      writer.write(countBySpecies.toString());

      writer.close();
    } catch (IOException e) {
      e.printStackTrace();
    }

    return analyzedModels;
  }
  public void check_model_presence_in_various_sbml_models_contained_in_BioCyc_folder() {

    final SortedMap<String, IntegerCounter> count_by_models = new TreeMap<String, IntegerCounter>();

    DotUtilAction<File> action =
        new DotUtilAction<File>() {

          @Override
          public void apply(File element) {

            Model model = null;
            SBMLDocument document = null;

            try {
              document = (new SBMLReader()).readSBML(element);
            } catch (FileNotFoundException e) {
            } catch (XMLStreamException e) {
            } catch (Exception e) {
            }

            if (document != null) {

              model = document.getModel();

              String model_name = model.getName();

              if (model_name == null) {
                Assert.fail("Impossible to have a model without a name");
              }

              if (count_by_models.containsKey(model_name) == false) {
                count_by_models.put(model_name, new IntegerCounter());
              }
              count_by_models.get(model_name).increment();
            }
          }
        };

    DotFileUtilHandler.mapOnAllFilesInFolder(
        DotFileUtilHandler.getSbmlExampleModelsFolder().concat("BioCyc15.0/"), action, true);

    // now we can generate the output file
    Writer writer;
    try {
      writer =
          new FileWriter(
              DotFileUtilHandler.dotOutputFolderPathName()
                  .concat("maps-of-models-presence-among-multiple-models-in-ByoCyc-folder")
                  .concat(DotFileUtilHandler.getPlainTextFilenameExtensionToken()));

      writer.write(count_by_models.toString());

      writer.close();
    } catch (IOException e) {
      e.printStackTrace();
    }

    Assert.assertEquals(92, count_by_models.size());

    int exploded_count = 0;
    int models_splitted_in_more_than_three_files = 0;
    for (Entry<String, IntegerCounter> entry : count_by_models.entrySet()) {
      exploded_count = exploded_count + entry.getValue().getCount();

      if (entry.getValue().getCount() > 2) {
        models_splitted_in_more_than_three_files = models_splitted_in_more_than_three_files + 1;
      }
    }

    Assert.assertEquals(167, exploded_count);
    Assert.assertTrue(models_splitted_in_more_than_three_files > 1);
  }