/// <summary> /// User topics walking graph for Gephi generation /// </summary> /// <param name="fileToSave"></param> /// <param name="topicExclusions"></param> /// <param name="scale">[0 .. 5) - more detailed, [5 .. ) - less detailed graph</param> public void GenerateTopicWalkingGraph(string fileToSave, HashSet<int> topicExclusions, int scale = 5) { Console.WriteLine(String.Join("\n", topicMoves.OrderByDescending(it => it.Value))); var topicConverter = new TopicConverter(Program.TopicsWordsFileName); var graphEdges = topicMoves .Where(it => it.Value > scale) .Where(it => !topicExclusions.Contains(it.Key.Items[0]) && !topicExclusions.Contains(it.Key.Items[1])) .Select(it => new { seq = it.Key, chance = GetGivenProbability(it.Key)}) .Select(row => new Edge{SourceId = row.seq.Items[0], DestinationId = row.seq.Items[1], Weight = row.chance}) .ToList(); var topics = graphEdges.Aggregate(new HashSet<int>(), (acc, e) => { acc.Add(e.SourceId); acc.Add(e.DestinationId); return acc; }); var graphVertices = topics.Select(t => new Vertex { Id = t, Label = String.Join(", ", topicConverter.GetTopicWords(t, 10)), Weight = topicDistribution[t] }); var graph = new GraphBuilder(graphVertices, graphEdges); graph.ExportToGVFormat(fileToSave, "TopikWalkingGraph", isOriented:true); }
public void SaveTopicGraph(string fileToSave, int nWords) { var vertices = topicToWords.Select(t => new Vertex {Id = t.Key, Label = String.Join(", ", GetTopicWords(t.Key, nWords)), Weight = 1}); var edges = from e1 in topicToWords.Keys from e2 in topicToWords.Keys select new Edge {SourceId = e1, DestinationId = e2, Weight = GetWeight(topicToWords[e1], topicToWords[e2])}; var graph = new GraphBuilder(vertices, edges); graph.ExportToGVFormat(fileToSave, "TopicGraph", isOriented:false); }