Examples of AnnotatorContextException


Examples of org.apache.uima.analysis_engine.annotator.AnnotatorContextException

      final SAXBuilder saxBuilder = new SAXBuilder();
      Document doc;
      try {
         doc = saxBuilder.build( descriptorFile );
      } catch ( JDOMException jdomE ) {
         throw new AnnotatorContextException( "Could not parse " + descriptorFile.getPath(), new Object[0], jdomE );
      } catch ( IOException ioE ) {
         throw new AnnotatorContextException( "Could not parse " + descriptorFile.getPath(), new Object[0], ioE );
      }
      final Map<String, RareWordDictionary> dictionaries
            = parseDictionaries( uimaContext, doc.getRootElement().getChild( DICTIONARIES_KEY ) );
      final TermConsumer consumer = parseConsumerXml( uimaContext,
                                                              doc.getRootElement().getChild( CONSUMER_KEY ) );
View Full Code Here

Examples of org.apache.uima.analysis_engine.annotator.AnnotatorContextException

      final String entityTypeId = dictionaryElement.getAttributeValue( TYPE_ID );
      Object externalResource;
      try {
         externalResource = uimaContext.getResourceObject( externalResourceKey );
      } catch ( ResourceAccessException raE ) {
         throw new AnnotatorContextException( "Could not access external resource " + externalResourceKey,
                                              new Object[0], raE );
      }
      if ( externalResource == null ) {
         throw new AnnotatorContextException( "Could not find external resource " + externalResourceKey,
                                              new Object[0] );
      }
      RareWordDictionary dictionary = null;
      final Element implementationElement = (Element) dictionaryElement.getChild( IMPLEMENTATION ).getChildren().get( 0 );
      final String implementationName = implementationElement.getName();
      if ( implementationName.equals( "rareWordJdbc" ) ) {
         dictionary = DictionaryFactory.createRareWordJdbc( implementationElement,
                                                            externalResource,
                                                            entityTypeId );
      } else if ( implementationName.equals( "rareWordUmls" ) ) {
         try {
            UmlsUserApprover.validateUMLSUser( uimaContext );
            dictionary = DictionaryFactory.createRareWordJdbc( implementationElement,
                                                               externalResource,
                                                               entityTypeId );
         } catch ( ResourceInitializationException riE ) {
            throw new AnnotatorContextException( riE );
         }
      } else if ( implementationName.equals( "rareWordBsv" ) ) {
         dictionary = DictionaryFactory.createRareWordBsv( externalResourceKey, externalResource, entityTypeId );
//      } else if ( implementationName.equals( "luceneImpl" ) ) {
//         dictionary = DictionaryFactory.createWrappedLucene( dictionaryElement,
//                                                                     externalResourceKey,
//                                                                     externalResource,
//                                                                     entityTypeId );
//      } else if ( implementationName.equals( "jdbcImpl" ) ) {
//         dictionary = DictionaryFactory.createWrappedJdbc( dictionaryElement,
//                                                                   implementationElement,
//                                                                   externalResourceKey,
//                                                                   externalResource,
//                                                                   entityTypeId );
//      } else if ( implementationName.equals( "csvImp" ) ) {
//         dictionary = DictionaryFactory.createWrappedCsv( dictionaryElement,
//                                                                  implementationElement,
//                                                                  externalResourceKey,
//                                                                  externalResource,
//                                                                  entityTypeId );
      } else {
         throw new AnnotatorContextException( "Unsupported dictionary implementation " + implementationName,
                                              new Object[0] );
      }
      if ( dictionary == null ) {
         throw new AnnotatorContextException( "No appropriate dictionary defined", new Object[0] );
      }
      // Deprecated -
//      if ( dictionary instanceof Dictionary ) {
//         final Collection metaFields = dictionaryElement.getChild( "metaFields" ).getChildren();
//         for ( Object value : metaFields ) {
View Full Code Here

