BrownClusterViewGenerator extends Annotator { @Override public void addView(TextAnnotation ta) { lazyLoadClusters(); SpanLabelView view = new SpanLabelView(getViewName(), "BrownClusters", ta, 1.0, true); Map<String, List<IntPair>> m = getMatchingSpans(ta); for (Entry<String, List<IntPair>> entry : m.entrySet()) { String label = entry.getKey(); Set<IntPair> added = new LinkedHashSet<>(); for (IntPair p : entry.getValue()) { boolean foundContainer = false; for (IntPair p1 : added) { if (p1 == p) continue; if (p1.getFirst() <= p.getFirst() && p1.getSecond() >= p.getSecond()) { foundContainer = true; break; } } if (!foundContainer) { view.addSpanLabel(p.getFirst(), p.getSecond(), label, 1.0); added.add(p); } } } ta.addView(getViewName(), view); } BrownClusterViewGenerator(String name, String file);  BrownClusterViewGenerator(String name, String file, ResourceManager nonDefaultRm);  BrownClusterViewGenerator(String name, String file, boolean gzip);  BrownClusterViewGenerator(String name, String file, boolean gzip, ResourceManager nonDefaultRm); void loadFromDataStore(); @Override void initialize(ResourceManager rm); @Override void addView(TextAnnotation ta); @Override String[] getRequiredViews(); final static String file100; final static String file320; final static String file1000; final static String file3200; }
@Test public final void testCharniakParseViewGenerator() { String sentence = "a test ."; TextAnnotation ta = TextAnnotationUtilities.createFromTokenizedString(sentence); BrownClusterViewGenerator viewGenerator = null; try { viewGenerator = new BrownClusterViewGenerator(BrownClusterViewGenerator.file100, BrownClusterViewGenerator.file100); viewGenerator.addView(ta); } catch (Exception e) { e.printStackTrace(); } SpanLabelView view = (SpanLabelView) ta.getView(viewGenerator.getViewName()); assertEquals("a", view.getConstituents().get(0).getSurfaceForm()); assertEquals("111011111", view.getConstituents().get(0).getLabel()); assertEquals("a", view.getConstituents().get(1).getSurfaceForm()); assertEquals("10010", view.getConstituents().get(1).getLabel()); assertEquals("test", view.getConstituents().get(2).getSurfaceForm()); assertEquals("001110", view.getConstituents().get(2).getLabel()); Properties props = new Properties(); props.setProperty(BrownClusterViewGeneratorConfigurator.NORMALIZE_TOKEN.key, Configurator.FALSE); ResourceManager rm = new ResourceManager(props); try { viewGenerator = new BrownClusterViewGenerator(BrownClusterViewGenerator.file100, BrownClusterViewGenerator.file100, rm); viewGenerator.addView(ta); } catch (Exception e) { e.printStackTrace(); } view = (SpanLabelView) ta.getView(viewGenerator.getViewName()); assertEquals("a", view.getConstituents().get(0).getSurfaceForm()); assertEquals("10010", view.getConstituents().get(0).getLabel()); assertEquals("test", view.getConstituents().get(1).getSurfaceForm()); assertEquals("001110", view.getConstituents().get(1).getLabel()); }