public static Learner getLearner ( String workdirectory , String implementationName , boolean overwrite ) throws Exception { File directory = new File ( workdirectory ) ; if ( directory . exists ( ) == false ) throw new Exception ( workdirectory + " must exist" ) ; if ( directory . isDirectory ( ) == false ) throw new Exception ( workdirectory + " must be a directory" ) ; // create the file names String model_file_name = workdirectory + File . separator + Parameters . modelName ; String lexicon_file_name = workdirectory + File . separator + Parameters . lexiconName ; String vector_file_name = workdirectory + File . separator + Parameters . vectorName ; String raw_file_name = workdirectory + File . separator + Parameters . rawName ; Learner learner = null ; // removes existing files for lexicon model and vector if ( overwrite ) { removeExistingFile ( model_file_name ) ; removeExistingFile ( lexicon_file_name ) ; removeExistingFile ( vector_file_name ) ; removeExistingFile ( raw_file_name ) ; } // define which implementation to use if ( LibSVMModelCreator . equals ( implementationName ) ) learner = new LibSVMModelCreator ( lexicon_file_name , model_file_name , vector_file_name ) ; else if ( LibLinearModelCreator . equals ( implementationName ) ) learner = new LibLinearModelCreator ( lexicon_file_name , model_file_name , vector_file_name ) ; else throw new Exception ( implementationName + " is unknown" ) ; // reuse the existing lexicon if ( ! overwrite ) { Lexicon oldlexicon = new Lexicon ( lexicon_file_name ) ; if ( oldlexicon != null ) learner . lexicon = oldlexicon ; } learner . workdirectory = directory ; return learner ; }
Generate an instance of Learner from an existing directory .