diff options
Diffstat (limited to 'gi/posterior-regularisation/prjava/src')
3 files changed, 30 insertions, 9 deletions
diff --git a/gi/posterior-regularisation/prjava/src/hmm/HMM.java b/gi/posterior-regularisation/prjava/src/hmm/HMM.java index 1c4d7659..17a4679f 100644 --- a/gi/posterior-regularisation/prjava/src/hmm/HMM.java +++ b/gi/posterior-regularisation/prjava/src/hmm/HMM.java @@ -1,5 +1,8 @@ package hmm;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Scanner;
@@ -248,8 +251,8 @@ public class HMM { }
}
- public void writeModel(String modelFilename){
- PrintStream ps=io.FileUtil.openOutFile(modelFilename);
+ public void writeModel(String modelFilename) throws FileNotFoundException, IOException{
+ PrintStream ps=io.FileUtil.printstream(new File(modelFilename));
ps.println(trans.length);
ps.println("Initial Probabilities:");
for(int i=0;i<pi.length;i++){
diff --git a/gi/posterior-regularisation/prjava/src/hmm/POS.java b/gi/posterior-regularisation/prjava/src/hmm/POS.java index 2dcf271c..bdcbc683 100644 --- a/gi/posterior-regularisation/prjava/src/hmm/POS.java +++ b/gi/posterior-regularisation/prjava/src/hmm/POS.java @@ -1,5 +1,8 @@ package hmm;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
import java.io.PrintStream;
import java.util.HashMap;
@@ -23,11 +26,17 @@ public class POS { public static void main(String[] args) {
//POS p=new POS();
//POS p=new POS(true);
- PRPOS();
+ try {
+ PRPOS();
+ } catch (FileNotFoundException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
}
- public POS(){
+ public POS() throws FileNotFoundException, IOException{
Corpus c= new Corpus(trainFilename);
//size of vocabulary +1 for unknown tokens
HMM hmm =new HMM(N_STATE, c.getVocabSize()+1,c.getAllData());
@@ -43,7 +52,7 @@ public class POS { Corpus test=new Corpus(testFilename,c.vocab);
- PrintStream ps= io.FileUtil.openOutFile(predFilename);
+ PrintStream ps= io.FileUtil.printstream(new File(predFilename));
int [][]data=test.getAllData();
for(int i=0;i<data.length;i++){
@@ -58,7 +67,7 @@ public class POS { }
//POS induction with L1/Linf constraints
- public static void PRPOS(){
+ public static void PRPOS() throws FileNotFoundException, IOException{
Corpus c= new Corpus(trainFilename);
//size of vocabulary +1 for unknown tokens
HMM hmm =new HMM(N_STATE, c.getVocabSize()+1,c.getAllData());
@@ -75,7 +84,7 @@ public class POS { }
- public POS(boolean supervised){
+ public POS(boolean supervised) throws FileNotFoundException, IOException{
Corpus c= new Corpus(trainFilename);
//size of vocabulary +1 for unknown tokens
HMM hmm =new HMM(c.tagVocab.size() , c.getVocabSize()+1,c.getAllData());
@@ -95,7 +104,7 @@ public class POS { System.out.println(c.vocab.get("<e>"));
- PrintStream ps= io.FileUtil.openOutFile(predFilename);
+ PrintStream ps= io.FileUtil.printstream(new File(predFilename));
int [][]data=test.getAllData();
for(int i=0;i<data.length;i++){
diff --git a/gi/posterior-regularisation/prjava/src/test/HMMModelStats.java b/gi/posterior-regularisation/prjava/src/test/HMMModelStats.java index dbf517fd..d54525c8 100644 --- a/gi/posterior-regularisation/prjava/src/test/HMMModelStats.java +++ b/gi/posterior-regularisation/prjava/src/test/HMMModelStats.java @@ -3,6 +3,9 @@ package test; import hmm.HMM;
import hmm.POS;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Collections;
@@ -39,7 +42,13 @@ public class HMMModelStats { - PrintStream ps=io.FileUtil.openOutFile(statsFilename);
+ PrintStream ps = null;
+ try {
+ ps = io.FileUtil.printstream(new File(statsFilename));
+ } catch (IOException e) {
+ e.printStackTrace();
+ System.exit(1);
+ }
double [][] emit=hmm.getEmitProb();
for(int i=0;i<emit.length;i++){
|