Java Code Examples for org.apache.uima.UimaContext#getLogger()

The following examples show how to use org.apache.uima.UimaContext#getLogger() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MongoDBWriter.java    From ctakes-docker with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void initialize(UimaContext context) throws ResourceInitializationException {
    super.initialize(context);

    if(logger == null) {
        logger = context.getLogger();
    }

    // Initialize the MongoDB Connection
    try{
        String connectionString;
        if(this.mongoUser == null){
            connectionString = String.format("mongodb://%s", this.mongoHost);
            logger.log(Level.SEVERE, "Using unauthenticated connection string: " + connectionString);
        }else{
            connectionString = String.format("mongodb://%s:%s@%s", this.mongoUser, this.mongoPw, this.mongoHost);
        }
        this.mongoClient = MongoClients.create(connectionString);
        this.mongoDb = mongoClient.getDatabase(this.mongoDbName);
        this.coll = mongoDb.getCollection(this.collection);
    }catch(Exception e){
        throw new ResourceInitializationException(e);
    }
}
 
Example 2
Source File: I2b2JdbcWriter.java    From ctakes-docker with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void initialize(UimaContext context) throws ResourceInitializationException {
   super.initialize(context);
   if(logger == null) {
       logger = context.getLogger();
   }
   logger.log(Level.INFO, "Table name = " + tableName);
}
 
Example 3
Source File: PoStagger.java    From Canova with Apache License 2.0 5 votes vote down vote up
/**
 * Initializes the current instance with the given context.
 *
 * Note: Do all initialization in this method, do not use the constructor.
 */
@Override
public void initialize(UimaContext context)
    throws ResourceInitializationException {

  super.initialize(context);

  this.context = context;

  this.logger = context.getLogger();

  if (this.logger.isLoggable(Level.INFO)) {
    this.logger.log(Level.INFO, "Initializing the OpenNLP "
        + "Part of Speech annotator.");
  }

  POSModel model;

  try {
    POSModelResource modelResource = (POSModelResource) context
        .getResourceObject(UimaUtil.MODEL_PARAMETER);

    model = modelResource.getModel();
  } catch (ResourceAccessException e) {
    throw new ResourceInitializationException(e);
  }

  Integer beamSize = AnnotatorUtil.getOptionalIntegerParameter(context,
      UimaUtil.BEAM_SIZE_PARAMETER);

  if (beamSize == null)
    beamSize = POSTaggerME.DEFAULT_BEAM_SIZE;

  this.posTagger = new POSTaggerME(model, beamSize, 0);
}
 
Example 4
Source File: TextLineWriter.java    From newsleak with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void initialize(UimaContext context) throws ResourceInitializationException {
	super.initialize(context);
	langStats = new HashMap<String, String>();
	logger = context.getLogger();
	// restrict to samples
	String[] sampleIds = { "9141", "9099", "10779", "6823", "7455", "8078", "9538", "10051", "9660", "10521" };
	sampleIdHash.addAll(Arrays.asList(sampleIds));
}
 
Example 5
Source File: DictionaryExtractor.java    From newsleak with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void initialize(UimaContext context) throws ResourceInitializationException {
	super.initialize(context);
	log = context.getLogger();
	unigramDictionaries = dictTermExtractor.getUnigramDictionaries();
	mwuDictionaries = dictTermExtractor.getMwuDictionaries();
}
 
Example 6
Source File: NerMicroservice.java    From newsleak with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void initialize(UimaContext context) throws ResourceInitializationException {
	super.initialize(context);
	log = context.getLogger();
	httpClient = HttpClientBuilder.create().build();
	request = new HttpPost(nerMicroserviceUrl);
	localeMap = LanguageDetector.localeToISO();
}
 
Example 7
Source File: LanguageDetector.java    From newsleak with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void initialize(UimaContext context) throws ResourceInitializationException {
	super.initialize(context);
	supportedLanguages = getSupportedLanguages();
	languageDetector = new LanguageDetectorME(languageDetectorResource.getModel());
	logger = context.getLogger();
}
 
