TryAppendVertexXmlNode
        (
            String sUserName,
            XmlNode oEntryXmlNode,
            GraphMLXmlDocument oGraphMLXmlDocument,
            Dictionary <String, XmlNode> oUserNameDictionary
        )
        {
            Debug.Assert(!String.IsNullOrEmpty(sUserName));
            Debug.Assert(oGraphMLXmlDocument != null);
            Debug.Assert(oUserNameDictionary != null);

            XmlNode oVertexXmlNode;

            if (oUserNameDictionary.TryGetValue(sUserName, out oVertexXmlNode))
            {
                return(false);
            }

            oVertexXmlNode = oGraphMLXmlDocument.AppendVertexXmlNode(sUserName);
            oUserNameDictionary.Add(sUserName, oVertexXmlNode);

            oGraphMLXmlDocument.AppendGraphMLAttributeValue(oVertexXmlNode,
                                                            NodeXLGraphMLUtil.VertexMenuTextID,
                                                            "Open YouTube Page for This Person");

            oGraphMLXmlDocument.AppendGraphMLAttributeValue(oVertexXmlNode,
                                                            NodeXLGraphMLUtil.VertexMenuActionID,
                                                            String.Format(WebPageUrlPattern, sUserName));

            return(true);
        }
        AppendVertexXmlNode
        (
            String sTag,
            GraphMLXmlDocument oGraphMLXmlDocument,
            Dictionary <String, XmlNode> oTagDictionary
        )
        {
            Debug.Assert(!String.IsNullOrEmpty(sTag));
            Debug.Assert(oGraphMLXmlDocument != null);
            Debug.Assert(oTagDictionary != null);

            if (!oTagDictionary.ContainsKey(sTag))
            {
                XmlNode oVertexXmlNode = oGraphMLXmlDocument.AppendVertexXmlNode(
                    sTag);

                oGraphMLXmlDocument.AppendGraphMLAttributeValue(oVertexXmlNode,
                                                                NodeXLGraphMLUtil.VertexLabelID, sTag);

                oGraphMLXmlDocument.AppendGraphMLAttributeValue(oVertexXmlNode,
                                                                NodeXLGraphMLUtil.VertexMenuTextID,
                                                                "Open Flickr Page for This Tag");

                oGraphMLXmlDocument.AppendGraphMLAttributeValue(oVertexXmlNode,
                                                                NodeXLGraphMLUtil.VertexMenuActionID,

                                                                String.Format(
                                                                    "http://www.flickr.com/photos/tags/{0}/"
                                                                    ,
                                                                    UrlUtil.EncodeUrlParameter(sTag)
                                                                    ));

                oTagDictionary.Add(sTag, oVertexXmlNode);
            }
        }
Beispiel #3
0
        TryAppendVertexXmlNode
        (
            String sUserID,
            String sScreenName,
            GraphMLXmlDocument oGraphMLXmlDocument,
            Dictionary <String, XmlNode> oUserIDDictionary
        )
        {
            Debug.Assert(!String.IsNullOrEmpty(sUserID));
            Debug.Assert(!String.IsNullOrEmpty(sScreenName));
            Debug.Assert(oGraphMLXmlDocument != null);
            Debug.Assert(oUserIDDictionary != null);

            XmlNode oVertexXmlNode;

            if (oUserIDDictionary.TryGetValue(sUserID, out oVertexXmlNode))
            {
                return(false);
            }

            oVertexXmlNode = oGraphMLXmlDocument.AppendVertexXmlNode(sScreenName);
            oUserIDDictionary.Add(sUserID, oVertexXmlNode);

            return(true);
        }
