in DictionaryAnnotator/src/main/java/org/apache/uima/annotator/dict_annot/impl/DictionaryAnnotator.java [191:308]
public void initialize(UimaContext context) throws ResourceInitializationException {
super.initialize(context);
// initialize annotator logger
this.logger = this.getContext().getLogger();
// get configuration parameter settings
// get parameter ConceptFiles, default is an empty array
String[] dictionaryFileNames = safeGetConfigParameterStringArrayValue(getContext(),
DICTIONARY_FILES, new String[] {});
// get input match type
this.inputMatchTypeStr = (String) this.getContext().getConfigParameterValue(INPUT_MATCH_TYPE);
// get input match feature path
this.inputMatchFeaturePathStr = (String) this.getContext().getConfigParameterValue(
INPUT_MATCH_FEATURE_PATH);
// initialize inputMatchFeaturePath - this must only be done if a feature
// path was specified
this.inputMatchFeaturePath = new FeaturePathInfo_impl();
if (this.inputMatchFeaturePathStr != null) {
this.inputMatchFeaturePath.initialize(this.inputMatchFeaturePathStr);
}
// get input match filter feature path
this.inputMatchFilterFeaturePathStr = (String) this.getContext().getConfigParameterValue(
INPUT_MATCH_FILTER_FEATURE_PATH);
// initialize inputMatchFilterFeaturePath - this must only be done if a
// feature path was specified
this.inputMatchFilterFeaturePath = new FeaturePathInfo_impl();
if (this.inputMatchFilterFeaturePathStr != null) {
this.inputMatchFilterFeaturePath.initialize(this.inputMatchFilterFeaturePathStr);
}
// get filter condition operator
this.filterConditionOperator = (String) this.getContext().getConfigParameterValue(
FILTER_CONDITION_OPERATOR);
// get filter condition value
this.filterConditionValue = (String) this.getContext().getConfigParameterValue(
FILTER_CONDITION_VALUE);
// check filter condition if we have a filter condition feature path
if (this.inputMatchFilterFeaturePathStr != null) {
if (this.filterConditionOperator == null) {
throw new DictionaryAnnotatorConfigException(
"dictionary_annotator_error_missing_config_parameter",
new Object[] { FILTER_CONDITION_OPERATOR });
}
if (this.filterConditionValue == null) {
throw new DictionaryAnnotatorConfigException(
"dictionary_annotator_error_missing_config_parameter",
new Object[] { FILTER_CONDITION_VALUE });
}
// get condition operator
FilterOp operator = Condition.getOperator(this.filterConditionOperator);
if (operator == null) {
throw new DictionaryAnnotatorConfigException(
"dictionary_annotator_error_condition_operator_not_valid",
new Object[] { this.filterConditionOperator });
}
// create new Condition object
this.filterCondition = new Condition(operator, this.filterConditionValue);
// log filter condition
StringBuffer buffer = new StringBuffer();
buffer.append(this.inputMatchTypeStr);
buffer.append(":");
buffer.append(this.inputMatchFilterFeaturePathStr);
buffer.append(" ");
buffer.append(operator.toString());
buffer.append(" ");
buffer.append(this.filterConditionValue);
this.logger.logrb(Level.CONFIG, "DictionaryAnnotator", "initialize", MESSAGE_DIGEST,
"dictionary_annotator_filter_feature_condition", new Object[] { buffer.toString() });
}
// create dictionary file parser
DictionaryFileParser fileParser = new DictionaryFileParserImpl();
// 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()));
}
// parse dictionary files
ArrayList<Dictionary> dicts = new ArrayList<Dictionary>();
for (int i = 0; i < dictionaryFileNames.length; i++) {
// try to resolve the relative file name with classpath or datapath
DictionaryFile file = resolveRelativeFilePath(dictionaryFileNames[i], datapathElements);
// if the current dictionary file wasn't found, throw an exception
if (file == null) {
throw new DictionaryAnnotatorConfigException("dictionary_annotator_resource_not_found",
new Object[] { dictionaryFileNames[i] });
} else {
// log concept file path
this.logger.logrb(Level.CONFIG, "DictionaryAnnotator", "initialize", MESSAGE_DIGEST,
"dictionary_annotator_dictionary_file", new Object[] { file.getFilePath() });
// parse dictionary file
Dictionary dict = fileParser.parseDictionaryFile(file.getFilePath(), file.getStream(),
new HashMapDictionaryBuilder());
// add dictionary to the dictionary list
dicts.add(dict);
}
}
// store all dictionaries in the dictionary array
this.dictionaries = dicts.toArray(new Dictionary[] {});
}