Example 8
Source File: NewsleakElasticsearchReader.java    From newsleak with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void initialize(UimaContext context) throws ResourceInitializationException {
	super.initialize(context);
	logger = context.getLogger();
	client = esResource.getClient();
	esIndex = esResource.getIndex();

	try {
		XContentBuilder builder = XContentFactory.jsonBuilder().startObject().field("match").startObject()
				.field("DocumentLanguage", language).endObject().endObject();

		// retrieve all ids
		totalIdList = new ArrayList<String>();
		SearchResponse scrollResp = client.prepareSearch(esIndex)
				.addSort(SortParseElement.DOC_FIELD_NAME, SortOrder.ASC).setScroll(new TimeValue(60000))
				.setQuery(builder).setSize(10000).execute().actionGet();
		while (true) {
			for (SearchHit hit : scrollResp.getHits().getHits()) {
				totalIdList.add(hit.getId());
			}
			scrollResp = client.prepareSearchScroll(scrollResp.getScrollId()).setScroll(new TimeValue(60000))
					.execute().actionGet();
			// Break condition: No hits are returned
			if (scrollResp.getHits().getHits().length == 0) {
				break;
			}
		}

		totalRecords = totalIdList.size();
		logger.log(Level.INFO, "Found " + totalRecords + " for language " + language + " in index");

	} catch (IOException e) {
		e.printStackTrace();
		System.exit(1);
	}

	// System.exit(1);

}
 
Example 9
Source File: SegmenterICU.java    From newsleak with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void initialize(UimaContext context) throws ResourceInitializationException {
	super.initialize(context);
	log = context.getLogger();

	localeMap = LanguageDetector.localeToISO();
}
 
Example 10
Source File: SentenceCleaner.java    From newsleak with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void initialize(UimaContext context) throws ResourceInitializationException {
	super.initialize(context);
	log = context.getLogger();
	log.setLevel(Level.ALL);
	dfs = new DateFormatSymbols(Locale.GERMAN);
	monthNames = new HashSet<String>(Arrays.asList(dfs.getMonths()));
}
 
Example 11
Source File: KeytermExtractor.java    From newsleak with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void initialize(UimaContext context) throws ResourceInitializationException {
	super.initialize(context);
	log = context.getLogger();
	try {
		extractor = new Extractor(languageCode, 100);
	} catch (IOException e) {
		throw new ResourceInitializationException(e.getMessage(), null);
	}
}
 
Example 12
Source File: IgnorableSectionAnnotator.java    From ctakes-docker with Apache License 2.0 4 votes vote down vote up
@Override
public void initialize(UimaContext context) throws ResourceInitializationException {
    super.initialize(context);
    logger = context.getLogger();
}
 
Example 13
Source File: HooverElasticsearchReader.java    From newsleak with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public void initialize(UimaContext context) throws ResourceInitializationException {
	super.initialize(context);

	logger = context.getLogger();
	// init hoover connection
	client = hooverResource.getClient();
	esIndex = hooverResource.getIndex();

	// query hoover's elasticsearch index
	Search search = new Search.Builder(
			"{\"query\": {\"match_all\" : {}}, \"_source\" : false, \"size\" : " + PARAM_SCROLL_SIZE + "}")
					.addIndex(hooverResource.getIndex()).addType(HooverResource.HOOVER_DOCUMENT_TYPE)
					.setParameter(Parameters.SCROLL, PARAM_SCROLL_TIME).build();

	try {

		// run JEST request
		JestResult result = client.execute(search);

		totalIdList = new ArrayList<String>();

		JsonArray hits = result.getJsonObject().getAsJsonObject("hits").getAsJsonArray("hits");
		Integer total = result.getJsonObject().getAsJsonObject("hits").get("total").getAsInt();

		int nHits = hits.size();

		logger.log(Level.INFO, "Hits first result: " + nHits);
		logger.log(Level.INFO, "Hits total: " + total);

		totalIdList.addAll(hooverResource.getIds(hits));

		String scrollId = result.getJsonObject().get("_scroll_id").getAsString();

		// run scroll request to collect all Ids
		int i = 0;
		while (nHits > 0) {
			SearchScroll scroll = new SearchScroll.Builder(scrollId, PARAM_SCROLL_TIME).build();

			result = client.execute(scroll);

			hits = result.getJsonObject().getAsJsonObject("hits").getAsJsonArray("hits");
			nHits = hits.size();
			logger.log(Level.INFO, "Hits " + ++i + " result: " + nHits);
			totalIdList.addAll(hooverResource.getIds(hits));
			scrollId = result.getJsonObject().getAsJsonPrimitive("_scroll_id").getAsString();
		}

		if (maxRecords > 0 && maxRecords < totalIdList.size()) {
			totalIdList = new ArrayList<String>(totalIdList.subList(0, maxRecords));
		}

		totalRecords = totalIdList.size();
		logger.log(Level.INFO, "Found " + totalRecords + " ids in index " + esIndex);

	} catch (IOException e) {
		throw new ResourceInitializationException(e);
	}

}
 