Beispiel #4
0
        TryAppendVertexXmlNode
        (
            String screenName,
            String userID,
            GraphMLXmlDocument graphMLXmlDocument,
            Dictionary <String, TwitterUser> userIDDictionary,
            out TwitterUser twitterUser
        )
        {
            Debug.Assert(!String.IsNullOrEmpty(screenName));
            Debug.Assert(!String.IsNullOrEmpty(userID));
            Debug.Assert(graphMLXmlDocument != null);
            Debug.Assert(userIDDictionary != null);

            twitterUser = null;

            if (userIDDictionary.TryGetValue(userID, out twitterUser))
            {
                // A vertex XML node already exists.

                return(false);
            }

            XmlNode vertexXmlNode = graphMLXmlDocument.AppendVertexXmlNode(
                screenName);

            twitterUser = new TwitterUser(screenName, vertexXmlNode);
            userIDDictionary.Add(userID, twitterUser);

            graphMLXmlDocument.AppendGraphMLAttributeValue(vertexXmlNode,
                                                           NodeXLGraphMLUtil.VertexMenuTextID,
                                                           "Open Twitter Page for This Person");

            graphMLXmlDocument.AppendGraphMLAttributeValue(
                vertexXmlNode,
                NodeXLGraphMLUtil.VertexMenuActionID,
                String.Format(TwitterApiUrls.UserWebPageUrlPattern, screenName)
                );

            return(true);
        }
