どうすればいいですか?サービスとしての大きなJavaプログラムとのやり取りは?
私がしたいことは、スタンフォードNLP ONCEを読み込んでから、HTTPまたは他のエンドポイント経由で対話することです。その理由は、ロードに時間がかかり、分析するすべての文字列の読み込みが問題にならないからです。
例えばは、ここにjarファイルをロードする簡単なC#プログラムでスタンフォードNLPの負荷である...私は以下のやったことをやって探していますが、Javaに:
Reading POS tagger model from edu/stanford/nlp/models/pos-tagger/english-left3words/english-left3words-distsim.tagger ... done [9.3 sec].
Loading classifier from D:\Repositories\StanfordNLPCoreNLP\stanford-corenlp-3.6.0-models\edu\stanford\nlp\models\ner\english.all.3class.distsim.crf.ser.gz ... done [12.8 sec].
Loading classifier from D:\Repositories\StanfordNLPCoreNLP\stanford-corenlp-3.6.0-models\edu\stanford\nlp\models\ner\english.muc.7class.distsim.crf.ser.gz ... done [5.9 sec].
Loading classifier from D:\Repositories\StanfordNLPCoreNLP\stanford-corenlp-3.6.0-models\edu\stanford\nlp\models\ner\english.conll.4class.distsim.crf.ser.gz ... done [4.1 sec].
done [8.8 sec].
Sentence #1 ...
これは30を超えています秒。これらのすべてが毎回読み込まなければならない場合は、yikes。私はJavaで何をしたいのかを示すために、私はC#での作業の例を書いて、この完全な例いつか誰かを助けるかもしれない:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using java.io;
using java.util;
using edu.stanford.nlp;
using edu.stanford.nlp.pipeline;
using Console = System.Console;
namespace NLPConsoleApplication
{
class Program
{
static void Main(string[] args)
{
// Path to the folder with models extracted from `stanford-corenlp-3.6.0-models.jar`
var jarRoot = @"..\..\..\..\StanfordNLPCoreNLP\stanford-corenlp-3.6.0-models";
// Text for intial run processing
var text = "Kosgi Santosh sent an email to Stanford University. He didn't get a reply.";
// Annotation pipeline configuration
var props = new Properties();
props.setProperty("annotators", "tokenize, ssplit, pos, lemma, ner, parse, sentiment");
props.setProperty("ner.useSUTime", "0");
// We should change current directory, so StanfordCoreNLP could find all the model files automatically
var curDir = Environment.CurrentDirectory;
Directory.SetCurrentDirectory(jarRoot);
var pipeline = new StanfordCoreNLP(props);
Directory.SetCurrentDirectory(curDir);
// loop
while (text != "quit")
{
// Annotation
var annotation = new Annotation(text);
pipeline.annotate(annotation);
// Result - Pretty Print
using (var stream = new ByteArrayOutputStream())
{
pipeline.prettyPrint(annotation, new PrintWriter(stream));
Console.WriteLine(stream.toString());
stream.close();
}
edu.stanford.nlp.trees.TreePrint tprint = new edu.stanford.nlp.trees.TreePrint("words");
Console.WriteLine();
Console.WriteLine("Enter a sentence to evaluate, and hit ENTER (enter \"quit\" to quit)");
text = Console.ReadLine();
} // end while
}
}
}
は、だから、ロードするために30秒かかりますが、それぞれの時間は、あなたがそれを与えますコンソール上の文字列では、最小文字数の文字列を&という文字列に変換します。
whileループの前にjarファイルをロードしたことがわかります。
これは、ソケットサービス、HTML、またはリクエストを(文字列の形で)受け入れ、解析を払い戻すことになるかもしれません。
私の最終的な目標は、従来のWebサーバーのスレッド化された例の場合(たとえば、30秒以上)、解析される文字列を送信できるプロセッサを使用してNifiでメカニズムを使用し、 ) 使用されている。すべてのリクエストが30秒間全体をロードし、その後はビジネスに落ち着きます。私はこれを明確にしたいと思う!
これを行う方法?
実際に質問されていません。 – chrylis
あなたの質問は何ですか? –
StandfordのNLPを活用するためにApache NiFiを使用する方法の方向性を探していると思います(これはWbeサービスフローのステップとして追加することができます)。あなたがC#に関わっている理由がありますか?Java NLPライブラリを使ってNiFiプロセッサを書くだけではありませんか? OnScheduleメソッドのすべてを初期化し、OnTrigger – JDP10101