@Test public void testMultiThreading() throws IOException, URISyntaxException, AnnotatorException { final SimpleGazetteerAnnotator sga = new SimpleGazetteerAnnotator(defaultRm); class TestThread extends Thread { Throwable throwable; public void run() { long start = System.currentTimeMillis(); while (true) { final TextAnnotation ta = tab.createTextAnnotation("I hail from the university of illinois at champaign urbana."); try { sga.addView(ta); } catch (AnnotatorException e) { throwable = e; return; } SpanLabelView view = (SpanLabelView) ta.getView(ViewNames.TREE_GAZETTEER); List<Constituent> entities = view.getConstituents(); Constituent c1 = entities.get(0); try { assertEquals(c1.toString(), "university of illinois"); Constituent c2 = entities.get(1); assertEquals(c2.toString(), "university of illinois at champaign urbana"); Constituent c3 = entities.get(2); assertEquals(c3.toString(), "illinois"); Constituent c4 = entities.get(3); assertEquals(c4.toString(), "champaign"); Constituent c5 = entities.get(4); assertEquals(c5.toString(), "urbana"); assertEquals(c1.getLabel(), "organizations(IC)"); assertEquals(c2.getLabel(), "organizations(IC)"); assertEquals(c3.getLabel(), "places(IC)"); assertEquals(c4.getLabel(), "places(IC)"); assertEquals(c5.getLabel(), "places(IC)"); if ((System.currentTimeMillis() - start) > 10000l) { throwable = null; return; } } catch (AssertionError ae) { throwable = ae; ae.printStackTrace(); return; } } } } final int numthreads = 20; TestThread[] threads = new TestThread[numthreads]; for (int i = 0; i < numthreads; i++) { threads[i] = new TestThread(); threads[i].start(); } logger.info("Begin multithreaded test."); for (int i = 0; i < numthreads; i++) { while (true) try { threads[i].join(); assertEquals("Exception during multithreading test : " + threads[i].throwable, threads[i].throwable, null); break; } catch (InterruptedException e) { continue; } } }
@Override public void addView(TextAnnotation ta) throws AnnotatorException { View view = ta.getView(ViewNames.TOKENS); List<Constituent> constituents = view.getConstituents(); SpanLabelView slv = new SpanLabelView(this.getViewName(), this.getClass().getName(), ta, 1d, true); for (int constindx = 0; constindx < constituents.size(); constindx++) { for (int dictindx = 0; dictindx < dictionaries.size(); dictindx++) { dictionaries.get(dictindx).match(constituents, constindx, slv); dictionariesIgnoreCase.get(dictindx).match(constituents, constindx, slv); } } ta.addView(slv.getViewName(), slv); }
SimpleGazetteerAnnotator extends Annotator { @Override public void addView(TextAnnotation ta) throws AnnotatorException { View view = ta.getView(ViewNames.TOKENS); List<Constituent> constituents = view.getConstituents(); SpanLabelView slv = new SpanLabelView(this.getViewName(), this.getClass().getName(), ta, 1d, true); for (int constindx = 0; constindx < constituents.size(); constindx++) { for (int dictindx = 0; dictindx < dictionaries.size(); dictindx++) { dictionaries.get(dictindx).match(constituents, constindx, slv); dictionariesIgnoreCase.get(dictindx).match(constituents, constindx, slv); } } ta.addView(slv.getViewName(), slv); } }
SimpleGazetteerAnnotator extends Annotator { @Override public void addView(TextAnnotation ta) throws AnnotatorException { View view = ta.getView(ViewNames.TOKENS); List<Constituent> constituents = view.getConstituents(); SpanLabelView slv = new SpanLabelView(this.getViewName(), this.getClass().getName(), ta, 1d, true); for (int constindx = 0; constindx < constituents.size(); constindx++) { for (int dictindx = 0; dictindx < dictionaries.size(); dictindx++) { dictionaries.get(dictindx).match(constituents, constindx, slv); dictionariesIgnoreCase.get(dictindx).match(constituents, constindx, slv); } } ta.addView(slv.getViewName(), slv); } SimpleGazetteerAnnotator();  SimpleGazetteerAnnotator(ResourceManager nonDefaultRm); }
SimpleGazetteerAnnotator extends Annotator { @Override public void addView(TextAnnotation ta) throws AnnotatorException { View view = ta.getView(ViewNames.TOKENS); List<Constituent> constituents = view.getConstituents(); SpanLabelView slv = new SpanLabelView(this.getViewName(), this.getClass().getName(), ta, 1d, true); for (int constindx = 0; constindx < constituents.size(); constindx++) { for (int dictindx = 0; dictindx < dictionaries.size(); dictindx++) { dictionaries.get(dictindx).match(constituents, constindx, slv); dictionariesIgnoreCase.get(dictindx).match(constituents, constindx, slv); } } ta.addView(slv.getViewName(), slv); } SimpleGazetteerAnnotator();  SimpleGazetteerAnnotator(ResourceManager nonDefaultRm); URL[] listGazetteers(String resourceDir); @Override void initialize(ResourceManager rm); @Override void addView(TextAnnotation ta); }
SimpleGazetteerAnnotator extends Annotator { @Override public void addView(TextAnnotation ta) throws AnnotatorException { View view = ta.getView(ViewNames.TOKENS); List<Constituent> constituents = view.getConstituents(); SpanLabelView slv = new SpanLabelView(this.getViewName(), this.getClass().getName(), ta, 1d, true); for (int constindx = 0; constindx < constituents.size(); constindx++) { for (int dictindx = 0; dictindx < dictionaries.size(); dictindx++) { dictionaries.get(dictindx).match(constituents, constindx, slv); dictionariesIgnoreCase.get(dictindx).match(constituents, constindx, slv); } } ta.addView(slv.getViewName(), slv); } SimpleGazetteerAnnotator();  SimpleGazetteerAnnotator(ResourceManager nonDefaultRm); URL[] listGazetteers(String resourceDir); @Override void initialize(ResourceManager rm); @Override void addView(TextAnnotation ta);  }