0

私は Java が初めてで、GATE JAVA API を使用して Eclipse から保存したパイプラインを呼び出したいと考えています。新しいドキュメントの作成方法などは知っていますが、これを行う方法がわかりません。

FeatureMap params = Factory.newFeatureMap();
params.put(Document.DOCUMENT_URL_PARAMETER_NAME, new URL("http://www.gate.ac.uk"));
params.put(Document.DOCUMENT_ENCODING_PARAMETER_NAME, "UTF-8");

// document features
FeatureMap feats = Factory.newFeatureMap();
feats.put("date", new Date());
Factory.createResource("gate.corpora.DocumentImpl", params, feats, "This is home");

//End Solution 2
// obtain a map of all named annotation sets
Document doc = Factory.newDocument("Document text");
Map <String, AnnotationSet> namedASes = doc.getNamedAnnotationSets();
System.out.println("No. of named Annotation Sets:" + namedASes.size());

// no of annotations each set contains
for (String setName : namedASes.keySet()) {
// annotation set
AnnotationSet aSet = namedASes.get(setName);
// no of annotations
System.out.println("No. of Annotations for " +setName + ":" + aSet.size());
4

2 に答える 2

0

Java からの GATE 使用の良い例があります。おそらく、それはあなたが望むものを正確に実行します。BatchProcessApp.java . 特に、パイプラインのロードは行で行われます

// load the saved application
CorpusController application =
  (CorpusController)PersistenceManager.loadObjectFromFile(gappFile);

で実行されるpipeli

// run the application
  application.execute();

コードは有益で明確で、特定のニーズに合わせて簡単に変更できます。オープンソースプロジェクトの酸素:)

于 2014-04-07T14:56:41.380 に答える
0

このようなものを使用できます(GATEを初期化することを忘れないでください:GATEをホームに設定するなど):

private void getProcessedText(String textToProcess) {
    Document gateDocument = null;
    try {
      // you can use your method from above to build document
        gateDocument = createGATEDocument(textToProcess);
        corpusController.getCorpus().add(gateDocument);
        corpusController.execute();
       // put here your annotations processing 
    } catch (Throwable ex) {
        ex.printStackTrace();
    } finally {
        if (corpusController.getCorpus() != null) {
            corpusController.getCorpus().remove(gateDocument);
        }
        if (gateDocument != null) {
            Factory.deleteResource(gateDocument);
        }
    }
}

private CorpusController initPersistentGateResources() {
    try {
        Corpus corpus = Factory.newCorpus("New Corpus");
        corpusController = (CorpusController) PersistenceManager.loadObjectFromFile(new File("PATH-TO-YOUR-GAPP-FILE"));
        corpusController.setCorpus(corpus);
    } catch (Exception ex) {
        ex.printStackTrace();
    }
       return corpusController;
}
于 2014-04-08T06:27:42.010 に答える