TraceLab Component Library
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties
OCSTI.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 System.Collections.Generic;
19 using System.Linq;
20 using System.Text;
21 using TraceLabSDK.Types;
22 
23 namespace TraceLab.Components.DevelopmentKit.Postprocessors.CSTI
24 {
28  public static class OCSTI
29  {
36  public static TLSimilarityMatrix Compute(TLSimilarityMatrix matrix, TLSimilarityMatrix relationships)
37  {
38  // create pseudo matrix for easy lookup
39  // Dictionary<sourceID, Dictionary<targetID, score>>
40  Dictionary<string, Dictionary<string, double>> storage = new Dictionary<string, Dictionary<string, double>>();
41  foreach (TLSingleLink link in matrix.AllLinks)
42  {
43  if (!storage.ContainsKey(link.SourceArtifactId))
44  {
45  storage.Add(link.SourceArtifactId, new Dictionary<string, double>());
46  }
47  storage[link.SourceArtifactId].Add(link.TargetArtifactId, link.Score);
48  }
49  // compute delta
50  double delta = DeltaUtils.Compute(matrix);
51  // iterate over every (source, target) pair
52  TLLinksList links = matrix.AllLinks;
53  links.Sort();
54  foreach (TLSingleLink link in links)
55  {
56  // get the set of target artifacts related to link.TargetArtifactId
57  // then update the value of (link.SourceArtifactId, relatedArtifact) by delta
58  foreach (string relatedArtifact in relationships.GetSetOfTargetArtifactIdsAboveThresholdForSourceArtifact(link.TargetArtifactId))
59  {
60  storage[link.SourceArtifactId][relatedArtifact] += storage[link.SourceArtifactId][relatedArtifact] * delta;
61  }
62  }
63  // build new matrix
64  TLLinksList newLinks = new TLLinksList();
65  foreach (string source in storage.Keys)
66  {
67  foreach (string target in storage[source].Keys)
68  {
69  newLinks.Add(new TLSingleLink(source, target, storage[source][target]));
70  }
71  }
72  newLinks.Sort();
73  TLSimilarityMatrix newMatrix = new TLSimilarityMatrix();
74  foreach (TLSingleLink link in newLinks)
75  {
76  newMatrix.AddLink(link.SourceArtifactId, link.TargetArtifactId, link.Score);
77  }
78  return newMatrix;
79  }
80  }
81 }