/// <summary> /// Imports script results /// </summary> /// <param name="result">RScriptResults object</param> /// <returns>Script results</returns> public override object ImportResults(RScriptResult result) { TextReader rfile = new StreamReader(_outputFile); string rawdata = rfile.ReadToEnd(); rfile.Close(); TLSimilarityMatrix matrix = new TLSimilarityMatrix(); string[] sims = rawdata.Remove(0, 2).Replace(")", String.Empty).Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); int src = 0; int tgt = _source.DocMap.Count; if (sims.Length != _source.DocMap.Count * _target.DocMap.Count) { throw new RDataException("Results are incorrect size: " + sims.Length + " vs " + (_source.DocMap.Count * _target.DocMap.Count)); } foreach (string sim in sims) { matrix.AddLink(_source.DocMap[src], _target.DocMap[tgt - _source.DocMap.Count], Convert.ToDouble(sim.Trim())); tgt++; if (tgt == _source.DocMap.Count + _target.DocMap.Count) { tgt = _source.DocMap.Count; src++; } } return(matrix); }
/// <summary> /// Import script results /// </summary> /// <param name="result">RScriptResults object</param> /// <returns>Script results</returns> public override object ImportResults(RScriptResult result) { // index = id - 1 string[] ids = Generics.ImportStrings(_mapFile); TextReader resultsMatrix = new StreamReader(_outputFile); TLSimilarityMatrix matrix = new TLSimilarityMatrix(); string[] sources = resultsMatrix.ReadLine().Split(); string line; while ((line = resultsMatrix.ReadLine()) != null) { if (String.IsNullOrWhiteSpace(line)) { continue; } // [0] target id, [x+] source sims index = x - 1 string[] entries = line.Split(); string entry = ids[Convert.ToInt32(entries[0]) - 1]; for (int i = 0; i < sources.Length; i++) { matrix.AddLink(ids[Convert.ToInt32(sources[i]) - 1], entry, Convert.ToDouble(entries[i + 1])); } } resultsMatrix.Close(); return(matrix); }
/// <summary> /// Imports script results /// </summary> /// <param name="result">RScriptResults object</param> /// <returns>Script results</returns> public override object ImportResults(RScriptResult result) { IEnumerable <double> authorities = Generics.ImportDoubles(_authorityFile, false); IEnumerable <double> hubs = Generics.ImportDoubles(_hubFile, false); IEnumerable <string> map = Generics.ImportStrings(_mappingFile); HITSResult results = new HITSResult(); for (int i = 0; i < map.Count(); i++) { results.Hubs.AddLink(_traceID, map.ElementAt(i), hubs.ElementAt(i)); results.Authorities.AddLink(_traceID, map.ElementAt(i), authorities.ElementAt(i)); } return(results); }
/// <summary> /// Import script results /// </summary> /// <param name="result">RScriptResults object</param> /// <returns>Script results</returns> public override object ImportResults(RScriptResult result) { IEnumerable <double> ranks = Generics.ImportDoubles(_outputFile, false); IEnumerable <string> map = Generics.ImportStrings(_mappingFile); if (ranks.Count() != map.Count()) { throw new RDataException("Results file in incorrect format: incorrect number of entries"); } TLSimilarityMatrix rankList = new TLSimilarityMatrix(); for (int i = 0; i < map.Count(); i++) { rankList.AddLink(_traceID, map.ElementAt(i), ranks.ElementAt(i)); } return(rankList); }
/// <summary> /// Returns an ideal GibbsLDA configuration object /// </summary> /// <param name="result">REngine results object</param> /// <returns>GibbsLDAConfig object</returns> public override object ImportResults(RScriptResult result) { TextReader resultFile = new StreamReader(_outputFile); string[] results = resultFile.ReadToEnd().Split(new char[] { '\t' }, StringSplitOptions.RemoveEmptyEntries); if (results.Length != 4) { throw new RDataException("Results file in incorrect format (" + _outputFile + ")"); } return(new GibbsLDAConfig { NumTopics = Convert.ToInt32(Math.Round(Convert.ToDouble(results[0]))), GibbsIterations = Convert.ToInt32(Math.Round(Convert.ToDouble(results[1]))), Alpha = Convert.ToDouble(results[2]), Beta = Convert.ToDouble(results[3]), Seed = _config.Seed, }); }
/// <summary> /// Returns an array containing the contributions of each matrix in the order they were added /// </summary> /// <param name="result">REngine result object</param> /// <returns>double[]</returns> public override object ImportResults(RScriptResult result) { List <double> pca = new List <double>(); TextReader file = new StreamReader(_outputFile); file.ReadLine(); string line = String.Empty; while ((line = file.ReadLine()) != null) { string[] entries = line.Split(','); if (entries.Length != 3) { throw new RDataException("Error in PCA output."); } pca.Add(Convert.ToDouble(entries[2])); } if (pca.Count != _matrices.Length) { throw new RDataException("PCA returned the incorrect number of entries."); } return(pca.ToArray()); }
/// <summary> /// Import script results /// </summary> /// <param name="result">RScriptResults object</param> /// <returns>Script results</returns> public override object ImportResults(RScriptResult result) { TextReader rfile = new StreamReader(_outputFile); string rawdata = rfile.ReadToEnd(); rfile.Close(); TLSimilarityMatrix matrix = new TLSimilarityMatrix(); string[] sims = rawdata.Remove(0, 2).Replace(")", String.Empty).Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); string[] edges = Generics.ImportStrings(_info.Edges); if (sims.Length != edges.Length) { throw new RDataException("Results are incorrect size: " + sims.Length + " vs " + edges.Length); } for (int i = 0; i < sims.Length; i++) { string[] split = edges[i].Split(); matrix.AddLink(_corpus.Map[Convert.ToInt32(split[0])], _corpus.Map[Convert.ToInt32(split[1])], Convert.ToDouble(sims[i])); } //int src = 0; //int tgt = _source.DocMap.Count; //if (sims.Length != _source.DocMap.Count * _target.DocMap.Count) //{ // throw new RDataException("Results are incorrect size: " + sims.Length + " vs " + (_source.DocMap.Count * _target.DocMap.Count)); //} //foreach (string sim in sims) //{ // matrix.AddLink(_source.DocMap[src], _target.DocMap[tgt - _source.DocMap.Count], Convert.ToDouble(sim.Trim())); // tgt++; // if (tgt == _source.DocMap.Count + _target.DocMap.Count) // { // tgt = _source.DocMap.Count; // src++; // } //} return(matrix); }
/// <summary> /// Import script results /// </summary> /// <param name="result">RScriptResults object</param> /// <returns>Script results</returns> public override object ImportResults(RScriptResult result) { return(Similarities.Import(_outputFile)); }