public FetchItemServiceResponse<Graph<UserDto>> CreateEgoNetwork(Graph<UserDto> graph, int egoNetworkCenterId) { FetchItemServiceResponse<Graph<UserDto>> response = new FetchItemServiceResponse<Graph<UserDto>>(); try { if (graph.EgoEdges.Count > 0) { foreach (Edge<UserDto> egoEdge in graph.EgoEdges) { graph.Edges.RemoveWhere(x => x.Node1.Id == egoEdge.Node1.Id && x.Node2.Id == egoEdge.Node2.Id); } } EgoNetwork egoNetwork = new EgoNetwork(); HashSet<HashSet<Node<UserDto>>> subGraphs = egoNetwork.FindConectedSubgraphs(graph); Node<UserDto> egoNetworkCenter = graph.GetNodeById(egoNetworkCenterId); if (egoNetworkCenter == null) { throw new Exception("Ego center node was not found."); } HashSet<Node<UserDto>> nodesWithMAximalDegreeInSubgraphsAximalDegreeInSubgraph = egoNetwork.GetNodesWithMaximalDegreeInSubgraphs(subGraphs, egoNetworkCenter); foreach (Node<UserDto> node in nodesWithMAximalDegreeInSubgraphsAximalDegreeInSubgraph) { Edge<UserDto> newEdge = new Edge<UserDto>() { Node1 = egoNetworkCenter, Node2 = node }; graph.AddEdge(newEdge); graph.EgoEdges.Add(newEdge); } graph.SetDegrees(); double eiIndex = egoNetwork.GetEIIndex(graph, egoNetworkCenter); double effectiveSizeOfEgo = egoNetwork.GetEffectiveSizeOfEgo(graph, egoNetworkCenter); int connectedCommunities = egoNetwork.GetNumberOfConnectedCommunities(graph, egoNetworkCenter); graph.Nodes.First(x => x.Id == egoNetworkCenter.Id).EIIndex = eiIndex; graph.Nodes.First(x => x.Id == egoNetworkCenterId).EffectiveSize = effectiveSizeOfEgo; graph.Nodes.First(x => x.Id == egoNetworkCenterId).CommunitiesConnected = connectedCommunities; response.Succeeded = true; response.Item = graph; } catch (Exception e) { response.Succeeded = false; throw new Exception(e.Message); } return response; }
// Command line argument: C:\Users\dilet\Desktop\TwitterDB static void Main(string[] args) { Console.WriteLine("Ego-Network Analysis Start (" + DateTime.Now.ToString() + ")\n"); // Commandline Arguments string dirPath = args[0] + Path.DirectorySeparatorChar; // DB(.sqlite) List string[] dbCollection = Directory.GetFiles(dirPath, "*.sqlite"); // Outfile Setting string outFilePath = args[0] + Path.DirectorySeparatorChar + "EgoNetwork_Analysis.txt"; if (File.Exists(outFilePath)) { File.Delete(outFilePath); } // <Ego, dbPath> Sorted by Ego ID(Ascending) SortedDictionary <long, string> egoList = new SortedDictionary <long, string>(); foreach (string dbPath in dbCollection) { long egoID = long.Parse(Path.GetFileNameWithoutExtension(dbPath)); egoList.Add(egoID, dbPath); } // Ego-Network Analysis foreach (KeyValuePair <long, string> kvp in egoList) { long egoID = kvp.Key; string dbPath = kvp.Value; SQLiteAdapter dbAdapter = new SQLiteAdapter(dbPath); Console.WriteLine(egoID + " Started"); // Configure Ego-Network EgoNetwork egoNetwork = new EgoNetwork(egoID); // Construct Ego-Network Information egoNetwork.setNetworkInformation(dbAdapter); // Anaylize Ego-Network egoNetwork.startNetworkAnalysis(dbAdapter, outFilePath); dbAdapter.closeDB(); } }
// Command line argument: C:\Users\dilet\Desktop\TwitterDB static void Main(string[] args) { Console.WriteLine("Ego-Network Analysis Start (" + DateTime.Now.ToString() + ")\n"); // Commandline Arguments string dirPath = args[0] + Path.DirectorySeparatorChar; // DB(.sqlite) List string[] dbCollection = Directory.GetFiles(dirPath, "*.sqlite"); // Outfile Setting string outFilePath = args[0] + Path.DirectorySeparatorChar + "EgoNetwork_Analysis.txt"; if (File.Exists(outFilePath)) File.Delete(outFilePath); // <Ego, dbPath> Sorted by Ego ID(Ascending) SortedDictionary<long, string> egoList = new SortedDictionary<long, string>(); foreach(string dbPath in dbCollection) { long egoID = long.Parse(Path.GetFileNameWithoutExtension(dbPath)); egoList.Add(egoID, dbPath); } // Ego-Network Analysis foreach(KeyValuePair<long, string> kvp in egoList) { long egoID = kvp.Key; string dbPath = kvp.Value; SQLiteAdapter dbAdapter = new SQLiteAdapter(dbPath); Console.WriteLine(egoID + " Started"); // Configure Ego-Network EgoNetwork egoNetwork = new EgoNetwork(egoID); // Construct Ego-Network Information egoNetwork.setNetworkInformation(dbAdapter); // Anaylize Ego-Network egoNetwork.startNetworkAnalysis(dbAdapter, outFilePath); dbAdapter.closeDB(); } }