<commit_before>package de.lmu.ifi.dbs.algorithm.result;

import de.lmu.ifi.dbs.data.DatabaseObject;
import de.lmu.ifi.dbs.database.Database;
import de.lmu.ifi.dbs.normalization.Normalization;
import de.lmu.ifi.dbs.utilities.UnableToComplyException;
import de.lmu.ifi.dbs.utilities.optionhandling.AttributeSettings;

import java.io.File;
import java.io.FileDescriptor;
import java.io.FileOutputStream;
import java.io.PrintStream;
import java.util.List;

/**
 * Abstract super class for a result object. Encapsulates methods common for
 * many result objects.
 * 
 * @author <NAME> (<a
 *         href="mailto:<EMAIL>"><EMAIL></a>)
 */
public abstract class AbstractResult<O extends DatabaseObject> implements
        Result<O>
{
    /**
     * Extension for txt-files.
     */
    public static final String FILE_EXTENSION = ".txt";

    /**
     * The database containing the objects of this result.
     */
    protected Database<O> db;

    /**
     * Creates a new abstract result object.
     * 
     * @param db
     *            the database containing the objects of this result
     */
    protected AbstractResult(Database<O> db)
    {
        this.db = db;
    }

    /**
     * Writes a header providing information concerning the underlying database
     * and the specified parameter-settings.
     * 
     * @param out
     *            the print stream where to write
     * @param settings
     *            the settings to be written into the header
     * @param headerInformation
     *            additional information to be printed in the header, each entry
     *            will be printed in one separate line
     */
    protected void writeHeader(PrintStream out,
            List<AttributeSettings> settings, List<String> headerInformation)
    {
        if (settings == null && headerInformation == null)
            return;
        out
                .println("################################################################################");
        out.println("### db size = " + db.size());
        // noinspection EmptyCatchBlock
        try
        {
            int dimensionality = db.dimensionality();
            out.println("### db dimensionality = " + dimensionality);
        } catch (UnsupportedOperationException e)
        {
            // dimensionality is unsupported - do nothing
        }
        if (headerInformation != null)
        {
            for (String s : headerInformation)
            {
                out.println("### " + s);
            }
        }
        out.println("###");

        for (AttributeSettings setting : settings)
        {
            if (!setting.getSettings().isEmpty())
            {
                out.println(setting.toString("### "));
                out.println("###");
            }
        }

        out
                .println("################################################################################");
    }

    /**
     * @see Result#output(File, Normalization, List)
     */
    public void output(File out, Normalization<O> normalization,
            List<AttributeSettings> settings) throws UnableToComplyException
    {
        PrintStream outStream;
        try
        {
            outStream = new PrintStream(new FileOutputStream(out));
        } catch (Exception e)
        {
            outStream = new PrintStream(
                    new FileOutputStream(FileDescriptor.out));
        }
        output(outStream, normalization, settings);
    }

    /**
     * Returns the database to which this clustering result belongs to.
     * 
     * @return the database to which this clustering result belongs to
     */
    public Database<O> getDatabase()
    {
        return db;
    }
}
<commit_msg>comments<commit_after>package de.lmu.ifi.dbs.algorithm.result;

import de.lmu.ifi.dbs.data.DatabaseObject;
import de.lmu.ifi.dbs.database.Database;
import de.lmu.ifi.dbs.normalization.Normalization;
import de.lmu.ifi.dbs.utilities.UnableToComplyException;
import de.lmu.ifi.dbs.utilities.optionhandling.AttributeSettings;

import java.io.File;
import java.io.FileDescriptor;
import java.io.FileOutputStream;
import java.io.PrintStream;
import java.util.List;

/**
 * Abstract super class for a result object. Encapsulates methods common for
 * many result objects.
 *
 * @author <NAME> (<a
 *         href="mailto:<EMAIL>"><EMAIL></a>)
 */
public abstract class AbstractResult<O extends DatabaseObject> implements
                                                               Result<O> {
  /**
   * Extension for txt-files.
   */
  public static final String FILE_EXTENSION = ".txt";

  /**
   * The database containing the objects of this result.
   */
  protected Database<O> db;

  /**
   * Creates a new abstract result object.
   *
   * @param db the database containing the objects of this result
   */
  protected AbstractResult(Database<O> db) {
    this.db = db;
  }

  /**
   * Writes a header providing information concerning the underlying database
   * and the specified parameter-settings.
   *
   * @param out               the print stream where to write
   * @param settings          the settings to be written into the header
   * @param headerInformation additional information to be printed in the header, each entry
   *                          will be printed in one separate line
   */
  protected void writeHeader(PrintStream out,
                             List<AttributeSettings> settings, List<String> headerInformation) {
    if (settings == null && headerInformation == null)
      return;
    out.println("################################################################################");
    out.println("### db size = " + db.size());
    // noinspection EmptyCatchBlock
    try {
      int dimensionality = db.dimensionality();
      out.println("### db dimensionality = " + dimensionality);
    }
    catch (UnsupportedOperationException e) {
      // dimensionality is unsupported - do nothing
    }
    if (headerInformation != null) {
      for (String s : headerInformation) {
        out.println("### " + s);
      }
    }
    out.println("###");

    for (AttributeSettings setting : settings) {
      if (!setting.getSettings().isEmpty()) {
        out.println(setting.toString("### "));
        out.println("###");
      }
    }

    out.println("################################################################################");
  }

  /**
   * @see Result#output(File, Normalization, List)
   */
  public void output(File out, Normalization<O> normalization,
                     List<AttributeSettings> settings) throws UnableToComplyException {
    PrintStream outStream;
    try {
      outStream = new PrintStream(new FileOutputStream(out));
    }
    catch (Exception e) {
      outStream = new PrintStream(
      new FileOutputStream(FileDescriptor.out));
    }
    output(outStream, normalization, settings);
  }

  /**
   * Returns the database to which this clustering result belongs to.
   *
   * @return the database to which this clustering result belongs to
   */
  public Database<O> getDatabase() {
    return db;
  }
}

{'fraction_non_alphanumeric': 0.14537258768840683, 'fraction_numerical': 0.0, 'mean_word_length': 2.398755385351843, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1367979', 'n_tokens_mistral': 1846, 'n_tokens_neox': 1792, 'n_words': 506}