Social network analysis with Visual Studio 2010

Visual Studio 2010 (professional and greater) does have a built in viewer for “Directed Graph” diagrams (DGML). To write a valid file for a “Directed Graph” in DGML is very simple, because it’s a really easy XML syntax – you have a root with “Node” and “Link” entries. Grouping is being represented by adding nodes with an attribute “Group” which might be “Collapsed” or “Expanded” and “Link” entries with the “Category” attribute “Contains”.

Visual Studio does make use of DGML diagrams to show directed graphs of dependencies between namespaces, classes or assemblies. I’m using this file format in my CodePlex project “SemSync” to represent connections between my contacts via social networks. Extracting information from social networks is really easy by simply using the normal web pages of those networks plus some regular expression. With the “friends” lists from such networks you can get the information what contacts have connections to other contacts.

To build the directed graph file, I’m using entity classes like this (the following is the class to represent the root element of the directed graph file):

namespace Sem.Sync.Connector.Statistic.DgmlContactsByCompany
{
    using System.Collections.Generic;
    using System.Linq;
    using System.Xml.Serialization;

    using Sem.Sync.SyncBase.DetailData;

    [XmlRoot(ElementName = "DirectedGraph",
             Namespace= "http://schemas.microsoft.com/vs/2009/dgml")]
    public class DgmlDirectedGraph
    {
        public DgmlDirectedGraph()
        {
            this.Nodes = new List<DgmlNode>();
        }

        public DgmlDirectedGraph(List<StdElement> elements)
        {
            this.Nodes = new List<DgmlNode>(from element in elements select new DgmlNode(element));
        }

        [XmlAttribute()]
        public DgmlGraphDirection GraphDirection { get; set; }

        [XmlAttribute()]
        public DgmlLayout Layout { get; set; }

        [XmlArrayItem(ElementName = "Node")]
        public List<DgmlNode> Nodes { get; set; }

        [XmlArrayItem(ElementName = "Link")]
        public List<DgmlLink> Links { get; set; }
    }
}

The class does contain the root namespace, the sub-nodes as properties, a default and a custom constructor. As you can see, the custom constructor fills the nodes from a list of StdElement entries – that’s my internal representation of a contact.

The class does expose directly the generic types like List<DgmlLink>, because I want to serialize these classes, so I cannot use interfaces here (well, I could, but that would make things complicated). My node class is named DgmlNode, but I need xml-node entries with the name “Node”, so I simply applied the XmlArrayItem attribute.

I have added such classes for the graph (root element), the nodes and the links – also I do need two enumerations (direction and layout) – that’s all. After preparing the lists in the graph object, I just need to serialize to disk – that’s it.

The following image is a graph with the people of some of the networks I’m connected to:

Sample of a DGML view

Unfortunately you will need Visual Studio to view the graphs, but as a developer, you might already have it – then you can zoom in, select & group the entries etc. In my project Sem.Sync, I’ve implemented automatic group generation for each of the properties a contact can have in my model, so I can really easy have an analysis what companies are connected through what people etc. The project currently supports Xing, Facebook and Wer-Kennt-Wen to read the contact links (more to come ;-)).

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Sylvio's Infobox

Aktuelle Themen rund um SQL Server, BI, Windows, ...

Meredith Lewis

Professional Digital Portfolio

Vittorio Bertocci

Just another WordPress.com weblog

ScottGu's Blog

Just another WordPress.com weblog

AJ's blog

Thoughts and informations I think worthwhile to share...

Outlawtrail - .NET Development

Architecture & Design

SDX eXperts Flurfunk

Just another WordPress.com weblog

%d bloggers like this: