public static TextClassifier getClassifier ( File resourceDirectoryFile ) throws Exception { // check whether we need to unzip the resources first if ( resourceDirectoryFile . toString ( ) . endsWith ( ".zip" ) && resourceDirectoryFile . isFile ( ) ) { resourceDirectoryFile = UnZip . unzip ( resourceDirectoryFile ) ; } // check the existence of the path if ( resourceDirectoryFile . exists ( ) == false ) throw new IOException ( "Directory " + resourceDirectoryFile . getAbsolutePath ( ) + " does not exist" ) ; // check that the lexicon files exists (e.g. its name should be simply // 'lexicon') File lexiconFile = new File ( resourceDirectoryFile , Parameters . lexiconName ) ; if ( lexiconFile . exists ( ) == false ) throw new IOException ( "Lexicon " + lexiconFile + " does not exist" ) ; // and that there is a model file File modelFile = new File ( resourceDirectoryFile , Parameters . modelName ) ; if ( modelFile . exists ( ) == false ) throw new IOException ( "Model " + modelFile + " does not exist" ) ; Lexicon lexicon = new Lexicon ( lexiconFile . toString ( ) ) ; // ask the Lexicon for the classifier to use String classifier = lexicon . getClassifierType ( ) ; TextClassifier instance = ( TextClassifier ) Class . forName ( classifier ) . newInstance ( ) ; // set the last modification info instance . lastmodifiedLexicon = lexiconFile . lastModified ( ) ; // set the pathResourceDirectory instance . pathResourceDirectory = resourceDirectoryFile . getAbsolutePath ( ) ; // set the model instance . lexicon = lexicon ; instance . loadModel ( ) ; return instance ; }
Returns a specific instance of a Text Classifier given a resource Directory