Examples of org.apache.uima.analysis_engine.annotator.AnnotatorContextException

      Properties consumerProperties = parsePropertiesXml( consumerPropertiesElement );
      Class consumerClass;
      try {
         consumerClass = Class.forName( consumerClassName );
      } catch ( ClassNotFoundException cnfE ) {
         throw new AnnotatorContextException( "Unknown class " + consumerClassName, new Object[0], cnfE );
      }
      if ( !TermConsumer.class.isAssignableFrom( consumerClass ) ) {
         throw new AnnotatorContextException( consumerClassName + " is not a TermConsumer",
                                              new Object[0] );
      }
      final Constructor[] constructors = consumerClass.getConstructors();
      for ( Constructor constructor : constructors ) {
         try {
            if ( Arrays.equals( constrArgsConsum, constructor.getParameterTypes() ) ) {
               final Object[] args = new Object[]{uimaContext, consumerProperties, MAX_LIST_SIZE}; //ohnlp-Bugs-3296301
               return (TermConsumer) constructor.newInstance( args );
            } else if ( Arrays.equals( constrArgsConsumB, constructor.getParameterTypes() ) ) {
               final Object[] args = new Object[]{uimaContext, consumerProperties};
               return (TermConsumer) constructor.newInstance( args );
            }
         } catch ( InstantiationException inE ) {
            throw new AnnotatorContextException( "Could not construct " + consumerClassName, new Object[0], inE );
         } catch ( IllegalAccessException iaE ) {
            throw new AnnotatorContextException( "Could not construct " + consumerClassName, new Object[0], iaE );
         } catch ( InvocationTargetException itE ) {
            throw new AnnotatorContextException( "Could not construct " + consumerClassName, new Object[0], itE );
         }
      }
      throw new AnnotatorContextException( "No Constructor for " + consumerClassName, new Object[0] );
   }
View Full Code Here

Examples of org.apache.uima.analysis_engine.annotator.AnnotatorContextException

   static private void checkResourceType( final Class expectedClassType, final Object typeValue )
         throws AnnotatorContextException {
      if ( expectedClassType.isInstance( typeValue ) ) {
         return;
      }
      throw new AnnotatorContextException( "Expected external resource to be " + expectedClassType.getName()
                                                 + " not " + typeValue.getClass().getName(), new Object[0] );
   }
View Full Code Here

