001package javax.visrec.ml.classification; 002 003import javax.visrec.spi.ServiceProvider; 004 005/** 006 * Builder to create @{link Classifier} 007 * 008 * @author Kevin Berendsen 009 * @since 1.0 010 */ 011public abstract class ClassifierBuilder { 012 013 protected ClassifierBuilder() { 014 // Prevent instantiation outside of subclasses. 015 } 016 017 /** 018 * Creates a new instance of the builder. 019 * @return the builder 020 */ 021 public static ClassifierBuilder newBuilder() { 022 return ServiceProvider.current().getBuilderService().newClassifierBuilder(); 023 } 024 025 /** 026 * Set the trained model to be used during the image classification. 027 * 028 * TODO Add the proper class to the method signature. 029 * 030 * @param trainedModel the object of the trained model. 031 * @return current builder instance 032 */ 033 public abstract ClassifierBuilder trainedModel(Object trainedModel); 034 035 /** 036 * Create the {@link Classifier} that is able to use {@code sourceClss} as input/source type and 037 * {@code returnCls} as return type of the {@link Classifier} 038 * 039 * @param sourceCls {@link Class} object of the incoming input/source. 040 * @param returnCls {@link Class} object of the return type of the {@link Classifier} 041 * @param <T> source type class of the {@link Classifier} 042 * @param <R> return type class of the {@link Classifier} 043 * @return {@link Classifier} object. 044 */ 045 public abstract <T, R> Classifier<T, R> buildWithSourceType(final Class<T> sourceCls, final Class<R> returnCls); 046 047 /** 048 * Create the {@link Classifier} that is able to use {@code sourceClss} as input/source type and 049 * {@link String} as default return type of the {@link Classifier} 050 * 051 * @param sourceCls {@link Class} object of the incoming input/source. 052 * @param <T> source type class of the {@link Classifier} 053 * @return {@link Classifier} object. 054 */ 055 public final <T> Classifier<T, String> buildWithSourceType(final Class<T> sourceCls) { 056 return buildWithSourceType(sourceCls, String.class); 057 } 058}