From fa43e7b4c2e0572cefe8c2b5389bfdcd0892c792 Mon Sep 17 00:00:00 2001 From: mihaiiancu Date: Mon, 13 Mar 2017 19:05:43 -0400 Subject: [PATCH 1/3] Fixed flush buffer bug for hlda output file state --- src/cc/mallet/topics/HierarchicalLDA.java | 3 ++- src/cc/mallet/topics/tui/HierarchicalLDATUI.java | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/cc/mallet/topics/HierarchicalLDA.java b/src/cc/mallet/topics/HierarchicalLDA.java index feac0c02a..c6100a6fa 100644 --- a/src/cc/mallet/topics/HierarchicalLDA.java +++ b/src/cc/mallet/topics/HierarchicalLDA.java @@ -428,7 +428,7 @@ public void printState() throws IOException, FileNotFoundException { /** * Write a text file describing the current sampling state. */ - public void printState(PrintWriter out) throws IOException { + protected void printState(PrintWriter out) throws IOException { int doc = 0; Alphabet alphabet = instances.getDataAlphabet(); @@ -459,6 +459,7 @@ public void printState(PrintWriter out) throws IOException { doc++; } + out.close(); } public void printNodes() { diff --git a/src/cc/mallet/topics/tui/HierarchicalLDATUI.java b/src/cc/mallet/topics/tui/HierarchicalLDATUI.java index f5f187384..34a7cb3c8 100644 --- a/src/cc/mallet/topics/tui/HierarchicalLDATUI.java +++ b/src/cc/mallet/topics/tui/HierarchicalLDATUI.java @@ -111,7 +111,7 @@ public static void main (String[] args) throws java.io.IOException { // Output results if (stateFile.value() != null) { - hlda.printState(new PrintWriter(stateFile.value())); + hlda.printState(); } if (testing != null) { From 1900e2f41a30f8a6dfff40850cf5b1c061f977cc Mon Sep 17 00:00:00 2001 From: mihaiiancu Date: Mon, 13 Mar 2017 19:05:43 -0400 Subject: [PATCH 2/3] Fixed flush buffer bug for hlda output file state --- src/cc/mallet/topics/HierarchicalLDA.java | 3 ++- src/cc/mallet/topics/tui/HierarchicalLDATUI.java | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/cc/mallet/topics/HierarchicalLDA.java b/src/cc/mallet/topics/HierarchicalLDA.java index 6fe0d71f9..a7b803b11 100644 --- a/src/cc/mallet/topics/HierarchicalLDA.java +++ b/src/cc/mallet/topics/HierarchicalLDA.java @@ -428,7 +428,7 @@ public void printState() throws IOException, FileNotFoundException { /** * Write a text file describing the current sampling state. */ - public void printState(PrintWriter out) throws IOException { + protected void printState(PrintWriter out) throws IOException { int doc = 0; Alphabet alphabet = instances.getDataAlphabet(); @@ -459,6 +459,7 @@ public void printState(PrintWriter out) throws IOException { doc++; } + out.close(); } public void printNodes() { diff --git a/src/cc/mallet/topics/tui/HierarchicalLDATUI.java b/src/cc/mallet/topics/tui/HierarchicalLDATUI.java index f5f187384..34a7cb3c8 100644 --- a/src/cc/mallet/topics/tui/HierarchicalLDATUI.java +++ b/src/cc/mallet/topics/tui/HierarchicalLDATUI.java @@ -111,7 +111,7 @@ public static void main (String[] args) throws java.io.IOException { // Output results if (stateFile.value() != null) { - hlda.printState(new PrintWriter(stateFile.value())); + hlda.printState(); } if (testing != null) { From 95fee66d5d2b05f59a50e82994a67120c9e80537 Mon Sep 17 00:00:00 2001 From: mihaiiancu Date: Wed, 15 Mar 2017 18:50:41 -0400 Subject: [PATCH 3/3] better to not change the API for existing users --- src/cc/mallet/topics/HierarchicalLDA.java | 2 +- src/cc/mallet/topics/tui/HierarchicalLDATUI.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/mallet/topics/HierarchicalLDA.java b/src/cc/mallet/topics/HierarchicalLDA.java index a7b803b11..373815c89 100644 --- a/src/cc/mallet/topics/HierarchicalLDA.java +++ b/src/cc/mallet/topics/HierarchicalLDA.java @@ -428,7 +428,7 @@ public void printState() throws IOException, FileNotFoundException { /** * Write a text file describing the current sampling state. */ - protected void printState(PrintWriter out) throws IOException { + public void printState(PrintWriter out) throws IOException { int doc = 0; Alphabet alphabet = instances.getDataAlphabet(); diff --git a/src/cc/mallet/topics/tui/HierarchicalLDATUI.java b/src/cc/mallet/topics/tui/HierarchicalLDATUI.java index 34a7cb3c8..2e37cc630 100644 --- a/src/cc/mallet/topics/tui/HierarchicalLDATUI.java +++ b/src/cc/mallet/topics/tui/HierarchicalLDATUI.java @@ -111,7 +111,7 @@ public static void main (String[] args) throws java.io.IOException { // Output results if (stateFile.value() != null) { - hlda.printState(); + hlda.printState(new PrintWriter(new BufferedWriter(new FileWriter(stateFile.value())))); } if (testing != null) {