Ejemplo n.º 1
0
  /** initialization method where we fill configuration values and check some prerequisites */
  public void initialize(UimaContext aContext) {
    // check if the supplied language is one that we can currently handle
    this.language =
        Language.getLanguageFromString((String) aContext.getConfigParameterValue(PARAM_LANGUAGE));

    // get configuration from the descriptor
    annotate_tokens = (Boolean) aContext.getConfigParameterValue(PARAM_ANNOTATE_TOKENS);
    annotate_sentences = (Boolean) aContext.getConfigParameterValue(PARAM_ANNOTATE_SENTENCES);
    annotate_partofspeech = (Boolean) aContext.getConfigParameterValue(PARAM_ANNOTATE_PARTOFSPEECH);
    String cnTokPath = (String) aContext.getConfigParameterValue(PARAM_CHINESE_TOKENIZER_PATH);

    // set some configuration based upon these values
    ttprops.languageName = language.getTreeTaggerLangName();
    if (ttprops.rootPath == null) ttprops.rootPath = System.getenv("TREETAGGER_HOME");
    ttprops.tokScriptName = "utf8-tokenize.perl";

    // parameter file
    if (!(new File(
            ttprops.rootPath + ttprops.fileSeparator + "lib", ttprops.languageName + "-utf8.par")
        .exists())) // get UTF8 version if it exists
    ttprops.parFileName = ttprops.languageName + ".par";
    else ttprops.parFileName = ttprops.languageName + "-utf8.par";

    // abbreviation file
    if (new File(
            ttprops.rootPath + ttprops.fileSeparator + "lib",
            ttprops.languageName + "-abbreviations-utf8")
        .exists()) { // get UTF8 version if it exists
      ttprops.abbFileName = ttprops.languageName + "-abbreviations-utf8";
    } else {
      ttprops.abbFileName = ttprops.languageName + "-abbreviations";
    }

    ttprops.languageSwitch = language.getTreeTaggerSwitch();
    if (cnTokPath != null && !cnTokPath.equals(""))
      ttprops.chineseTokenizerPath = new File(cnTokPath);
    else ttprops.chineseTokenizerPath = new File(ttprops.rootPath, "cmd");

    // handle the treetagger path from the environment variables
    if (ttprops.rootPath == null) {
      Logger.printError("TreeTagger environment variable is not present, aborting.");
      System.exit(-1);
    }

    // Check for whether the required treetagger parameter files are present
    Boolean abbFileFlag = true;
    Boolean parFileFlag = true;
    Boolean tokScriptFlag = true;
    File abbFile = new File(ttprops.rootPath + ttprops.fileSeparator + "lib", ttprops.abbFileName);
    File parFile = new File(ttprops.rootPath + ttprops.fileSeparator + "lib", ttprops.parFileName);
    File tokFile =
        new File(ttprops.rootPath + ttprops.fileSeparator + "cmd", ttprops.tokScriptName);
    if (!(abbFileFlag = abbFile.exists())) {
      if (language.equals(Language.CHINESE) || language.equals(Language.RUSSIAN)) {
        abbFileFlag = true;
        ttprops.abbFileName = null;
      } else {
        Logger.printError(
            component, "File missing to use TreeTagger tokenizer: " + ttprops.abbFileName);
      }
    }
    if (!(parFileFlag = parFile.exists())) {
      Logger.printError(
          component, "File missing to use TreeTagger tokenizer: " + ttprops.parFileName);
    }
    if (!(tokScriptFlag = tokFile.exists())) {
      if (language.equals(Language.CHINESE)) tokScriptFlag = true;
      else
        Logger.printError(
            component, "File missing to use TreeTagger tokenizer: " + ttprops.tokScriptName);
    }

    if (!abbFileFlag || !parFileFlag || !tokScriptFlag) {
      Logger.printError(
          component,
          "Cannot find tree tagger ("
              + ttprops.rootPath
              + ttprops.fileSeparator
              + "cmd"
              + ttprops.fileSeparator
              + ttprops.tokScriptName
              + ")."
              + " Make sure that path to tree tagger is set correctly in config.props!");
      Logger.printError(component, "If path is set correctly:");
      Logger.printError(
          component, "Maybe you need to download the TreeTagger tagger-scripts.tar.gz");
      Logger.printError(
          component,
          "from http://www.cis.uni-muenchen.de/~schmid/tools/TreeTagger/data/tagger-scripts.tar.gz");
      Logger.printError(
          component,
          "Extract this file and copy the missing file into the corresponding TreeTagger directories.");
      Logger.printError(
          component,
          "If missing, copy "
              + ttprops.abbFileName
              + " into "
              + ttprops.rootPath
              + ttprops.fileSeparator
              + "lib");
      Logger.printError(
          component,
          "If missing, copy "
              + ttprops.parFileName
              + " into "
              + ttprops.rootPath
              + ttprops.fileSeparator
              + "lib");
      Logger.printError(
          component,
          "If missing, copy "
              + ttprops.tokScriptName
              + " into "
              + ttprops.rootPath
              + ttprops.fileSeparator
              + "cmd");
      System.exit(-1);
    }
  }