I am using the Stanford POS-tagger application to tag some articles in about 300 files. To do this, I wrote a C# code that will go through the files and use the tagger.
My code looks like this:
Process thisProcess=new Process();
thisProcess.StartInfo.CreateNoWindow=true;
thisProcess.StartInfo.WindowStyle=ProcessWindowStyle.Hidden;
thisProcess.StartInfo.WorkingDirectory=@"C:\postagger";
thisProcess.StartInfo.FileName=@"C:\postagger\stanford-postagger.bat";
thisProcess.StartInfo.UseShellExecute=false;
thisProcess.StartInfo.RedirectStandardOutput=true;
if(Directory.Exists(@"C:\brown2")) {
DirectoryInfo brown=new DirectoryInfo(@"C:\brown2");
DirectoryInfo brownParsed;
if(!Directory.Exists(@"C:\brown-parsed"))
brownParsed=Directory.CreateDirectory(@"C:\brown-parsed");
else
brownParsed=new DirectoryInfo(@"C:\brown-parsed");
FileInfo[] files=brown.GetFiles();
foreach(FileInfo f in files) {
Console.WriteLine("Parsing file "+f.Name+" ...");
thisProcess.StartInfo.Arguments=@"C:\postagger\models\wsj-0-18-bidirectional-distsim.tagger "+f.FullName;
//Console.WriteLine(thisProcess.StartInfo.Arguments);
thisProcess.Start();
thisProcess.WaitForExit();
//Console.Read();
StreamWriter sw=new StreamWriter(Path.Combine(brownParsed.FullName, f.Name), false);
string output=thisProcess.StandardOutput.ReadToEnd();
//sw.Write(thisProcess.StandardOutput.ReadToEnd());
sw.Write(output);
sw.Flush();
sw.Close();
//Console.WriteLine("File {0} done!",f.Name);
Console.WriteLine(output);
}
}
else
Console.WriteLine("Dir not found!");
Console.Read();
And the stanford-postagger.bat looks like this:
usage: stanford-postagger model textFile e.g., stanford-postagger models\left3words-wsj-0-18.tagger sample-input.txt
java -mx300m -cp "stanford-postagger.jar;" edu.stanford.nlp.tagger.maxent.MaxentTagger -model %1 -textFile %2
The problem is:
The code runs it, but it will NOT run the java command. I tried it on my laptop, and it works like a charm, it tags. But it won't tag large files due to not enough memory. But on my PC, which is more powerfull, it will not run the java.
If I open the CMD and enter that java command with the right parameters for a file, it works. Any ideea of what may cause it not to work? All the paths are good, I triple checked them.
Here is an example of output I get from the non-working program(on my PC):
C:\postagger>java -mx300m -cp "stanford-postagger.jar;" edu.stanford.nlp.tagger.maxent.MaxentTagger -model C:\postagger\models\wsj-0-18-bidirectional-distsim.tagger -textFile C:\brown2\aaa.txt