TraceLab Component Library
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties
TraceabilityMetricsQueryComponent.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;
18 using TraceLab.Components.DevelopmentKit.Metrics;
19 using TraceLab.Components.DevelopmentKit.Metrics.Traceability;
20 using TraceLab.Components.Library.Metrics.Controller;
21 using TraceLabSDK;
22 using TraceLabSDK.Types;
23 
24 namespace TraceLab.Components.Library.Metrics.Traceability
25 {
26  [Component(Name = "Traceability Metrics - Query granularity",
27  Description = "Computes various traceability metrics per source artifact in a similarity matrix.",
28  Author = "SEMERU; Evan Moritz",
29  Version = "1.0.0.0",
30  ConfigurationType = typeof(TraceabilityMetricsQueryConfig))]
31  [IOSpec(IOSpecType.Input, "CandidateMatrix", typeof(TLSimilarityMatrix))]
32  [IOSpec(IOSpecType.Input, "AnswerMatrix", typeof(TLSimilarityMatrix))]
33  [Tag("Metrics.Traceability")]
34  public class TraceabilityMetricsQueryComponent : BaseComponent
35  {
36  private TraceabilityMetricsQueryConfig _config;
37 
38  public TraceabilityMetricsQueryComponent(ComponentLogger log)
39  : base(log)
40  {
41  _config = new TraceabilityMetricsQueryConfig();
42  Configuration = _config;
43  }
44 
45  public override void Compute()
46  {
47  Logger.Trace("Starting metrics computation: " + _config.TechniqueName);
48  TLSimilarityMatrix matrix = (TLSimilarityMatrix)Workspace.Load("CandidateMatrix");
49  TLSimilarityMatrix oracle = (TLSimilarityMatrix)Workspace.Load("AnswerMatrix");
50  #region Precision
51  if (_config.Precision)
52  {
53  Logger.Trace("Computing precision...");
54  IMetricComputation computation = new PrecisionQueryComputation(matrix, oracle);
55  computation.Compute();
56  ResultsController.Instance.AddResult(_config.TechniqueName, _config.DatasetName, computation);
57  }
58  else
59  {
60  Logger.Trace("Skipped precision computation.");
61  }
62  #endregion
63  #region Recall
64  if (_config.Recall)
65  {
66  Logger.Trace("Computing recall...");
67  IMetricComputation computation = new RecallQueryComputation(matrix, oracle);
68  computation.Compute();
69  ResultsController.Instance.AddResult(_config.TechniqueName, _config.DatasetName, computation);
70  }
71  else
72  {
73  Logger.Trace("Skipped recall computation.");
74  }
75  #endregion
76  #region Average Precision
77  if (_config.AveragePrecision)
78  {
79  Logger.Trace("Computing average precision...");
80  IMetricComputation computation = new AveragePrecisionQueryComputation(matrix, oracle);
81  computation.Compute();
82  ResultsController.Instance.AddResult(_config.TechniqueName, _config.DatasetName, computation);
83  }
84  else
85  {
86  Logger.Trace("Skipped average precision computation.");
87  }
88  #endregion
89  #region Mean Average Precision
90  if (_config.MeanAveragePrecision)
91  {
92  Logger.Trace("Computing mean average precision...");
93  IMetricComputation computation = new MeanAveragePrecisionComputation(matrix, oracle);
94  computation.Compute();
95  ResultsController.Instance.AddResult(_config.TechniqueName, _config.DatasetName, computation);
96  }
97  else
98  {
99  Logger.Trace("Skipped mean average precision computation.");
100  }
101  #endregion
102  }
103  }
104 }
105