in RegularExpressionAnnotator/src/main/java/org/apache/uima/annotator/regex/impl/RegExAnnotator.java [89:180]
public void initialize(UimaContext aContext) throws ResourceInitializationException {
super.initialize(aContext);
// initialize annotator logger
this.logger = getContext().getLogger();
// default initialization for number format
this.floatNumberFormat = NumberFormat.getNumberInstance();
this.integerNumberFormat = NumberFormat.getIntegerInstance();
// create a concept file parser object
ConceptFileParser parser = new ConceptFileParser_impl();
// get configuration parameter settings
// get parameter ConceptFiles, default is an empty array
String[] conceptFileNames = safeGetConfigParameterStringArrayValue(getContext(),
REGEX_CONCEPTS_FILES, new String[] {});
// get UIMA datapath and tokenize it into its elements
StringTokenizer tokenizer = new StringTokenizer(getContext().getDataPath(), PATH_SEPARATOR);
ArrayList<File> datapathElements = new ArrayList<File>();
while (tokenizer.hasMoreTokens()) {
// add datapath elements to the 'datapathElements' array list
datapathElements.add(new File(tokenizer.nextToken()));
}
// try to resolve the concept file names
ArrayList<Concept> concepts = new ArrayList<Concept>();
for (int i = 0; i < conceptFileNames.length; i++) {
// try to resolve the relative file name with classpath or datapath
String filename = conceptFileNames[i];
List<ConceptFile> cfList = new ArrayList<ConceptFile>();
if (containsWildcardChar(filename)) {
resolveRelativeWildcardFilePath(filename, datapathElements, cfList);
} else {
ConceptFile file = resolveRelativeFilePath(filename, datapathElements);
// if the current concept file wasn't found, throw an exception
if (file == null) {
throw new RegexAnnotatorConfigException("regex_annotator_resource_not_found",
new Object[] { conceptFileNames[i] });
}
cfList.add(file);
// log concept file path
this.logger.logrb(Level.CONFIG, "RegExAnnotator", "initialize", MESSAGE_DIGEST,
"regex_annotator_rule_set_file", new Object[] { file.getFilePath() });
}
for (ConceptFile file : cfList) {
// parse concept file to internal objects
Concept[] currentConcepts = parser.parseConceptFile(file.getFilePath(), file.getStream());
try {
file.getStream().close();
} catch (IOException e) {
this.logger.logrb(Level.WARNING, "RegExAnnotator", "initialize", MESSAGE_DIGEST,
"regex_annotator_error_closing_input_stream", new Object[] { file.getFilePath(),
e.getMessage() });
}
// add all concepts to the concepts list
for (int c = 0; c < currentConcepts.length; c++) {
concepts.add(currentConcepts[c]);
}
}
}
// get one array that contains all the concepts
this.regexConcepts = concepts.toArray(new Concept[] {});
// check duplicate concept names
HashSet<String> conceptNames = new HashSet<String>(this.regexConcepts.length);
for (int i = 0; i < this.regexConcepts.length; i++) {
String name = this.regexConcepts[i].getName();
// check if concept name was set, if not, skip concept
if (name == null) {
continue;
}
// concept name was set, check for duplicate concept names
// duplicate concept names can occurs, just log a warning!
if (conceptNames.contains(name)) {
this.logger.logrb(Level.WARNING, "RegExAnnotator", "initialize", MESSAGE_DIGEST,
"regex_annotator_warning_duplicate_concept_name", new Object[] { name });
} else {
// add concept name to the concept name list
conceptNames.add(name);
}
}
// initialize the regex concepts
for (int i = 0; i < this.regexConcepts.length; i++) {
((Concept_impl) this.regexConcepts[i]).initialize(this.logger);
}
}