View Javadoc
1   package com.acumenvelocity.ath.mt.confidence;
2   
3   import java.util.List;
4   import java.util.Map;
5   
6   /**
7    * Data structures for the HeuristicQualityEstimator.
8    */
9   public class HeuristicDataStructures {
10  
11    /**
12     * Represents the heuristic quality score for a single translation.
13     */
14    public static class HeuristicScore {
15      private final String modelId;
16      private final String translation;
17      private final double overallScore; // 0.0 - 1.0 (higher is better)
18      private final Map<String, Double> detailedMetrics;
19      private final List<String> detectedIssues;
20  
21      public HeuristicScore(String modelId, String translation, double overallScore,
22          Map<String, Double> detailedMetrics, List<String> detectedIssues) {
23        
24        this.modelId = modelId;
25        this.translation = translation;
26        this.overallScore = overallScore;
27        this.detailedMetrics = detailedMetrics;
28        this.detectedIssues = detectedIssues;
29      }
30  
31      public String getModelId() {
32        return modelId;
33      }
34  
35      public String getTranslation() {
36        return translation;
37      }
38  
39      public double getOverallScore() {
40        return overallScore;
41      }
42  
43      public Map<String, Double> getDetailedMetrics() {
44        return detailedMetrics;
45      }
46  
47      public List<String> getDetectedIssues() {
48        return detectedIssues;
49      }
50  
51      @Override
52      public String toString() {
53        String metrics = detailedMetrics.entrySet().stream()
54            .map(e -> String.format("%s=%.2f", e.getKey(), e.getValue()))
55            .collect(java.util.stream.Collectors.joining(", "));
56  
57        StringBuilder sb = new StringBuilder();
58        
59        sb.append(String.format("Translation: '%s' | Score: %.3f | Metrics: %s",
60            translation.substring(0, Math.min(translation.length(), 60))
61                + (translation.length() > 60 ? "..." : ""),
62            overallScore,
63            metrics));
64  
65        if (!detectedIssues.isEmpty()) {
66          sb.append("\n    Issues: ");
67          sb.append(String.join("; ", detectedIssues));
68        }
69  
70        return sb.toString();
71      }
72    }
73  
74    /**
75     * Represents the collection of heuristic scores for all translations of a single segment.
76     */
77    public static class HeuristicResult {
78      private final int segmentId;
79      private final String sourceText;
80      private final List<HeuristicScore> scores;
81  
82      public HeuristicResult(int segmentId, String sourceText, List<HeuristicScore> scores) {
83        this.segmentId = segmentId;
84        this.sourceText = sourceText;
85        this.scores = scores;
86      }
87  
88      public int getSegmentId() {
89        return segmentId;
90      }
91  
92      public String getSourceText() {
93        return sourceText;
94      }
95  
96      public List<HeuristicScore> getScores() {
97        return scores;
98      }
99  
100     public HeuristicScore getBestScore() {
101       return scores.isEmpty() ? null : scores.get(0);
102     }
103 
104     public void printReport() {
105       System.out.printf("\n=== Segment %d ===%n", segmentId);
106       System.out.printf("Source: %s%n", sourceText);
107       System.out.println("\nHeuristic Scores:");
108 
109       for (int i = 0; i < scores.size(); i++) {
110         System.out.printf("%d. %s%n", i + 1, scores.get(i));
111       }
112     }
113   }
114 }