1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Linq;
|
---|
4 | using System.Text;
|
---|
5 | using System.Threading.Tasks;
|
---|
6 | using HeuristicLab.Common;
|
---|
7 |
|
---|
8 | namespace HeuristicLab.Problems.GrammaticalOptimization {
|
---|
9 | public class SentenceSetStatistics {
|
---|
10 | public int NumberOfSentences { get; private set; }
|
---|
11 | public string BestSentence { get; private set; }
|
---|
12 | public string FirstSentence { get; private set; }
|
---|
13 | public string LastSentence { get; private set; }
|
---|
14 | public double BestSentenceQuality { get; private set; }
|
---|
15 | public double BestSentenceIndex { get; private set; }
|
---|
16 | public double FirstSentenceQuality { get; private set; }
|
---|
17 | public double LastSentenceQuality { get; private set; }
|
---|
18 | public double AverageQuality { get { return sumQualities / NumberOfSentences; } }
|
---|
19 | // public double MedianQuality { get; private set; }
|
---|
20 | private double sumQualities;
|
---|
21 |
|
---|
22 | private readonly double bestKnownQuality;
|
---|
23 | public SentenceSetStatistics(double bestKnownQuality = 1.0) {
|
---|
24 | this.bestKnownQuality = bestKnownQuality;
|
---|
25 | BestSentenceQuality = double.NegativeInfinity;
|
---|
26 | BestSentence = string.Empty;
|
---|
27 | FirstSentence = string.Empty;
|
---|
28 | LastSentence = string.Empty;
|
---|
29 | }
|
---|
30 |
|
---|
31 | public void AddSentence(string sentence, double quality) {
|
---|
32 | sumQualities += quality;
|
---|
33 | NumberOfSentences++;
|
---|
34 |
|
---|
35 | if (NumberOfSentences == 1) {
|
---|
36 | FirstSentence = sentence;
|
---|
37 | FirstSentenceQuality = quality;
|
---|
38 | }
|
---|
39 |
|
---|
40 | if (quality > BestSentenceQuality) {
|
---|
41 | BestSentence = sentence;
|
---|
42 | BestSentenceQuality = quality;
|
---|
43 | BestSentenceIndex = NumberOfSentences;
|
---|
44 | }
|
---|
45 |
|
---|
46 | LastSentence = sentence;
|
---|
47 | LastSentenceQuality = quality;
|
---|
48 | }
|
---|
49 |
|
---|
50 | public override string ToString() {
|
---|
51 | return
|
---|
52 | string.Format("Sentences: {0,10} avg.-quality {1,7:F5} best {2,7:F5} {3,2} {4,10} {5,30} first {6,7:F5} {7,20} last {8,7:F5} {9,20}",
|
---|
53 | NumberOfSentences, AverageQuality,
|
---|
54 | BestSentenceQuality, DoubleExtensions.IsAlmost(BestSentenceQuality, bestKnownQuality) ? 1.0 : 0.0,
|
---|
55 | BestSentenceIndex, TrimToSize(BestSentence, 30),
|
---|
56 | FirstSentenceQuality, TrimToSize(FirstSentence, 20),
|
---|
57 | LastSentenceQuality, TrimToSize(LastSentence, 20)
|
---|
58 | );
|
---|
59 | }
|
---|
60 |
|
---|
61 | private string TrimToSize(string s, int len) {
|
---|
62 | if (s.Length < len) return s;
|
---|
63 | else {
|
---|
64 | var sb = new StringBuilder(len);
|
---|
65 | sb.Append(s.Substring(0, len - 3));
|
---|
66 | sb.Append("...");
|
---|
67 | return sb.ToString();
|
---|
68 | }
|
---|
69 | }
|
---|
70 | }
|
---|
71 | }
|
---|