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()); }
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()); }
/** * Adds a view that is generated by a {@link Annotator} */ public void addView(Annotator annotator) throws AnnotatorException { addView(annotator.getViewName(), annotator.getView(this)); }
/** * Adds a view that is generated by a {@link Annotator} */ public void addView(Annotator annotator) throws AnnotatorException { addView(annotator.getViewName(), annotator.getView(this)); }
/** * 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 ); }
/** * 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 ); }
@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; }
@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; }
viewProviders.put(annotator.getViewName(), annotator);
viewProviders.put(annotator.getViewName(), annotator);
/** * 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; }
/** * 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; }
textAnnotation.addView(annotator.getViewName(), v); } else processBySentence(annotator, textAnnotation);
textAnnotation.addView(annotator.getViewName(), v); } else processBySentence(annotator, textAnnotation);
/** * Process each sentence individually. This potentially allows for failure at an individual * sentence level, without failing for the whole text. THIS REQUIRES THAT ALL RELATIONS ARE * INTRA-SENTENCE. Any that are *not* will be omitted for the sentence-level processing. * * @param annotator Annotator to apply * @param textAnnotation TextAnnotation to augment * @return */ public void processBySentence(Annotator annotator, TextAnnotation textAnnotation) { logger.debug("in processBySentence()..."); for (int sentenceId = 0; sentenceId < textAnnotation.sentences().size(); ++sentenceId) { TextAnnotation sentTa = TextAnnotationUtilities.getSubTextAnnotation(textAnnotation, sentenceId); try { annotator.getView(sentTa); int start = textAnnotation.getSentence(sentenceId).getStartSpan(); int end = textAnnotation.getSentence(sentenceId).getEndSpan(); TextAnnotationUtilities.copyViewFromTo(annotator.getViewName(), sentTa, textAnnotation, start, end, start); } catch (AnnotatorException e) { e.printStackTrace(); } } return; }
/** * Process each sentence individually. This potentially allows for failure at an individual * sentence level, without failing for the whole text. THIS REQUIRES THAT ALL RELATIONS ARE * INTRA-SENTENCE. Any that are *not* will be omitted for the sentence-level processing. * * @param annotator Annotator to apply * @param textAnnotation TextAnnotation to augment * @return */ public void processBySentence(Annotator annotator, TextAnnotation textAnnotation) { logger.debug("in processBySentence()..."); for (int sentenceId = 0; sentenceId < textAnnotation.sentences().size(); ++sentenceId) { TextAnnotation sentTa = TextAnnotationUtilities.getSubTextAnnotation(textAnnotation, sentenceId); try { annotator.getView(sentTa); int start = textAnnotation.getSentence(sentenceId).getStartSpan(); int end = textAnnotation.getSentence(sentenceId).getEndSpan(); TextAnnotationUtilities.copyViewFromTo(annotator.getViewName(), sentTa, textAnnotation, start, end, start); } catch (AnnotatorException e) { e.printStackTrace(); } } return; }