Example 14
Source File: ElasticsearchDocumentWriter.java    From newsleak with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public void initialize(UimaContext context) throws ResourceInitializationException {
	super.initialize(context);
	logger = context.getLogger();
	client = esResource.getClient();
}
 
Example 15
Source File: PostgresDbWriter.java    From newsleak with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public void initialize(UimaContext context) throws ResourceInitializationException {
	super.initialize(context);
	logger = context.getLogger();
	timeFormatter = new NewsleakTimeFormatter();
}
 
Example 16
Source File: PoStagger.java    From DataVec with Apache License 2.0 3 votes vote down vote up
/**
 * Initializes the current instance with the given context.
 *
 * Note: Do all initialization in this method, do not use the constructor.
 */
@Override
public void initialize(UimaContext context) throws ResourceInitializationException {

    super.initialize(context);

    this.context = context;

    this.logger = context.getLogger();

    if (this.logger.isLoggable(Level.INFO)) {
        this.logger.log(Level.INFO, "Initializing the OpenNLP " + "Part of Speech annotator.");
    }

    POSModel model;

    try {
        POSModelResource modelResource = (POSModelResource) context.getResourceObject(UimaUtil.MODEL_PARAMETER);

        model = modelResource.getModel();
    } catch (ResourceAccessException e) {
        throw new ResourceInitializationException(e);
    }

    Integer beamSize = AnnotatorUtil.getOptionalIntegerParameter(context, UimaUtil.BEAM_SIZE_PARAMETER);

    if (beamSize == null)
        beamSize = POSTaggerME.DEFAULT_BEAM_SIZE;

    this.posTagger = new POSTaggerME(model, beamSize, 0);
}
 
Example 17
Source File: PoStagger.java    From deeplearning4j with Apache License 2.0 3 votes vote down vote up
/**
 * Initializes the current instance with the given context.
 *
 * Note: Do all initialization in this method, do not use the constructor.
 */
@Override
public void initialize(UimaContext context) throws ResourceInitializationException {

    super.initialize(context);

    this.context = context;

    this.logger = context.getLogger();

    if (this.logger.isLoggable(Level.INFO)) {
        this.logger.log(Level.INFO, "Initializing the OpenNLP " + "Part of Speech annotator.");
    }

    POSModel model;

    try {
        POSModelResource modelResource = (POSModelResource) context.getResourceObject(UimaUtil.MODEL_PARAMETER);

        model = modelResource.getModel();
    } catch (ResourceAccessException e) {
        throw new ResourceInitializationException(e);
    }

    Integer beamSize = AnnotatorUtil.getOptionalIntegerParameter(context, UimaUtil.BEAM_SIZE_PARAMETER);

    if (beamSize == null)
        beamSize = POSTaggerME.DEFAULT_BEAM_SIZE;

    this.posTagger = new POSTaggerME(model, beamSize, 0);
}
 
Example 18
Source File: PoStagger.java    From deeplearning4j with Apache License 2.0 3 votes vote down vote up
/**
 * Initializes the current instance with the given context.
 * 
 * Note: Do all initialization in this method, do not use the constructor.
 */
@Override
public void initialize(UimaContext context) throws ResourceInitializationException {

    super.initialize(context);

    this.context = context;

    this.logger = context.getLogger();

    if (this.logger.isLoggable(Level.INFO)) {
        this.logger.log(Level.INFO, "Initializing the OpenNLP " + "Part of Speech annotator.");
    }

    POSModel model;

    try {
        POSModelResource modelResource = (POSModelResource) context.getResourceObject(UimaUtil.MODEL_PARAMETER);

        model = modelResource.getModel();
    } catch (ResourceAccessException e) {
        throw new ResourceInitializationException(e);
    }

    Integer beamSize = AnnotatorUtil.getOptionalIntegerParameter(context, UimaUtil.BEAM_SIZE_PARAMETER);

    if (beamSize == null)
        beamSize = POSTaggerME.DEFAULT_BEAM_SIZE;

    this.posTagger = new POSTaggerME(model, beamSize, 0);
}