2

1 つのカスタムJAPEファイルを作成し、それを GATE ソース コードで構成する方法を教えてください。次のコードを試してみましたが、「文法の解析中にエラーが発生しました:」や「grammarURL または binaryGrammarURL パラメーターが設定されていません!」などの例外が発生しました。

     try{
             Document doc = new DocumentImpl();
              String str = "This is test.";
              DocumentContentImpl impl = new DocumentContentImpl(str);
              doc.setContent(impl);
          System.setProperty("gate.home", "C:\\Program Files\\GATE_Developer_7.1"); 
          Gate.init();
          gate.Corpus corpus = (Corpus) Factory
            .createResource("gate.corpora.CorpusImpl");
          File gateHome = Gate.getGateHome();
          File pluginsHome = new File(gateHome, "plugins");
          Gate.getCreoleRegister().registerDirectories(new File(pluginsHome, "ANNIE").toURI().toURL());  

          Transducer transducer = new Transducer();
             transducer.setDocument(doc);
transducer.setGrammarURL(new URL("file:///D:/misc_workspace/gate-7.1-build4485-SRC/plugins/ANNIE/resources/NE/SportsCategory.jape"));
transducer.setBinaryGrammarURL(new URL("file:///D:/misc_workspace/gate-7.1-build4485-SRC/plugins/ANNIE/resources/NE/SportsCategory.jape"));

LanguageAnalyser jape = (LanguageAnalyser)Factory.createResource(
                  "gate.creole.Transducer", gate.Utils.featureMap(
                          "grammarURL", "D:/misc_workspace/gate-7.1-build4485-SRC/plugins/ANNIE/resources/NE/SportsCategory.jape",
                          "encoding", "UTF-8"));
4

3 に答える 3

3

ANNIEプラグインをロードする必要があります

Gate.getCreoleRegister().registerDirectories(
  new File(Gate.getPluginsHome(), "ANNIE").toURI().toURL());

gate.creole.Transducer次に、適切なパラメータを使用してのインスタンスを作成します

LanguageAnalyser jape = (LanguageAnalyser)Factory.createResource(
  "gate.creole.Transducer", gate.Utils.featureMap(
      "grammarURL", new URL("file:///D:/path/to/my-grammar.jape"),
      "encoding", "UTF-8")); // ensure this matches the file

しかし、私たちが通常提唱するアプローチは、パイプライン全体をGATE Developerで希望どおりにアセンブルおよび構成し、必要な標準コンポーネントと独自の文法を使用して、アプリケーションの状態をファイルに保存することです。その後、1行を使用してコードからアプリケーション全体をリロードできます

CorpusController app = (CorpusController) PersistenceManager.loadObjectFromFile(savedAppFile);

編集:質問に追加したコードには、いくつかの基本的な問題があります。まずGate.init()、GATEで他のことを行う前に、を呼び出す必要があります。を作成するDocumentに呼び出す必要があります。次に、クラスのコンストラクターを直接呼び出さResourceないでください。常に。を使用してFactoryください。init()同様に、これはの一部として行われるため、直接呼び出す必要はありませんFactory.createResource。例えば:

// initialise GATE
Gate.setGateHome(new File("C:\\Program Files\\GATE_Developer_7.1"));
Gate.init();

// load ANNIE plugin - you must do this before you can create tokeniser
// or JAPE transducer resources.
Gate.getCreoleRegister().registerDirectories(
   new File(Gate.getPluginsHome(), "ANNIE").toURI().toURL());

// Build the pipeline
SerialAnalyserController pipeline =
  (SerialAnalyserController)Factory.createResource(
     "gate.creole.SerialAnalyserController");
LanguageAnalyser tokeniser = (LanguageAnalyser)Factory.createResource(
     "gate.creole.tokeniser.DefaultTokeniser");
LanguageAnalyser jape = (LanguageAnalyser)Factory.createResource(
  "gate.creole.Transducer", gate.Utils.featureMap(
      "grammarURL", new File("D:\\path\\to\\my-grammar.jape").toURI().toURL(),
      "encoding", "UTF-8")); // ensure this matches the file
pipeline.add(tokeniser);
pipeline.add(jape);

// create document and corpus
Corpus corpus = Factory.newCorpus(null);
Document doc = Factory.newDocument("This is test.");
corpus.add(doc);
pipeline.setCorpus(corpus);

// run it
pipeline.execute();

// extract results
System.out.println("Found annotations of the following types: " +
  doc.getAnnotations().getAllTypes());

まだ行っていない場合は、少なくともモジュール5のトレーニングコースの資料に目を通すことを強くお勧めします。これにより、ドキュメントをロードして処理リソースを実行する正しい方法がわかります。

于 2013-02-23T18:10:23.153 に答える
1

ありがとうイアン。これらのトレーニング コースの資料は役に立ちます。しかし、私の問題は異なり、解決しました。次のコード スナップは、 GATE でカスタム jape ファイルを使用する方法です。これで、カスタム jape ファイルで新しい注釈を生成できるようになりました。

 System.setProperty("gate.home", "C:\\Program Files\\GATE_Developer_7.1"); 
  Gate.init();

  ProcessingResource token = (ProcessingResource)   Factory.createResource("gate.creole.tokeniser.DefaultTokeniser",Factory.newFeatureMap());



 String str = "This is a test. Myself Abhijit Nag sport";
   Document doc = Factory.newDocument(str);


  gate.Corpus corpus = (Corpus) Factory.createResource("gate.corpora.CorpusImpl");
  corpus.add(doc);
  File gateHome = Gate.getGateHome();
  File pluginsHome = new File(gateHome, "plugins");

  Gate.getCreoleRegister().registerDirectories(new File(pluginsHome, "ANNIE").toURI().toURL());  


 LanguageAnalyser jape = (LanguageAnalyser)Factory.createResource(
              "gate.creole.Transducer", gate.Utils.featureMap(
                      "grammarURL", "file:///D:/misc_workspace/gate-7.1-build4485-SRC/plugins/ANNIE/resources/NE/SportsCategory.jape","encoding", "UTF-8"));
      jape.setCorpus(corpus);
      jape.setDocument(doc);
      jape.execute();

  pipeline = (SerialAnalyserController) Factory.createResource("gate.creole.SerialAnalyserController",
                Factory.newFeatureMap(), Factory.newFeatureMap(),"ANNIE");
              initAnnie();
              pipeline.setCorpus(corpus);
              pipeline.add(token);
              pipeline.add((ProcessingResource)jape.init());
              pipeline.execute();
      AnnotationSetImpl ann = (AnnotationSetImpl) doc.getAnnotations();
      System.out.println(" ...Total annotation "+ann.getAllTypes());
于 2013-02-25T20:29:10.797 に答える
0

これは、ANNIE パイプラインを更新する場合の別のオプションです。

  1. 最初に、パイプライン内のデフォルト/既存の処理リソースのリストを取得します
  2. JAPE ルールのインスタンスを作成する
  3. 既存の処理リソースのリストを反復処理して、それぞれを新しいコレクションに追加します。このコレクションに独自のカスタム JAPE ルールを追加します。
  4. ANNIE パイプラインを実行すると、JAPE ルールが自動的に取得されるため、ドキュメント パスを指定したり、個別に実行したりする必要はありません。

サンプルコード:

File pluginsHome = Gate.getPluginsHome();
File anniePlugin = new File(pluginsHome, "ANNIE");
File annieGapp = new File(anniePlugin, "ANNIE_with_defaults.gapp");
annieController = (CorpusController) PersistenceManager.loadObjectFromFile(annieGapp);

LanguageAnalyser jape = (LanguageAnalyser)Factory.createResource(
                "gate.creole.Transducer", gate.Utils.featureMap(
                        "grammarURL", new URL("file:///C://Program Files//gate-7.1//plugins//ANNIE//resources//NE//opensource.jape"),
                        "encoding", "UTF-8")); 

Collection<ProcessingResource> newPRS = new ArrayList<ProcessingResource>();
Collection<ProcessingResource> prs = annieController.getPRs();
for(ProcessingResource resource: prs){
    newPRS.add(resource);
}
newPRS.add((ProcessingResource)jape.init());
annieController.setPRs(newPRS);
于 2014-02-15T14:56:13.520 に答える