throws AnnotatorContextException, ResourceAccessException {
final String extResrcKey = rootDictEl.getAttributeValue( "externalResourceKey" );
// UimaContext.getResourceObject(..) throws ResourceAccessException
final Object extResrc = annotCtx.getResourceObject( extResrcKey );
if ( extResrc == null ) {
throw new ResourceAccessException( "Unable to find external resource with key:" + extResrcKey, null );
}
final Element lookupFieldEl = rootDictEl.getChild( "lookupField" );
final String lookupFieldName = lookupFieldEl.getAttributeValue( "fieldName" );
Dictionary dict;
try {
if (rootDictEl.getChild( "implementation" ).getChildren().isEmpty() ) {
throw new ResourceAccessException( new IndexOutOfBoundsException() );
}
final Element implEl = (Element) rootDictEl.getChild( "implementation" ).getChildren().get( 0 );
final String implType = implEl.getName();
if ( implType.equals( "luceneImpl" ) ) {
if ( !(extResrc instanceof LuceneIndexReaderResource) ) {
throw new ResourceAccessException( "Expected external resource to be:"
+ LuceneIndexReaderResource.class, new Object[]{extResrc} );
}
final IndexReader indexReader = ((LuceneIndexReaderResource) extResrc).getIndexReader();
final IndexSearcher indexSearcher = new IndexSearcher( indexReader );
// Added 'MaxListSize' ohnlp-Bugs-3296301
dict = new LuceneDictionaryImpl( indexSearcher, lookupFieldName, MAX_LIST_SIZE );
} else if ( implType.equals( "jdbcImpl" ) ) {
final String tableName = implEl.getAttributeValue( "tableName" );
if ( !(extResrc instanceof JdbcConnectionResource) ) {
throw new ResourceAccessException( "Expected external resource to be:"
+ JdbcConnectionResource.class, new Object[]{extResrc} );
}
final Connection conn = ((JdbcConnectionResource) extResrc).getConnection();
dict = new JdbcDictionaryImpl( conn, tableName, lookupFieldName );
} else if ( implType.equals( "csvImpl" ) ) {
final String fieldDelimiter = implEl.getAttributeValue( "delimiter" );
if ( !(extResrc instanceof FileResource) ) {
throw new ResourceAccessException( "Expected external resource to be:"
+ FileResource.class, new Object[]{extResrc} );
}
final String idxFieldNameStr = implEl.getAttributeValue( "indexedFieldNames" );
final StringTokenizer st = new StringTokenizer( idxFieldNameStr, "," );
int arrIdx = 0;
String[] idxFieldNameArr = new String[st.countTokens()];
while ( st.hasMoreTokens() ) {
idxFieldNameArr[arrIdx++] = st.nextToken().trim();
}
final File csvFile = ((FileResource) extResrc).getFile();
try {
final StringTable strTable = StringTableFactory.build( new FileReader( csvFile ),
fieldDelimiter, idxFieldNameArr, true );
dict = new StringTableDictionaryImpl( strTable, lookupFieldName );
} catch ( FileNotFoundException fnfE ) {
throw new ResourceAccessException( "Could not open csv file", new Object[]{csvFile} );
} catch (IOException ioE ) {
throw new ResourceAccessException( "Could not open csv file", new Object[]{csvFile} );
}
} else {
throw new ResourceAccessException( "Unsupported impl type:" + implType, new Object[]{implType} );
}
final List<Element> rootDictChildren = rootDictEl.getChild( "metaFields" ).getChildren();
for ( Element metaFieldEl : rootDictChildren ) {
final String metaFieldName = metaFieldEl.getAttributeValue( "fieldName" );
dict.retainMetaData( metaFieldName );
}
} catch ( NullPointerException npE ) {
// thrown all over this method ...
throw new ResourceAccessException( npE );
}
final boolean keepCase = Boolean.parseBoolean( rootDictEl.getAttributeValue( "caseSensitive" ) );
final DictionaryEngine dictEngine = new DictionaryEngine( dict, keepCase );
final Element excludeList = rootDictEl.getChild( "excludeList" );
if ( excludeList != null && excludeList.getChildren() != null && !excludeList.getChildren().isEmpty() ) {