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()); }
/** Removes the label from the NER_GOLD_EXTENT_SPAN. */ private static List<TextAnnotation> removeLabelsForNER(List<TextAnnotation> cleansedAnnotations) { List<String> nerViews = new ArrayList<>(); nerViews.add(ViewNames.SENTENCE); nerViews.add(ViewNames.TOKENS); nerViews.add("NER_GOLD_EXTENT_SPAN"); List<TextAnnotation> textAnnotations = removeViews(cleansedAnnotations, nerViews); for (TextAnnotation textAnnotation : textAnnotations) { View view = textAnnotation.getView("NER_GOLD_EXTENT_SPAN"); List<Constituent> constituents = view.getConstituents(); for (Constituent c : constituents) { view.removeConstituent(c); int start = c.getStartSpan(); int end = c.getEndSpan(); view.addConstituent( new Constituent("", "NER_GOLD_EXTENT_SPAN", textAnnotation, start, end)); } textAnnotation.addView(view.getViewName(), view); } return textAnnotations; }
/** Removes all coreference relations from {@code COREF} View. */ private static List<TextAnnotation> removeCoreferenceRelations( List<TextAnnotation> uncleansedAnnotations) { List<String> coreferenceViews = new ArrayList<>(); coreferenceViews.add(ViewNames.SENTENCE); coreferenceViews.add(ViewNames.TOKENS); coreferenceViews.add(ViewNames.COREF); List<TextAnnotation> textAnnotations = removeViews(uncleansedAnnotations, coreferenceViews); for (TextAnnotation textAnnotation : textAnnotations) { Set<String> viewNames = textAnnotation.getAvailableViews(); for (String viewName : viewNames) { View view = textAnnotation.getView(viewName); if (view instanceof CoreferenceView) { CoreferenceView coreferenceView = (CoreferenceView) view; coreferenceView.removeAllRelations(); textAnnotation.addView(viewName, coreferenceView); } } } return textAnnotations; }