TraceLab Component Library
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties
TPTPComponent.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;
22 using TraceLabSDK.Component.Config;
23 using TraceLab.Components.Types.Preprocessors.ExecutionTraces;
24 using TraceLab.Components.DevelopmentKit.Preprocessors.ExecutionTraces;
25 using System.IO;
26 using TraceLabSDK.Types;
27 
28 namespace TraceLab.Components.Library.Preprocessors.ExecutionTraces
29 {
30  [Component(Name = "TPTP Trace Analyzer",
31  Description = "Extracts a PDG and unique methods from a TPTP-format trace.",
32  Author = "SEMERU; Bogdon Dit; Evan Moritz",
33  Version = "1.0.0.0",
34  ConfigurationType = typeof(TPTPComponentConfig))]
35  [Tag("Preprocessors.Execution Traces")]
36  [IOSpec(IOSpecType.Input, "TraceID", typeof(string))]
37  [IOSpec(IOSpecType.Output, "PDG", typeof(PDG))]
38  [IOSpec(IOSpecType.Output, "UniqueMethods", typeof(IEnumerable<string>))]
39  public class TPTPComponent : BaseComponent
40  {
41  private TPTPComponentConfig _config;
42 
43  public TPTPComponent(ComponentLogger log)
44  : base(log)
45  {
46  _config = new TPTPComponentConfig();
47  Configuration = _config;
48  }
49 
50  public override void Compute()
51  {
52  string traceID = (string)Workspace.Load("TraceID");
53  TLArtifactsCollection artifacts = (TLArtifactsCollection)Workspace.Load("Artifacts");
54  BiGramCollection bigrams = TPTP.GenerateBiGrams(Path.Combine(_config.TraceDirectory, traceID));
55  PDG pdg = PDG.Convert(bigrams);
56  ISet<string> unique = TPTP.GenerateUniqueMethods(Path.Combine(_config.TraceDirectory, traceID));
57  Workspace.Store("PDG", pdg);
58  Workspace.Store("UniqueMethods", unique);
59  }
60  }
61 
62  public class TPTPComponentConfig
63  {
64  public DirectoryPath TraceDirectory { get; set; }
65  }
66 }