/** * Adds a view that is generated by a {@link Annotator} */ public void addView(Annotator annotator) throws AnnotatorException { addView(annotator.getViewName(), annotator.getView(this)); }
/** * Same lazy view function, but with resource parameters * First, checks whether model is initialized, and calls initialize() if not. Then, calls * addView(). IMPORTANT: clients should always call getView(). */ private void lazyAddView(TextAnnotation ta, ResourceManager runtimeAttributes) throws AnnotatorException { if (!isInitialized()) { doInitialize(); } addView(ta, runtimeAttributes); }
/** * If you want lazy initialization, this method must load the component models/resources, * Default implementation just sets the relevant field to 'true'. */ final public void doInitialize() { initialize(config); isInitialized = true; }
@Override public boolean addView(TextAnnotation textAnnotation, String viewName, ResourceManager runtimeAttributes) throws AnnotatorException { boolean isUpdated = false; if (ViewNames.SENTENCE.equals(viewName) || ViewNames.TOKENS.equals(viewName)) return false; if ( !textAnnotation.hasView( viewName ) || forceUpdate ) { isUpdated = true; if ( !viewProviders.containsKey(viewName) ) throw new AnnotatorException( "View '" + viewName + "' cannot be provided by this AnnotatorService." ); Annotator annotator = viewProviders.get( viewName ); for ( String prereqView : annotator.getRequiredViews() ) { addView( textAnnotation, prereqView, runtimeAttributes); } View v = annotator.getView(textAnnotation, runtimeAttributes); textAnnotation.addView( annotator.getViewName(), v ); } if (isUpdated && throwExceptionIfNotCached) throwNotCachedException(textAnnotation.getCorpusId(), textAnnotation.getId(), textAnnotation.getText()); return isUpdated; }
for (String prereqView : annotator.getRequiredViews()) { addView(textAnnotation, prereqView); if (!annotator.isSentenceLevel()) { v = annotator.getView(textAnnotation); textAnnotation.addView(annotator.getViewName(), v); } else processBySentence(annotator, textAnnotation);
/** * Add a new {@link Annotator} to the service. All prerequisite views must already be provided by other annotators * known to this {@link AnnotatorService}. * * @param annotator the {@link Annotator} to be added. * @throws {@link AnnotatorException} if the annotator requires views that cannot be satisfied. */ @Override public void addAnnotator(Annotator annotator) throws AnnotatorException { String[] prerequisites = annotator.getRequiredViews(); for ( String pre : prerequisites ) if ( !this.getAvailableViews().contains( pre ) ) throw new AnnotatorException("Missing prerequisite: " + pre ); this.viewProviders.put( annotator.getViewName(), annotator ); }
private static TreeView getDependencyView(TextAnnotation ta, Annotator viewGenerator) { if (!ta.hasView(viewGenerator.getViewName())) { synchronized (FeatureInputTransformer.class) { if (!ta.hasView(viewGenerator.getViewName())) { try { ta.addView(viewGenerator); } catch (AnnotatorException e) { throw new RuntimeException(e); } } } } return (TreeView) ta.getView(viewGenerator.getViewName()); }
/** * Add a new {@link Annotator} to the service. All prerequisite views must already be provided by other annotators * known to this {@link AnnotatorService}. * * @param annotator the {@link Annotator} to be added. * @throws {@link AnnotatorException} if the annotator requires views that cannot be satisfied. */ @Override public void addAnnotator(Annotator annotator) throws AnnotatorException { for ( String prereq : annotator.getRequiredViews() ) if ( !viewProviders.containsKey( prereq ) ) throw new AnnotatorException( "Prerequisite view '" + prereq + "' is not provided by other annotators." ); }
/** * some annotators have complex initialization, so will have to pass a ResourceManager to be on * hand for their initialization if non-lazy initialization is desired. * * @param viewName The name of the View this annotator will populate. This will be used to * access the created view from the TextAnnotation holding it. * @param requiredViews The views that must be populated for this new view to be created. * @param isLazilyInitialized if 'true', defers the initialization of the derived class until * getView() is called. * @param config these properties are stored for use by derived class, esp. in * initialize() */ public Annotator(String viewName, String[] requiredViews, boolean isLazilyInitialized, ResourceManager config) { this.viewName = viewName; this.requiredViews = requiredViews; this.config = config; isSentenceLevel = true; isInitialized = false; if (!isLazilyInitialized) doInitialize(); }
/** Add the content of the annotators to a given TextAnnotation object. @param runtimeAttributes the parameters that might change the behavior of the annotator while after initialization and while running. */ protected void addView(TextAnnotation ta, ResourceManager runtimeAttributes) throws AnnotatorException { logger.warn("This annotator does not accept run-time attributes. You have to run `addView() function without the attributes parameter. `"); addView(ta); }
@Override public boolean addView(TextAnnotation textAnnotation, String viewName, ResourceManager runtimeAttributes) throws AnnotatorException { boolean isUpdated = false; if (ViewNames.SENTENCE.equals(viewName) || ViewNames.TOKENS.equals(viewName)) return false; if ( !textAnnotation.hasView( viewName ) || forceUpdate ) { isUpdated = true; if ( !viewProviders.containsKey(viewName) ) throw new AnnotatorException( "View '" + viewName + "' cannot be provided by this AnnotatorService." ); Annotator annotator = viewProviders.get( viewName ); for ( String prereqView : annotator.getRequiredViews() ) { addView( textAnnotation, prereqView, runtimeAttributes); } View v = annotator.getView(textAnnotation, runtimeAttributes); textAnnotation.addView( annotator.getViewName(), v ); } if (isUpdated && throwExceptionIfNotCached) throwNotCachedException(textAnnotation.getCorpusId(), textAnnotation.getId(), textAnnotation.getText()); return isUpdated; }
for (String prereqView : annotator.getRequiredViews()) { addView(textAnnotation, prereqView); if (!annotator.isSentenceLevel()) { v = annotator.getView(textAnnotation); textAnnotation.addView(annotator.getViewName(), v); } else processBySentence(annotator, textAnnotation);
/** * Add a new {@link Annotator} to the service. All prerequisite views must already be provided by other annotators * known to this {@link AnnotatorService}. * * @param annotator the {@link Annotator} to be added. * @throws {@link AnnotatorException} if the annotator requires views that cannot be satisfied. */ @Override public void addAnnotator(Annotator annotator) throws AnnotatorException { String[] prerequisites = annotator.getRequiredViews(); for ( String pre : prerequisites ) if ( !this.getAvailableViews().contains( pre ) ) throw new AnnotatorException("Missing prerequisite: " + pre ); this.viewProviders.put( annotator.getViewName(), annotator ); }
private static TreeView getDependencyView(TextAnnotation ta, Annotator viewGenerator) { if (!ta.hasView(viewGenerator.getViewName())) { synchronized (FeatureInputTransformer.class) { if (!ta.hasView(viewGenerator.getViewName())) { try { ta.addView(viewGenerator); } catch (AnnotatorException e) { throw new RuntimeException(e); } } } } return (TreeView) ta.getView(viewGenerator.getViewName()); }
/** * Add a new {@link Annotator} to the service. All prerequisite views must already be provided by other annotators * known to this {@link AnnotatorService}. * * @param annotator the {@link Annotator} to be added. * @throws {@link AnnotatorException} if the annotator requires views that cannot be satisfied. */ @Override public void addAnnotator(Annotator annotator) throws AnnotatorException { for ( String prereq : annotator.getRequiredViews() ) if ( !viewProviders.containsKey( prereq ) ) throw new AnnotatorException( "Prerequisite view '" + prereq + "' is not provided by other annotators." ); }
/** * some annotators have complex initialization, so will have to pass a ResourceManager to be on * hand for their initialization if non-lazy initialization is desired. * * @param viewName The name of the View this annotator will populate. This will be used to * access the created view from the TextAnnotation holding it. * @param requiredViews The views that must be populated for this new view to be created. * @param isLazilyInitialized if 'true', defers the initialization of the derived class until * getView() is called. * @param config these properties are stored for use by derived class, esp. in * initialize() */ public Annotator(String viewName, String[] requiredViews, boolean isLazilyInitialized, ResourceManager config) { this.viewName = viewName; this.requiredViews = requiredViews; this.config = config; isSentenceLevel = true; isInitialized = false; if (!isLazilyInitialized) doInitialize(); }
/** Add the content of the annotators to a given TextAnnotation object. @param runtimeAttributes the parameters that might change the behavior of the annotator while after initialization and while running. */ protected void addView(TextAnnotation ta, ResourceManager runtimeAttributes) throws AnnotatorException { logger.warn("This annotator does not accept run-time attributes. You have to run `addView() function without the attributes parameter. `"); addView(ta); }
/** * DOES NOT CACHE THE ADDED VIEW!!! * * @param textAnnotation textAnnotation to be modified * @param viewName name of view to be added * @return 'true' if textAnnotation was modified * @throws AnnotatorException */ @Override public boolean addView(TextAnnotation textAnnotation, String viewName) throws AnnotatorException { boolean isUpdated = false; if (ViewNames.SENTENCE.equals(viewName) || ViewNames.TOKENS.equals(viewName)) return false; if ( !textAnnotation.hasView( viewName ) || forceUpdate ) { isUpdated = true; if ( !viewProviders.containsKey(viewName) ) throw new AnnotatorException( "View '" + viewName + "' cannot be provided by this AnnotatorService." ); Annotator annotator = viewProviders.get( viewName ); for ( String prereqView : annotator.getRequiredViews() ) { addView( textAnnotation, prereqView ); } View v = annotator.getView(textAnnotation); textAnnotation.addView( annotator.getViewName(), v ); } if (isUpdated && throwExceptionIfNotCached) throwNotCachedException(textAnnotation.getCorpusId(), textAnnotation.getId(), textAnnotation.getText()); return isUpdated; }
/** * Adds a view that is generated by a {@link Annotator} */ public void addView(Annotator annotator) throws AnnotatorException { addView(annotator.getViewName(), annotator.getView(this)); }
/** * First, checks whether model is initialized, and calls initialize() if not. Then, calls * addView(). IMPORTANT: clients should always call getView(). * * @param ta */ private void lazyAddView(TextAnnotation ta) throws AnnotatorException { if (!isInitialized()) { doInitialize(); } addView(ta); }