public Dictionary parseDictionaryFile(String dictionaryFilePath,
InputStream dictionaryFileStream, DictionaryBuilder dictBuilder)
throws ResourceInitializationException {
// parse the dictionary file and extract the content
DictionaryDocument dictionaryDoc;
try {
dictionaryDoc = DictionaryDocument.Factory.parse(dictionaryFileStream);
} catch (Exception ex) {
throw new DictionaryAnnotatorConfigException(
"dictionary_annotator_error_parsing_dictionary_file",
new Object[] { dictionaryFilePath }, ex);
}
// validate input file
ArrayList<XmlError> validationErrors = new ArrayList<XmlError>();
XmlOptions validationOptions = new XmlOptions();
validationOptions.setErrorListener(validationErrors);
boolean isValid = dictionaryDoc.validate(validationOptions);
// output the errors if the XML is invalid.
if (!isValid) {
Iterator<XmlError> iter = validationErrors.iterator();
StringBuffer errorMessages = new StringBuffer();
while (iter.hasNext()) {
errorMessages.append("\n>> ");
errorMessages.append(iter.next());
}
throw new DictionaryAnnotatorConfigException(
"dictionary_annotator_error_xml_validation", new Object[] {
dictionaryFilePath, errorMessages.toString() });
}
// get dictionary document
DictionaryDocument.Dictionary dictionary = dictionaryDoc.getDictionary();
// get type collection settings
TypeCollectionDocument.TypeCollection typeCollection = dictionary
.getTypeCollection();
DictionaryMetaData dictMetaData = typeCollection.getDictionaryMetaData();