2424 */
2525public class CrossDomainEvaluator {
2626
27+ private static final ObjectMapper MAPPER = new ObjectMapper ()
28+ .enable (SerializationFeature .INDENT_OUTPUT );
29+
2730 private static final String [] TRAIN_DOMAINS = {"imdb_50k" , "amazon_polarity" , "yelp" };
2831 private static final String [] TEST_DOMAINS = {"imdb_50k" , "amazon_polarity" , "yelp" };
2932 private static final String [] ALGORITHMS = {"svm" , "naive_bayes" , "random_forest" , "logistic_regression" };
@@ -196,7 +199,7 @@ public String generateReport() {
196199 var best = getBestGeneralizingModel ();
197200 if (best != null ) {
198201 sb .append ("═══════════════════════════════════════════════════════════════\n " );
199- sb .append ("🏆 BEST GENERALIZING MODEL\n " );
202+ sb .append ("BEST GENERALIZING MODEL\n " );
200203 sb .append ("═══════════════════════════════════════════════════════════════\n " );
201204 sb .append (String .format ("Model: %s%n" , best .getKey ()));
202205 sb .append (String .format ("Cross-Domain Avg Accuracy: %.3f%n" , best .getValue ()));
@@ -214,9 +217,6 @@ public String generateReport() {
214217 * Export to JSON
215218 */
216219 public void exportToJson (Path outputPath ) throws IOException {
217- ObjectMapper mapper = new ObjectMapper ();
218- mapper .enable (SerializationFeature .INDENT_OUTPUT );
219-
220220 Map <String , Object > export = new LinkedHashMap <>();
221221 export .put ("evaluated_at" , evaluatedAt .toString ());
222222 export .put ("domains" , Arrays .asList (TRAIN_DOMAINS ));
@@ -261,8 +261,8 @@ public void exportToJson(Path outputPath) throws IOException {
261261 export .put ("best_generalizing_model" , bestModel );
262262 }
263263
264- mapper .writeValue (outputPath .toFile (), export );
265- System .out .println ("✓ Cross-domain evaluation exported to: " + outputPath );
264+ MAPPER .writeValue (outputPath .toFile (), export );
265+ System .out .println ("Cross-domain evaluation exported to: " + outputPath );
266266 }
267267 }
268268
@@ -285,25 +285,25 @@ public static CrossDomainMatrix evaluateAll(
285285 for (String algo : ALGORITHMS ) {
286286 Map <String , SentimentClassifier > algoModels = models .get (algo );
287287 if (algoModels == null ) {
288- System .out .println ("⚠ No models found for algorithm: " + algo );
288+ System .out .println ("No models found for algorithm: " + algo );
289289 continue ;
290290 }
291291
292292 for (String trainDomain : TRAIN_DOMAINS ) {
293293 SentimentClassifier model = algoModels .get (trainDomain );
294294 if (model == null ) {
295- System .out .println ("⚠ No model found for " + algo + " trained on " + trainDomain );
295+ System .out .println ("No model found for " + algo + " trained on " + trainDomain );
296296 continue ;
297297 }
298298
299299 for (String testDomain : TEST_DOMAINS ) {
300300 currentEval ++;
301- System .out .printf ("[%d/%d] Evaluating %s (trained on %s) → testing on %s%n" ,
301+ System .out .printf ("[%d/%d] Evaluating %s (trained on %s) -> testing on %s%n" ,
302302 currentEval , totalEvaluations , algo , trainDomain , testDomain );
303303
304304 List <Dataset > testData = testDatasets .get (testDomain );
305305 if (testData == null ) {
306- System .out .println (" ⚠ No test data found for " + testDomain );
306+ System .out .println (" No test data found for " + testDomain );
307307 continue ;
308308 }
309309
@@ -372,7 +372,7 @@ public static CrossDomainMatrix evaluateAll(
372372 );
373373
374374 matrix .addResult (result );
375- System .out .printf (" ✓ Accuracy: %.3f | Brier: %.3f%s%n" ,
375+ System .out .printf (" Accuracy: %.3f | Brier: %.3f%s%n" ,
376376 result .accuracy , result .brierScore ,
377377 result .isInDomain ? " (in-domain)" : "" );
378378 }
@@ -388,9 +388,6 @@ public static CrossDomainMatrix evaluateAll(
388388 * Uses TrainingMetadata class to ensure correct JSON structure.
389389 */
390390 private static void persistToModelMetadata (CrossDomainMatrix matrix , Path modelsDir ) {
391- ObjectMapper mapper = new ObjectMapper ();
392- mapper .enable (SerializationFeature .INDENT_OUTPUT );
393-
394391 for (String algo : ALGORITHMS ) {
395392 for (String trainDomain : TRAIN_DOMAINS ) {
396393 // Build metadata file path
@@ -487,14 +484,14 @@ public static void main(String[] args) {
487484 if (fullData .size () > maxSamplesPerDomain ) {
488485 Collections .shuffle (fullData , new Random (42 )); // Reproducible sampling
489486 sampledData = fullData .subList (0 , maxSamplesPerDomain );
490- System .out .println ("✓ Loaded " + domain + ": " + sampledData .size () + " samples (sampled from " + fullData .size () + ") from " + testFile );
487+ System .out .println ("Loaded " + domain + ": " + sampledData .size () + " samples (sampled from " + fullData .size () + ") from " + testFile );
491488 } else {
492- System .out .println ("✓ Loaded " + domain + ": " + sampledData .size () + " samples from " + testFile );
489+ System .out .println ("Loaded " + domain + ": " + sampledData .size () + " samples from " + testFile );
493490 }
494491
495492 testDatasets .put (domain , sampledData );
496493 } else {
497- System .out .println ("⚠ Test file not found in either:" );
494+ System .out .println ("Test file not found in either:" );
498495 System .out .println (" " + processedTestFile );
499496 System .out .println (" " + rawTestFile );
500497 }
@@ -509,15 +506,15 @@ public static void main(String[] args) {
509506 Map <String , SentimentClassifier > algoModels = sentiment .models .ModelLoader .loadAllForAlgorithm (algo );
510507
511508 if (algoModels .isEmpty ()) {
512- System .out .println ("⚠ No models found for " + algo );
509+ System .out .println ("No models found for " + algo );
513510 } else {
514511 models .put (algo , algoModels );
515- System .out .println ("✓ Loaded " + algoModels .size () + " " + algo + " model(s)" );
512+ System .out .println ("Loaded " + algoModels .size () + " " + algo + " model(s)" );
516513 }
517514 }
518515
519516 if (models .isEmpty ()) {
520- System .err .println ("\n ✗ No models found in " + modelsDir );
517+ System .err .println ("\n No models found in " + modelsDir );
521518 System .err .println ("Train models first using: ./scripts/train_all_models.sh" );
522519 System .exit (1 );
523520 }
0 commit comments