I just implemented a program that uses the Stanford POS tagger in Java.
I used an input file of a few KB in size, consisting of a few hundred words. I even set the heap size to 600 MB.
But it is still slow and sometimes runs out of heap memory. How can I increase its execution speed and memory performance? I would like to be able to use a few MB as input.
public static void postag(String args) throws ClassNotFoundException
{
try
{
File filein=new File("c://input.txt");
String content = FileUtils.readFileToString(filein);
MaxentTagger tagger = new MaxentTagger("postagging/wsj-0-18-bidirectional-distsim.tagger");
String tagged = tagger.tagString(content);
try
{
File file = new File("c://output.txt");
if (!file.exists())
{
file.createNewFile();
}
FileWriter fw = new FileWriter(file.getAbsoluteFile());
BufferedWriter bw = new BufferedWriter(fw);
bw.write("\n"+tagged);
bw.close();
}
catch (IOException e)
{
e.printStackTrace();
}
} catch (IOException e1)
{
e1.printStackTrace();
}
}