public static LanguageDetectorModel trainModel() throws Exception { return trainModel(new LanguageDetectorFactory()); }
public static LanguageDetectorFactory create(String subclassName) throws InvalidFormatException { if (subclassName == null) { // will create the default factory return new LanguageDetectorFactory(); } try { LanguageDetectorFactory theFactory = ExtensionLoader.instantiateExtension( LanguageDetectorFactory.class, subclassName); theFactory.init(); return theFactory; } catch (Exception e) { String msg = "Could not instantiate the " + subclassName + ". The initialization throw an exception."; throw new InvalidFormatException(msg, e); } }
@Test public void evaluate() throws Exception { TrainingParameters params = new TrainingParameters(); params.put(TrainingParameters.ITERATIONS_PARAM, 100); params.put(TrainingParameters.CUTOFF_PARAM, 5); params.put("PrintMessages", false); final AtomicInteger correctCount = new AtomicInteger(); final AtomicInteger incorrectCount = new AtomicInteger(); LanguageDetectorCrossValidator cv = new LanguageDetectorCrossValidator(params, new LanguageDetectorFactory(), new LanguageDetectorEvaluationMonitor() { @Override public void correctlyClassified(LanguageSample reference, LanguageSample prediction) { correctCount.incrementAndGet(); } @Override public void missclassified(LanguageSample reference, LanguageSample prediction) { incorrectCount.incrementAndGet(); } }); LanguageDetectorSampleStream sampleStream = LanguageDetectorMETest.createSampleStream(); cv.evaluate(sampleStream, 2); Assert.assertEquals(99, cv.getDocumentCount()); Assert.assertEquals(0.98989898989899, cv.getDocumentAccuracy(), 0.01); }
public static LanguageDetectorFactory create(String subclassName) throws InvalidFormatException { if (subclassName == null) { // will create the default factory return new LanguageDetectorFactory(); } try { LanguageDetectorFactory theFactory = ExtensionLoader.instantiateExtension( LanguageDetectorFactory.class, subclassName); theFactory.init(); return theFactory; } catch (Exception e) { String msg = "Could not instantiate the " + subclassName + ". The initialization throw an exception."; throw new InvalidFormatException(msg, e); } }
public static LanguageDetectorFactory create(String subclassName) throws InvalidFormatException { if (subclassName == null) { // will create the default factory return new LanguageDetectorFactory(); } try { LanguageDetectorFactory theFactory = ExtensionLoader.instantiateExtension( LanguageDetectorFactory.class, subclassName); theFactory.init(); return theFactory; } catch (Exception e) { String msg = "Could not instantiate the " + subclassName + ". The initialization throw an exception."; throw new InvalidFormatException(msg, e); } }