18 using System.Collections.Generic;
22 using TraceLabSDK.Types;
23 using TraceLab.Components.DevelopmentKit;
26 namespace TraceLab.Components.DevelopmentKit.Tracers.InformationRetrieval
33 #region Private members
36 private IEnumerable<string> _sourceDocs;
37 private IEnumerable<string> _targetDocs;
49 public LDACorpus(
string name, TLArtifactsCollection source, TLArtifactsCollection target)
54 _sourceDocs = sMatrix.
DocMap;
55 _targetDocs = tMatrix.
DocMap;
68 _sourceDocs = source.
DocMap;
69 _targetDocs = target.
DocMap;
83 _sourceDocs = sourceIDs;
84 _targetDocs = targetIDs;
90 #region Public accessors
95 public string Name {
get;
private set; }
104 StringBuilder edges =
new StringBuilder();
105 foreach (
string sourceID
in _sourceDocs)
107 foreach (
string targetID
in _targetDocs)
109 edges.AppendFormat(
"{0} {1}", _matrix.GetDocumentIndex(sourceID), _matrix.GetDocumentIndex(targetID));
113 return edges.ToString();
124 StringBuilder list =
new StringBuilder(
"list(");
125 List<string> links =
new List<string>();
126 for (
int i = 0; i < _matrix.NumDocs; i++)
128 links.Add(
"integer(0)");
130 list.Append(String.Join(
",", links));
132 return list.ToString();
143 return "c(\"" + String.Join(
"\",\"", _matrix.TermMap) +
"\")";
169 StringBuilder tdoc =
new StringBuilder(
"list(");
171 for (
int i = 0; i < _matrix.NumDocs; i++)
173 tdoc.Append(
"structure(c(");
174 List<string> entries =
new List<string>();
175 for (
int j = 0; j < _matrix.NumTerms; j++)
177 int freq = Convert.ToInt32(_matrix[i, j]);
178 for (
int k = 1; k <= freq; k++)
180 entries.Add(j +
"L,1L");
183 tdoc.Append(String.Join(
",", entries));
184 tdoc.Append(
"), .Dim = c(2L, " + Convert.ToInt32(_matrix.GetDocument(i).Sum()) +
"L))");
185 if (i < _matrix.NumDocs - 1)
187 tdoc.AppendLine(
",");
191 tdoc.AppendLine(
")");
192 return tdoc.ToString();
199 public List<string> Map
203 return _matrix.DocMap;
223 TextWriter corpus =
new StreamWriter(cFS);
224 corpus.Write(Matrix);
229 info.
Vocab = vFS.Name;
230 TextWriter vocab =
new StreamWriter(vFS);
236 info.
Edges = eFS.Name;
237 TextWriter edges =
new StreamWriter(eFS);
243 info.
Links = lFS.Name;
244 TextWriter links =
new StreamWriter(lFS);