GenericAnalyzerAssembler extends AssemblerBase { @Override public Analyzer open(Assembler a, Resource root, Mode mode) { if (root.hasProperty(TextVocab.pClass)) { String className = root.getProperty(TextVocab.pClass).getString(); Class<?> clazz = null; try { clazz = Class.forName(className); } catch (ClassNotFoundException e) { Log.error(this, "Analyzer class " + className + " not found. " + e.getMessage(), e); return null; } if (!Analyzer.class.isAssignableFrom(clazz)) { Log.error(this, clazz.getName() + " has to be a subclass of " + Analyzer.class.getName()); return null; } if (root.hasProperty(TextVocab.pParams)) { RDFNode node = root.getProperty(TextVocab.pParams).getObject(); if (! node.isResource()) { throw new TextIndexException("text:params must be a list of parameter resources: " + node); } List<Params.ParamSpec> specs = Params.getParamSpecs((Resource) node); final Class<?> paramClasses[] = new Class<?>[specs.size()]; final Object paramValues[] = new Object[specs.size()]; for (int i = 0; i < specs.size(); i++) { Params.ParamSpec spec = specs.get(i); paramClasses[i] = spec.getValueClass(); paramValues[i] = spec.getValue(); } return newAnalyzer(clazz, paramClasses, paramValues); } else { return newAnalyzer(clazz, new Class<?>[0], new Object[0]); } } else { throw new TextIndexException("text:class property is required by GenericAnalyzer: " + root); } }  @Override Analyzer open(Assembler a, Resource root, Mode mode);  }
@Test public void AnalyzerNullaryCtor() { GenericAnalyzerAssembler gaAssem = new GenericAnalyzerAssembler(); Analyzer analyzer = gaAssem.open(null, spec1, null); assertEquals(SimpleAnalyzer.class, analyzer.getClass()); }
@Test public void AnalyzerNullaryCtor2() { GenericAnalyzerAssembler gaAssem = new GenericAnalyzerAssembler(); Analyzer analyzer = gaAssem.open(null, spec2, null); assertEquals(FrenchAnalyzer.class, analyzer.getClass()); }
@Test public void AnalyzerCtorSet1() { GenericAnalyzerAssembler gaAssem = new GenericAnalyzerAssembler(); Analyzer analyzer = gaAssem.open(null, spec3, null); assertEquals(FrenchAnalyzer.class, analyzer.getClass()); }
@Test public void AnalyzerCtorAnalyzerInt() { GenericAnalyzerAssembler gaAssem = new GenericAnalyzerAssembler(); Analyzer analyzer = gaAssem.open(null, spec4, null); assertEquals(ShingleAnalyzerWrapper.class, analyzer.getClass()); }
@Test public void AnalyzerCtorShingle7() { GenericAnalyzerAssembler gaAssem = new GenericAnalyzerAssembler(); Analyzer analyzer = gaAssem.open(null, spec5, null); assertEquals(ShingleAnalyzerWrapper.class, analyzer.getClass()); }
@Test public void AnalyzerCtorFile() { GenericAnalyzerAssembler gaAssem = new GenericAnalyzerAssembler(); Analyzer analyzer = gaAssem.open(null, spec6, null); assertEquals(StopAnalyzer.class, analyzer.getClass()); }