Beispiel #5
0
        SaveGraphCore
        (
            IGraph graph,
            Stream stream
        )
        {
            Debug.Assert(graph != null);
            Debug.Assert(stream != null);
            AssertValid();

            GraphMLXmlDocument oGraphMLXmlDocument = new GraphMLXmlDocument(
                graph.Directedness == GraphDirectedness.Directed);

            String [] asEdgeAttributeNames = ( String[] )graph.GetRequiredValue(
                ReservedMetadataKeys.AllEdgeMetadataKeys, typeof(String[]));

            String [] asVertexAttributeNames = ( String[] )graph.GetRequiredValue(
                ReservedMetadataKeys.AllVertexMetadataKeys, typeof(String[]));

            // Define the Graph-ML attributes.

            const String VertexAttributeIDPrefix = "V-";
            const String EdgeAttributeIDPrefix   = "E-";

            foreach (String sVertexAttributeName in asVertexAttributeNames)
            {
                oGraphMLXmlDocument.DefineGraphMLAttribute(false,
                                                           VertexAttributeIDPrefix + sVertexAttributeName,
                                                           sVertexAttributeName, "string", null);
            }

            foreach (String sEdgeAttributeName in asEdgeAttributeNames)
            {
                oGraphMLXmlDocument.DefineGraphMLAttribute(true,
                                                           EdgeAttributeIDPrefix + sEdgeAttributeName,
                                                           sEdgeAttributeName, "string", null);
            }

            // Add the vertices and their Graph-ML attribute values.

            foreach (IVertex oVertex in graph.Vertices)
            {
                XmlNode oVertexXmlNode = oGraphMLXmlDocument.AppendVertexXmlNode(
                    oVertex.Name);

                AppendGraphMLAttributeValues(oVertex, oGraphMLXmlDocument,
                                             oVertexXmlNode, asVertexAttributeNames,
                                             VertexAttributeIDPrefix);
            }

            // Add the edges and their Graph-ML attribute values.

            foreach (IEdge oEdge in graph.Edges)
            {
                IVertex [] oVertices = oEdge.Vertices;

                XmlNode oEdgeXmlNode = oGraphMLXmlDocument.AppendEdgeXmlNode(
                    oVertices[0].Name, oVertices[1].Name);

                AppendGraphMLAttributeValues(oEdge, oGraphMLXmlDocument,
                                             oEdgeXmlNode, asEdgeAttributeNames, EdgeAttributeIDPrefix);
            }

            oGraphMLXmlDocument.Save(stream);
        }
        AppendVertexXmlNodes
        (
            String sSearchTerm,
            WhatToInclude eWhatToInclude,
            Int32 iMaximumVideos,
            GraphMLXmlDocument oGraphMLXmlDocument,
            RequestStatistics oRequestStatistics,
            out HashSet <String> oVideoIDs,
            out Dictionary <String, LinkedList <String> > oCategoryDictionary
        )
        {
            Debug.Assert(!String.IsNullOrEmpty(sSearchTerm));
            Debug.Assert(iMaximumVideos > 0);
            Debug.Assert(oGraphMLXmlDocument != null);
            Debug.Assert(oRequestStatistics != null);
            AssertValid();

            ReportProgress("Getting a list of videos.");

            // This is used to skip duplicate videos in the results returned by
            // YouTube.  (I'm not sure why YouTube sometimes returns duplicates,
            // but it does.)

            oVideoIDs = new HashSet <String>();

            // If an edge should be included for each pair of videos that share the
            // same category, the key is a lower-case category and the value is a
            // LinkedList of the video IDs that have the category.

            if (WhatToIncludeFlagIsSet(eWhatToInclude,
                                       WhatToInclude.SharedCategoryEdges))
            {
                oCategoryDictionary =
                    new Dictionary <String, LinkedList <String> >();
            }
            else
            {
                oCategoryDictionary = null;
            }

            String sUrl = String.Format(

                "http://gdata.youtube.com/feeds/api/videos?q={0}"
                ,
                EncodeUrlParameter(sSearchTerm)
                );

            // The document consists of an "entry" XML node for each video.

            foreach (XmlNode oEntryXmlNode in EnumerateXmlNodes(sUrl,
                                                                "a:feed/a:entry", iMaximumVideos, false, oRequestStatistics))
            {
                XmlNamespaceManager oXmlNamespaceManager =
                    CreateXmlNamespaceManager(oEntryXmlNode.OwnerDocument);

                // Use the video ID as the GraphML vertex name.  The video title
                // can't be used because it is not unique.

                String sVideoID;

                if (
                    !XmlUtil2.TrySelectSingleNodeAsString(oEntryXmlNode,
                                                          "media:group/yt:videoid/text()", oXmlNamespaceManager,
                                                          out sVideoID)
                    ||
                    oVideoIDs.Contains(sVideoID)
                    )
                {
                    continue;
                }

                oVideoIDs.Add(sVideoID);

                XmlNode oVertexXmlNode = oGraphMLXmlDocument.AppendVertexXmlNode(
                    sVideoID);

                AppendStringGraphMLAttributeValue(oEntryXmlNode,
                                                  "a:title/text()", oXmlNamespaceManager, oGraphMLXmlDocument,
                                                  oVertexXmlNode, TitleID);

                AppendStringGraphMLAttributeValue(oEntryXmlNode,
                                                  "a:author/a:name/text()", oXmlNamespaceManager,
                                                  oGraphMLXmlDocument, oVertexXmlNode, AuthorID);

                AppendDoubleGraphMLAttributeValue(oEntryXmlNode,
                                                  "gd:rating/@average", oXmlNamespaceManager,
                                                  oGraphMLXmlDocument, oVertexXmlNode, RatingID);

                AppendInt32GraphMLAttributeValue(oEntryXmlNode,
                                                 "yt:statistics/@viewCount", oXmlNamespaceManager,
                                                 oGraphMLXmlDocument, oVertexXmlNode, ViewsID);

                AppendInt32GraphMLAttributeValue(oEntryXmlNode,
                                                 "yt:statistics/@favoriteCount", oXmlNamespaceManager,
                                                 oGraphMLXmlDocument, oVertexXmlNode, FavoritedID);

                AppendInt32GraphMLAttributeValue(oEntryXmlNode,
                                                 "gd:comments/gd:feedLink/@countHint", oXmlNamespaceManager,
                                                 oGraphMLXmlDocument, oVertexXmlNode, CommentsID);

                AppendYouTubeDateGraphMLAttributeValue(oEntryXmlNode,
                                                       "a:published/text()", oXmlNamespaceManager,
                                                       oGraphMLXmlDocument, oVertexXmlNode, CreatedDateUtcID);

                AppendStringGraphMLAttributeValue(oEntryXmlNode,
                                                  "media:group/media:thumbnail/@url", oXmlNamespaceManager,
                                                  oGraphMLXmlDocument, oVertexXmlNode,
                                                  NodeXLGraphMLUtil.VertexImageFileID);

                if (AppendStringGraphMLAttributeValue(oEntryXmlNode,
                                                      "media:group/media:player/@url", oXmlNamespaceManager,
                                                      oGraphMLXmlDocument, oVertexXmlNode,
                                                      NodeXLGraphMLUtil.VertexMenuActionID))
                {
                    oGraphMLXmlDocument.AppendGraphMLAttributeValue(oVertexXmlNode,
                                                                    NodeXLGraphMLUtil.VertexMenuTextID,
                                                                    "Play Video in Browser");
                }

                if (oCategoryDictionary != null)
                {
                    CollectCategories(oEntryXmlNode, sVideoID,
                                      oXmlNamespaceManager, oCategoryDictionary);
                }
            }
        }