public void loadDictionaryContents()

in ConceptMapper/src/main/java/org/apache/uima/conceptMapper/support/dictionaryResource/DictionaryResource_impl.java [252:348]


  public void loadDictionaryContents(UimaContext aContext, Logger logger,
          String tokenAnnotationName, String tokenTypeFeatureName, String tokenClassFeatureName,
          String tokenizerDescriptor) throws ResourceInitializationException {

    InputStream dictStream = null;
    try {
      dictLoader.setLogger(logger);
      Boolean sortElementsParam = Boolean.valueOf (false);

      sortElementsParam = (Boolean) aContext.getConfigParameterValue(PARAM_ORDERINDEPENDENTLOOKUP);
      if (sortElementsParam == null) {
        sortElements = false;
      } else {
        sortElements = sortElementsParam.booleanValue();
      }

      Boolean dumpDictParam = (Boolean) aContext.getConfigParameterValue(PARAM_DUMPDICT);
      if (dumpDictParam == null) {
        dumpDict = false;
      } else {
        dumpDict = dumpDictParam.booleanValue();
      }

      TokenNormalizer tokenNormalizer = new TokenNormalizer(aContext, logger);

      // open input stream to data
      dictStream = dictLoader.getInputStream();

      TokenFilter tokenFilter = new TokenFilter(tokenAnnotationName, tokenTypeFeatureName,
              tokenClassFeatureName, logger);
      tokenFilter.initConfig(aContext);

      String langID = (String) aContext.getConfigParameterValue(PARAM_LANGID);
      if ((langID == null) || (langID == ""))
      {
        langID = DEFAULT_LANGID;
      }
      
      XMLParserName = (String) aContext.getConfigParameterValue(PARAM_XML_PARSER);
      
      String [] entryPropertyNames = (String []) aContext.getConfigParameterValue(PARAM_ATTRIBUTE_LIST);
      entryPropertiesRoot = new EntryPropertiesRoot(entryPropertyNames);
      // System.out.print ("Loading Dictionary: '" + dictLoader.dataResource.getUri().toString() +
      // "'...");
      // System.out.print ("Loading Dictionary...");
      URL dictUrl = dictLoader.dataResource.getUrl();
      String loadPath = (null != dictUrl) 
                          ? (" from " + dictLoader.dataResource.getUrl().toString())
                          : "";
      logger.logInfo("Loading Dictionary" + loadPath);
      dictLoader.setDictionary(dictStream, NumOfInitialDictEntries, tokenAnnotationName,
              tokenTypeFeatureName, tokenClassFeatureName, tokenizerDescriptor, tokenFilter,
              tokenNormalizer, langID, entryPropertiesRoot);
      logger.logInfo("...done loading dictionary" + loadPath);
      
      do { // to establish break boundary
        if (compDictDir != null) {
          if (!compDictDir.exists()) {
            if (!compDictDir.mkdirs()) {
              logger.logError("Cannot create compiled dictionary output directory: " + compDictDir.toString());
              break;
            }
          }
          
          // get the last part of the file source name - this will be the name of the compiled dictioary
          String n = dictUrl.getPath();
          int i = n.lastIndexOf(File.separator);
          n = (i >= 0) ? n.substring(i + 1) : n;
          
          BufferedOutputStream output = new BufferedOutputStream(new FileOutputStream(new File(compDictDir, n)));
          serializeEntries(output);
          output.close();
        }
      } while (false);  // of do establishing break boundary
      
      // System.out.println ("done");
      // System.err.println("NEW DICT:\n" + toString());
      setLoaded(true);
      if (dumpDict)
      {
        System.err.println("BEGIN DUMPING DICTIONARY:");
        System.err.println(toString());
        System.err.println("DONE DUMPING DICTIONARY! ");
      }

    } catch (Exception e) {
      throw new ResourceInitializationException(e);
    } finally {
      if (dictStream != null) {
        try {
          dictStream.close();
        } catch (IOException e) {
        }
      }
    }

  }