11package sentiment .models ;
22
3+ import org .slf4j .Logger ;
4+ import org .slf4j .LoggerFactory ;
35import sentiment .preprocessing .TextPreprocessor ;
46import sentiment .preprocessing .WekaInstancesConverter ;
57import sentiment .training .TrainingMetadata ;
1820 */
1921public class ModelLoader {
2022
23+ private static final Logger logger = LoggerFactory .getLogger (ModelLoader .class );
24+
2125 /**
2226 * Load model with metadata validation.
2327 * Throws exception if metadata file is missing (non-negotiable requirement).
@@ -43,23 +47,22 @@ public static SentimentClassifier loadWithMetadata(String modelPath)
4347
4448 // Load metadata first
4549 TrainingMetadata metadata = TrainingMetadata .load (metadataPath );
46- System . out . printf ( "✓ Loaded metadata: %s , trained on %s , accuracy=%.3f%n " ,
50+ logger . info ( " Loaded metadata: {} , trained on {} , accuracy={} " ,
4751 metadata .getModelId (),
4852 metadata .getDataset ().datasetName ,
49- metadata .getMetrics ().testAccuracy );
53+ String . format ( "%.3f" , metadata .getMetrics ().testAccuracy ) );
5054
5155 // Validate metadata points to correct model file
5256 if (metadata .getModelFile () != null &&
5357 !metadata .getModelFile ().equals (path .getFileName ().toString ())) {
54- System . err . printf ( "⚠ Metadata model_file mismatch: expected %s , got %s%n " ,
58+ logger . warn ( " Metadata model_file mismatch: expected {} , got {} " ,
5559 metadata .getModelFile (), path .getFileName ());
5660 }
5761
5862 // Load the actual model based on algorithm type
5963 SentimentClassifier classifier = loadModelByType (path , metadata );
6064
61- System .out .printf ("✓ Loaded model: %s from %s%n" ,
62- path .getFileName (), path .getParent ());
65+ logger .info ("Loaded model: {} from {}" , path .getFileName (), path .getParent ());
6366
6467 return classifier ;
6568 }
@@ -141,7 +144,7 @@ public static java.util.Map<String, SentimentClassifier> loadAllForAlgorithm(Str
141144 Path algoDir = Paths .get ("models" , algorithm );
142145
143146 if (!Files .exists (algoDir )) {
144- System . err . println ( "⚠ Model directory not found: " + algoDir );
147+ logger . warn ( " Model directory not found: {}" , algoDir );
145148 return models ;
146149 }
147150
@@ -157,10 +160,10 @@ public static java.util.Map<String, SentimentClassifier> loadAllForAlgorithm(Str
157160 SentimentClassifier classifier = loadWithMetadata (modelPath .toString ());
158161 models .put (domain , classifier );
159162
160- System . out . printf ( "✓ Loaded %s model trained on %s%n " , algorithm , domain );
163+ logger . info ( " Loaded {} model trained on {} " , algorithm , domain );
161164
162165 } catch (Exception e ) {
163- System . err . println ( "✗ Failed to load " + modelPath + ": " + e .getMessage ());
166+ logger . error ( " Failed to load {}: {}" , modelPath , e .getMessage ());
164167 }
165168 });
166169 }
0 commit comments