18 using System.Collections.Generic;
21 using System.Reflection;
23 using RPlugin.Exceptions;
24 using TraceLab.Components.DevelopmentKit.IO;
25 using TraceLab.Components.RPlugin.Properties;
26 using TraceLab.Components.Types.Preprocessors.ExecutionTraces;
27 using TraceLab.Components.Types.Tracers.WebMining;
29 namespace TraceLab.Components.DevelopmentKit.Tracers.WebMining
36 private readonly
string _baseScript = Settings.Default.Resources +
"HITS.R";
37 private readonly
string[] _requiredPackages =
new string[] {
"base" };
40 private string _mappingFile;
41 private string _authorityFile;
42 private string _hubFile;
44 private string _traceID;
49 public override string BaseScript
60 public override string[] RequiredPackages
64 return _requiredPackages;
87 string matrixFile = GenerateAdjacencyMatrix();
90 _arguments =
new List<object>();
91 _arguments.Add(matrixFile);
92 _arguments.Add(_authorityFile);
93 _arguments.Add(_hubFile);
94 _arguments.Add(_config.Epsilon);
108 for (
int i = 0; i < map.Count(); i++)
110 results.
Hubs.AddLink(_traceID, map.ElementAt(i), hubs.ElementAt(i));
111 results.
Authorities.AddLink(_traceID, map.ElementAt(i), authorities.ElementAt(i));
116 #region Private methods
118 private string GenerateAdjacencyMatrix()
120 int n = _pdg.Nodes.Count();
121 double defaultValue = 1.0 / n;
122 double[] rowValues =
new double[n];
125 TextWriter matrixWriter =
new StreamWriter(matrixFS);
131 _mappingFile = mapFS.Name;
132 TextWriter mapWriter =
new StreamWriter(mapFS);
134 for (
int nodeIndex = 0; nodeIndex < _pdg.Nodes.Count(); nodeIndex++)
136 PDGNode pdgNode = _pdg.GetNode(nodeIndex);
138 for (
int i = 0; i < n; i++)
145 for (
int indexOutgoingEdge = 0; indexOutgoingEdge < pdgNode.
OutgoingEdges.Count(); indexOutgoingEdge++)
148 int columnFrequencies = _pdg.IndexOf(pdgOutgoingEdge.
OutgoingNodeID);
151 if ((columnFrequencies < 0))
158 rowValues[columnFrequencies] = 1;
163 rowValues[columnFrequencies] = pdgOutgoingEdge.
Weight;
167 throw new RDataException(
"Unknown weighting scheme: " + _config.Weight);
176 matrixWriter.WriteLine(String.Join(
" ", rowValues));
180 matrixWriter.Flush();
181 matrixWriter.Close();
186 return matrixFS.Name;