Beispiel #1
0
  void saveItemset(Itemset itemset) throws IOException {
    itemsetCount++;

    // if the result should be saved to a file
    if (writer != null) {
      writer.write(itemset.toString() + " #SUP: " + itemset.getAbsoluteSupport());
      writer.newLine();
    } // otherwise the result is kept into memory
    else {
      patterns.addItemset(itemset, itemset.size());
    }
  }
Beispiel #2
0
  void saveItemsetToFile(Integer item, Integer support) throws IOException {
    itemsetCount++;

    // if the result should be saved to a file
    if (writer != null) {
      writer.write(item + " #SUP: " + support);
      writer.newLine();
    } // otherwise the result is kept into memory
    else {
      Itemset itemset = new Itemset(item);
      itemset.setAbsoluteSupport(support);
      patterns.addItemset(itemset, 1);
    }
  }
  /**
   * Write a frequent itemset that is found to the output file or keep into memory if the user
   * prefer that the result be saved into memory.
   */
  private void saveItemset(int[] itemset, int itemsetLength, int support) throws IOException {

    // increase the number of itemsets found for statistics purpose
    itemsetCount++;

    // if the result should be saved to a file
    if (writer != null) {
      // copy the itemset in the output buffer and sort items
      System.arraycopy(itemset, 0, itemsetOutputBuffer, 0, itemsetLength);
      Arrays.sort(itemsetOutputBuffer, 0, itemsetLength);

      // Create a string buffer
      StringBuilder buffer = new StringBuilder();
      // write the items of the itemset
      for (int i = 0; i < itemsetLength; i++) {
        buffer.append(itemsetOutputBuffer[i]);
        if (i != itemsetLength - 1) {
          buffer.append(' ');
        }
      }
      // Then, write the support
      buffer.append(" #SUP: ");
      buffer.append(support);
      // write to file and create a new line
      writer.write(buffer.toString());
      writer.newLine();
    } // otherwise the result is kept into memory
    else {
      // create an object Itemset and add it to the set of patterns
      // found.
      int[] itemsetArray = new int[itemsetLength];
      System.arraycopy(itemset, 0, itemsetArray, 0, itemsetLength);

      // sort the itemset so that it is sorted according to lexical ordering before we show it to
      // the user
      Arrays.sort(itemsetArray);

      Itemset itemsetObj = new Itemset(itemsetArray);
      itemsetObj.setAbsoluteSupport(support);
      patterns.addItemset(itemsetObj, itemsetLength);
    }
  }