0

Stanford POS-tagger アプリケーションを使用して、約 300 ファイルの記事にタグを付けています。これを行うために、ファイルを調べてタガーを使用する C# コードを作成しました。

私のコードは次のようになります。

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();

stanford-postagger.bat は次のようになります。

使用法: stanford-postagger model textFile 例: stanford-postagger models\left3words-wsj-0-18.tagger sample-input.txt

java -mx300m -cp "stanford-postagger.jar;" edu.stanford.nlp.tagger.maxent.MaxentTagger -モデル %1 -textFile %2

問題は:

コードはそれを実行しますが、java コマンドは実行しません。ラップトップで試してみたところ、魅力的に機能し、タグ付けされます。ただし、メモリが不足しているため、大きなファイルにはタグ付けできません。しかし、より強力な私の PC では、Java は実行されません。

CMD を開いて、ファイルの正しいパラメーターを指定してその Java コマンドを入力すると、機能します。それが機能しない原因について何か考えはありますか? すべてのパスは良好です。トリプルチェックしました。

これは、動作していないプログラム (PC 上) から取得した出力の例です。

C:\postagger>java -mx300m -cp "stanford-postagger.jar;" edu.stanford.nlp.tagger.maxent.MaxentTagger -モデル C:\postagger\models\wsj-0-18-bidirectional-distim.tagger -textFile C:\brown2\aaa.txt

4

1 に答える 1

0

これを使用してバッチファイルを実行することについて100%確信があるわけではありませんが、おそらく Process を使用して実行しますか?

var process = new Process
        {
            StartInfo = new ProcessStartInfo
            {
                FileName = "path-to-file.bat"
            }
        };
        process.Start();
        process.WaitForExit();
于 2013-03-27T20:43:56.957 に答える