// Copyright (c) Committed Software 2018, opensource@committed.io
package uk.gov.dstl.baleen.annotators.language;

import org.apache.uima.UimaContext;
import org.apache.uima.analysis_engine.AnalysisEngineProcessException;
import org.apache.uima.jcas.JCas;
import org.apache.uima.resource.ResourceInitializationException;
import org.clulab.processors.Document;
import org.clulab.processors.clu.CluProcessor;

import com.google.common.collect.ImmutableSet;
import com.typesafe.config.ConfigFactory;

import uk.gov.dstl.baleen.core.pipelines.orderers.AnalysisEngineAction;
import uk.gov.dstl.baleen.odin.DocumentConverter;
import uk.gov.dstl.baleen.types.language.Dependency;
import uk.gov.dstl.baleen.types.language.Sentence;
import uk.gov.dstl.baleen.types.language.WordToken;
import uk.gov.dstl.baleen.uima.BaleenAnnotator;

/**
 * Extract language elements using Odin Extraction Framework.
 *
 * <p>
 */
public class OdinParser extends BaleenAnnotator {

  private CluProcessor processor;

  @Override
  public void initialize(UimaContext context) throws ResourceInitializationException {
    super.initialize(context);
    processor = new CluProcessor(ConfigFactory.load("cluprocessoropen"));
  }

  @Override
  public void doProcess(JCas jCas) throws AnalysisEngineProcessException {

    Document document = processor.annotate(jCas.getDocumentText(), false);

    DocumentConverter converter = new DocumentConverter(jCas, document);
    converter.convert();
  }

  @Override
  public AnalysisEngineAction getAction() {
    return new AnalysisEngineAction(
        ImmutableSet.of(), ImmutableSet.of(Sentence.class, WordToken.class, Dependency.class));
  }
}

@@ -1294,16 +1294,42 @@
 ocument 
+document;%0A    try %7B%0A      
 document
@@ -1382,16 +1382,251 @@
 false);%0A
+    %7D catch (Exception e) %7B%0A      getMonitor()%0A          .error(%0A              %22OdinParser has a known bug if the Baleen JAR path contains spaces. See https://github.com/dstl/baleen/issues/82 for further details%22);%0A      throw e;%0A    %7D
 %0A    Doc

Add error information relating to https://github.com/dstl/baleen/issues/82