2014-04-07 13 views
0

我是新來的Java,我想通過Eclipse的 調用使用GATE JAVA API我保存的管道,我不知道我怎麼能做到這一點,雖然我知道如何創建新的文檔等調用現有的管道在GATE

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

回答

0

java有一個很好的GATE用法的例子。可能它確實是你想要的。 BatchProcessApp.java。 特別是: 裝載管道用線來完成與

// run the application 
    application.execute(); 

代碼執行的是內容翔實,清晰

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

pipeli並且可以輕鬆改變您的特定需求。開源項目:)的

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; 
}