Examples of org.apache.uima.analysis_engine.annotator.AnnotatorContextException

         for ( Element bindingEl : bindingChildren ) {
            final Element dictEl = bindingEl.getChild( "dictionaryRef" );
            final String dictID = dictEl.getAttributeValue( "idRef" );
            final DictionaryEngine dictEngine = dictMap.get( dictID );
            if ( dictEngine == null ) {
               throw new AnnotatorContextException( "Dictionary undefined: " + dictID, null );
            }

            final Element lookupInitEl = bindingEl.getChild( "lookupInitializer" );
            final String liClassName = lookupInitEl.getAttributeValue( "className" );
            final Element liPropertiesEl = lookupInitEl.getChild( "properties" );
            final Properties liProps = parsePropertiesXml( liPropertiesEl );
            final Class<?> liClass = Class.forName( liClassName );
            final Constructor<?> liConstr = liClass.getConstructor( constrArgs );
            final Object[] liArgs = {annotCtx, liProps};
            final LookupInitializer li = (LookupInitializer) liConstr.newInstance( liArgs );

            final Element lookupConsumerEl = bindingEl.getChild( "lookupConsumer" );
            final String lcClassName = lookupConsumerEl.getAttributeValue( "className" );
            final Element lcPropertiesEl = lookupConsumerEl.getChild( "properties" );
            final Properties lcProps = parsePropertiesXml( lcPropertiesEl );
            final Class<?> lcClass = Class.forName( lcClassName );
            final Constructor<?>[] consts = lcClass.getConstructors();
            Constructor<?> lcConstr = null;
            Object[] lcArgs = null;
            for ( Constructor<?> constConstr : consts ) {
               lcConstr = constConstr;
               if ( Arrays.equals( constrArgsConsum, lcConstr.getParameterTypes() ) ) {
                  lcConstr = lcClass.getConstructor( constrArgsConsum );
                  lcArgs = new Object[]{annotCtx, lcProps, MAX_LIST_SIZE};//ohnlp-Bugs-3296301
               } else if ( Arrays.equals( constrArgsConsumB, lcConstr.getParameterTypes() ) ) {
                  lcConstr = lcClass.getConstructor( constrArgsConsumB );
                  lcArgs = new Object[]{annotCtx, lcProps};
               }
            }

            final LookupConsumer lc = (LookupConsumer) lcConstr.newInstance( lcArgs );
            final LookupAlgorithm la = li.getLookupAlgorithm( dictEngine );

            final LookupSpec ls = new LookupSpec( la, li, lc );

            lsSet.add( ls );
         }
         // TODO refactor to catch ( ex1 | ex2 | ex3 ) when cTakes moves to java 7
      } catch ( ClassNotFoundException cnfE ) {
         // thrown by Class.forName(..)
         throw new AnnotatorContextException( cnfE );
      } catch ( NoSuchMethodException nsmE ) {
         // thrown by Class.getConstructor(..)
         throw new AnnotatorContextException( nsmE );
      } catch ( SecurityException secE ) {
         // thrown by Class.getConstructor(..)
         throw new AnnotatorContextException( secE );
      } catch ( InstantiationException instE ) {
         // thrown by Class.newInstance(..)
         throw new AnnotatorContextException( instE );
      } catch ( IllegalAccessException iaE ) {
         // thrown by Class.newInstance(..)
         throw new AnnotatorContextException( iaE );
      } catch ( InvocationTargetException itE ) {
         // thrown by Class.newInstance(..)
         throw new AnnotatorContextException( itE );
      } catch ( AnnotatorInitializationException aiE ) {
         // thrown by LookupInitializer.getLookupAlgorithm(..)
         throw new AnnotatorContextException( aiE );
      } catch ( ClassCastException ccE ) {
         // thrown everywhere in this method ...
         throw new AnnotatorContextException( ccE );
      } catch ( NullPointerException npE ) {
         // thrown everywhere in this method ...
         throw new AnnotatorContextException( npE );
      }
      return lsSet;
   }
View Full Code Here

