TraceLab Component Library
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties
RecallQueryComputation.cs
Go to the documentation of this file.
1 // TraceLab Component Library
2 // Copyright © 2012-2013 SEMERU
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16 
17 using System.Linq;
18 using TraceLabSDK;
19 using TraceLabSDK.Types;
20 using TraceLabSDK.Types.Contests;
21 
22 namespace TraceLab.Components.DevelopmentKit.Metrics.Traceability
23 {
28  {
29  #region Members
30 
31  private const string _name = "Recall (query granularity)";
32  private const string _description = "Recall measures the fraction of correctly retrieved documents among the total correct documents. This metric is calculated per source artifact.";
33 
37  public override string Name
38  {
39  get { return _name; }
40  }
41 
45  public override string Description
46  {
47  get { return _description; }
48  }
49 
50  private TLSimilarityMatrix _matrix;
51  private TLSimilarityMatrix _oracle;
52 
53  #endregion
54 
60  public RecallQueryComputation(TLSimilarityMatrix candidateMatrix, TLSimilarityMatrix answerMatrix)
61  : base()
62  {
63  _matrix = candidateMatrix;
64  _oracle = answerMatrix;
65  }
66 
70  protected override void ComputeImplementation()
71  {
72  SerializableDictionary<string, double> sourceRecall = new SerializableDictionary<string, double>();
73  _oracle.Threshold = 0;
74  foreach (string sourceArtifact in _oracle.SourceArtifactsIds)
75  {
76  TLLinksList links = _matrix.GetLinksAboveThresholdForSourceArtifact(sourceArtifact);
77  int correct = 0;
78  foreach (TLSingleLink link in links)
79  {
80  if (_oracle.IsLinkAboveThreshold(link.SourceArtifactId, link.TargetArtifactId))
81  {
82  correct++;
83  }
84  }
85  sourceRecall.Add(sourceArtifact, correct / (double) _oracle.GetCountOfLinksAboveThresholdForSourceArtifact(sourceArtifact));
86  }
87  Results = sourceRecall;
88  }
89 
94  protected override Metric GenerateSummaryImplementation()
95  {
96  BoxSummaryData data = new BoxSummaryData(Name, Description);
97  data.AddPoint(new BoxPlotPoint(Results.Values.ToArray()));
98  return data;
99  }
100  }
101 }