Examples of org.apache.uima.analysis_engine.annotator.AnnotatorContextException

         for ( Element bindingEl : bindingChildren ) {
            final Element dictEl = bindingEl.getChild( "dictionaryRef" );
            final String dictID = dictEl.getAttributeValue( "idRef" );
            final DictionaryEngine dictEngine = dictMap.get( dictID );
            if ( dictEngine == null ) {
               throw new AnnotatorContextException( "Dictionary undefined: " + dictID, null );
            }

            final Element lookupInitEl = bindingEl.getChild( "lookupInitializer" );
            final String liClassName = lookupInitEl.getAttributeValue( "className" );
            final Element liPropertiesEl = lookupInitEl.getChild( "properties" );
            final Properties liProps = parsePropertiesXml( liPropertiesEl );
            final Class liClass = Class.forName( liClassName );
            final Constructor liConstr = liClass.getConstructor( constrArgs );
            final Object[] liArgs = {annotCtx, liProps};
            final LookupInitializer li = (LookupInitializer) liConstr.newInstance( liArgs );

            final Element lookupConsumerEl = bindingEl.getChild( "lookupConsumer" );
            final String lcClassName = lookupConsumerEl.getAttributeValue( "className" );
            final Element lcPropertiesEl = lookupConsumerEl.getChild( "properties" );
            final Properties lcProps = parsePropertiesXml( lcPropertiesEl );
            final Class lcClass = Class.forName( lcClassName );
            final Constructor[] consts = lcClass.getConstructors();
            Constructor lcConstr = null;
            Object[] lcArgs = null;
            for ( Constructor constConstr : consts ) {
               lcConstr = constConstr;
               if ( Arrays.equals( constrArgsConsum, lcConstr.getParameterTypes() ) ) {
                  lcConstr = lcClass.getConstructor( constrArgsConsum );
                  lcArgs = new Object[]{annotCtx, lcProps, MAX_LIST_SIZE};//ohnlp-Bugs-3296301
               } else if ( Arrays.equals( constrArgsConsumB, lcConstr.getParameterTypes() ) ) {
                  lcConstr = lcClass.getConstructor( constrArgsConsumB );
                  lcArgs = new Object[]{annotCtx, lcProps};
               }
            }

            final LookupConsumer lc = (LookupConsumer) lcConstr.newInstance( lcArgs );
            final LookupAlgorithm la = li.getLookupAlgorithm( dictEngine );

            final LookupSpec ls = new LookupSpec( la, li, lc );

            lsSet.add( ls );
         }
         // TODO refactor to catch ( ex1 | ex2 | ex3 ) when cTakes moves to java 7
      } catch ( ClassNotFoundException cnfE ) {
         // thrown by Class.forName(..)
         throw new AnnotatorContextException( cnfE );
      } catch ( NoSuchMethodException nsmE ) {
         // thrown by Class.getConstructor(..)
         throw new AnnotatorContextException( nsmE );
      } catch ( SecurityException secE ) {
         // thrown by Class.getConstructor(..)
         throw new AnnotatorContextException( secE );
      } catch ( InstantiationException instE ) {
         // thrown by Class.newInstance(..)
         throw new AnnotatorContextException( instE );
      } catch ( IllegalAccessException iaE ) {
         // thrown by Class.newInstance(..)
         throw new AnnotatorContextException( iaE );
      } catch ( InvocationTargetException itE ) {
         // thrown by Class.newInstance(..)
         throw new AnnotatorContextException( itE );
      } catch ( AnnotatorInitializationException aiE ) {
         // thrown by LookupInitializer.getLookupAlgorithm(..)
         throw new AnnotatorContextException( aiE );
      } catch ( ClassCastException ccE ) {
         // thrown everywhere in this method ...
         throw new AnnotatorContextException( ccE );
      } catch ( NullPointerException npE ) {
         // thrown everywhere in this method ...
         throw new AnnotatorContextException( npE );
      }
      return lsSet;
   }
View Full Code Here

Examples of org.apache.uima.analysis_engine.annotator.AnnotatorContextException

   */
  public URL getResourceURL(String aKey) throws AnnotatorContextException {
    try {
      return mUimaContext.getResourceURL(aKey);
    } catch (ResourceAccessException e) {
      throw new AnnotatorContextException(e);
    }
  }
View Full Code Here

Examples of org.apache.uima.analysis_engine.annotator.AnnotatorContextException

   */
  public URI getResourceURI(String aKey) throws AnnotatorContextException {
    try {
      return mUimaContext.getResourceURI(aKey);
    } catch (ResourceAccessException e) {
      throw new AnnotatorContextException(e);
    }
  }
View Full Code Here

Examples of org.apache.uima.analysis_engine.annotator.AnnotatorContextException

   */
  public String getResourceFilePath(String aKey) throws AnnotatorContextException {
    try {
      return mUimaContext.getResourceFilePath(aKey);
    } catch (ResourceAccessException e) {
      throw new AnnotatorContextException(e);
    }
  }
View Full Code Here

Examples of org.apache.uima.analysis_engine.annotator.AnnotatorContextException

   */
  public InputStream getResourceAsStream(String aKey) throws AnnotatorContextException {
    try {
      return mUimaContext.getResourceAsStream(aKey);
    } catch (ResourceAccessException e) {
      throw new AnnotatorContextException(e);
    }
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.