//************************************************************************* // Method: CreateGraphMLXmlDocument() // /// <summary> /// Creates a GraphMLXmlDocument representing a network of YouTube videos. /// </summary> /// /// <returns> /// A GraphMLXmlDocument representing a network of YouTube videos. The /// document includes GraphML-attribute definitions but no vertices or /// edges. /// </returns> //************************************************************************* protected GraphMLXmlDocument CreateGraphMLXmlDocument() { AssertValid(); GraphMLXmlDocument oGraphMLXmlDocument = new GraphMLXmlDocument(false); DefineRelationshipGraphMLAttribute(oGraphMLXmlDocument); oGraphMLXmlDocument.DefineGraphMLAttribute(false, TitleID, "Title", "string", null); oGraphMLXmlDocument.DefineGraphMLAttribute(false, RatingID, "Rating", "double", null); oGraphMLXmlDocument.DefineGraphMLAttribute(false, ViewsID, "Views", "int", null); oGraphMLXmlDocument.DefineGraphMLAttribute(false, FavoritedID, "Favorited", "int", null); oGraphMLXmlDocument.DefineGraphMLAttribute(false, CommentsID, "Comments", "int", null); oGraphMLXmlDocument.DefineGraphMLAttribute(false, CreatedDateUtcID, "Created Date (UTC)", "string", null); DefineImageFileGraphMLAttribute(oGraphMLXmlDocument); DefineCustomMenuGraphMLAttributes(oGraphMLXmlDocument); return (oGraphMLXmlDocument); }
//************************************************************************* // Method: CreateGraphMLXmlDocument() // /// <summary> /// Creates a GraphMLXmlDocument representing a network of YouTube users. /// </summary> /// /// <param name="bIncludeAllStatistics"> /// true to include each user's statistics. /// </param> /// /// <returns> /// A GraphMLXmlDocument representing a network of YouTube users. The /// document includes GraphML-attribute definitions but no vertices or /// edges. /// </returns> //************************************************************************* protected GraphMLXmlDocument CreateGraphMLXmlDocument( Boolean bIncludeAllStatistics ) { AssertValid(); GraphMLXmlDocument oGraphMLXmlDocument = new GraphMLXmlDocument(true); DefineCustomMenuGraphMLAttributes(oGraphMLXmlDocument); DefineRelationshipGraphMLAttribute(oGraphMLXmlDocument); if (bIncludeAllStatistics) { oGraphMLXmlDocument.DefineGraphMLAttribute(false, FriendsID, "Friends", "int", null); oGraphMLXmlDocument.DefineGraphMLAttribute(false, SubscriptionsID, "People Subscribed To", "int", null); oGraphMLXmlDocument.DefineGraphMLAttribute(false, SubscribersID, "Subscribers", "int", null); oGraphMLXmlDocument.DefineGraphMLAttribute(false, VideosWatchedID, "Videos Watched", "int", null); oGraphMLXmlDocument.DefineGraphMLAttribute(false, JoinedDateUtcID, "Joined YouTube Date (UTC)", "string", null); oGraphMLXmlDocument.DefineGraphMLAttribute(false, VideosUploadedID, "Videos Uploaded", "int", null); DefineImageFileGraphMLAttribute(oGraphMLXmlDocument); } return (oGraphMLXmlDocument); }
//************************************************************************* // Method: GetSearchNetworkInternal() // /// <summary> /// Gets the network of people who have tweeted a specified search term, /// given a GraphMLXmlDocument. /// </summary> /// /// <param name="sSearchTerm"> /// The term to search for. /// </param> /// /// <param name="eWhatToInclude"> /// Specifies what should be included in the network. /// </param> /// /// <param name="iMaximumPeoplePerRequest"> /// Maximum number of people to request for each query, or Int32.MaxValue /// for no limit. /// </param> /// /// <param name="oRequestStatistics"> /// A <see cref="RequestStatistics" /> object that is keeping track of /// requests made while getting the network. /// </param> /// /// <param name="oGraphMLXmlDocument"> /// The GraphMLXmlDocument to populate with the requested network. /// </param> //************************************************************************* protected void GetSearchNetworkInternal( String sSearchTerm, WhatToInclude eWhatToInclude, Int32 iMaximumPeoplePerRequest, RequestStatistics oRequestStatistics, GraphMLXmlDocument oGraphMLXmlDocument ) { Debug.Assert( !String.IsNullOrEmpty(sSearchTerm) ); Debug.Assert(iMaximumPeoplePerRequest > 0); Debug.Assert(oRequestStatistics != null); Debug.Assert(oGraphMLXmlDocument != null); AssertValid(); if ( WhatToIncludeFlagIsSet(eWhatToInclude, WhatToInclude.Statuses) ) { oGraphMLXmlDocument.DefineGraphMLAttribute(false, StatusID, "Tweet", "string", null); oGraphMLXmlDocument.DefineGraphMLAttribute(false, StatusDateUtcID, "Tweet Date (UTC)", "string", null); } // The key is the screen name and the value is the corresponding // TwitterVertex. This is used to prevent the same screen name from // being added to the XmlDocument twice. Dictionary<String, TwitterVertex> oScreenNameDictionary = new Dictionary<String, TwitterVertex>(); // First, add a vertex for each person who has tweeted the search term. AppendVertexXmlNodes(sSearchTerm, eWhatToInclude, iMaximumPeoplePerRequest, oGraphMLXmlDocument, oScreenNameDictionary, oRequestStatistics); if ( WhatToIncludeFlagIsSet(eWhatToInclude, WhatToInclude.FollowedEdges) ) { // Look at the people followed by each author, and if a followed // has also tweeted the search term, add an edge between the author // and the followed. AppendFollowedEdgeXmlNodes(eWhatToInclude, iMaximumPeoplePerRequest, oGraphMLXmlDocument, oScreenNameDictionary, oRequestStatistics); } Boolean bIncludeStatistics = WhatToIncludeFlagIsSet( eWhatToInclude, WhatToInclude.Statistics); AppendMissingGraphMLAttributeValues(oGraphMLXmlDocument, oScreenNameDictionary, bIncludeStatistics, false, oRequestStatistics); AppendRepliesToAndMentionsXmlNodes(oGraphMLXmlDocument, oScreenNameDictionary, WhatToIncludeFlagIsSet(eWhatToInclude, WhatToInclude.RepliesToEdges), WhatToIncludeFlagIsSet(eWhatToInclude, WhatToInclude.MentionsEdges) ); }
//************************************************************************* // Method: DefineLabelGraphMLAttribute() // /// <summary> /// Defines a GraphML-Attribute for vertex labels. /// </summary> /// /// <param name="oGraphMLXmlDocument"> /// GraphMLXmlDocument being populated. /// </param> //************************************************************************* protected void DefineLabelGraphMLAttribute( GraphMLXmlDocument oGraphMLXmlDocument ) { Debug.Assert(oGraphMLXmlDocument != null); AssertValid(); oGraphMLXmlDocument.DefineGraphMLAttribute(false, LabelID, LabelColumnName, "string", null); }
//************************************************************************* // Method: DefineRelationshipGraphMLAttribute() // /// <summary> /// Defines a GraphML-Attribute for edge relationships. /// </summary> /// /// <param name="oGraphMLXmlDocument"> /// GraphMLXmlDocument being populated. /// </param> //************************************************************************* protected void DefineRelationshipGraphMLAttribute( GraphMLXmlDocument oGraphMLXmlDocument ) { Debug.Assert(oGraphMLXmlDocument != null); AssertValid(); oGraphMLXmlDocument.DefineGraphMLAttribute(true, RelationshipID, "Relationship", "string", null); }
//************************************************************************* // Method: DefineImageFileGraphMLAttribute() // /// <summary> /// Defines a GraphML-Attribute for vertex image files. /// </summary> /// /// <param name="oGraphMLXmlDocument"> /// GraphMLXmlDocument being populated. /// </param> //************************************************************************* protected void DefineImageFileGraphMLAttribute( GraphMLXmlDocument oGraphMLXmlDocument ) { Debug.Assert(oGraphMLXmlDocument != null); AssertValid(); oGraphMLXmlDocument.DefineGraphMLAttribute(false, ImageFileID, ImageColumnName, "string", null); }
//************************************************************************* // Method: DefineCustomMenuGraphMLAttributes() // /// <summary> /// Defines the GraphML-Attributes for custom menu items. /// </summary> /// /// <param name="oGraphMLXmlDocument"> /// GraphMLXmlDocument being populated. /// </param> //************************************************************************* protected void DefineCustomMenuGraphMLAttributes( GraphMLXmlDocument oGraphMLXmlDocument ) { Debug.Assert(oGraphMLXmlDocument != null); AssertValid(); oGraphMLXmlDocument.DefineGraphMLAttribute(false, MenuTextID, MenuTextColumnName, "string", null); oGraphMLXmlDocument.DefineGraphMLAttribute(false, MenuActionID, MenuActionColumnName, "string", null); }
//************************************************************************* // Method: SaveGraphCore() // /// <summary> /// Saves graph data to a stream. /// </summary> /// /// <param name="graph"> /// Graph to save. /// </param> /// /// <param name="stream"> /// Stream to save the graph data to. /// </param> /// /// <remarks> /// This method saves <paramref name="graph" /> to <paramref /// name="stream" />. It does not close <paramref name="stream" />. /// /// <para> /// The arguments have already been checked for validity. /// </para> /// /// </remarks> //************************************************************************* protected override void 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); }
//************************************************************************* // Method: CreateGraphMLXmlDocument() // /// <summary> /// Creates a GraphMLXmlDocument representing a network of Twitter users. /// </summary> /// /// <param name="bIncludeStatistics"> /// true to include each user's statistics. /// </param> /// /// <param name="bIncludeLatestStatuses"> /// true to include each user's latest status. /// </param> /// /// <returns> /// A GraphMLXmlDocument representing a network of Twitter users. The /// document includes GraphML-attribute definitions but no vertices or /// edges. /// </returns> //************************************************************************* protected GraphMLXmlDocument CreateGraphMLXmlDocument( Boolean bIncludeStatistics, Boolean bIncludeLatestStatuses ) { AssertValid(); GraphMLXmlDocument oGraphMLXmlDocument = new GraphMLXmlDocument(true); if (bIncludeStatistics) { oGraphMLXmlDocument.DefineGraphMLAttribute(false, FollowedID, "Followed", "int", null); oGraphMLXmlDocument.DefineGraphMLAttribute(false, FollowersID, "Followers", "int", null); oGraphMLXmlDocument.DefineGraphMLAttribute(false, StatusesID, "Tweets", "int", null); oGraphMLXmlDocument.DefineGraphMLAttribute(false, FavoritesID, "Favorites", "int", null); oGraphMLXmlDocument.DefineGraphMLAttribute(false, DescriptionID, "Description", "string", null); oGraphMLXmlDocument.DefineGraphMLAttribute(false, TimeZoneID, "Time Zone", "string", null); oGraphMLXmlDocument.DefineGraphMLAttribute(false, UtcOffsetID, "Time Zone UTC Offset (Seconds)", "int", null); oGraphMLXmlDocument.DefineGraphMLAttribute(false, JoinedDateUtcID, "Joined Twitter Date (UTC)", "string", null); } if (bIncludeLatestStatuses) { oGraphMLXmlDocument.DefineGraphMLAttribute(false, LatestStatusID, "Latest Tweet", "string", null); oGraphMLXmlDocument.DefineGraphMLAttribute(false, LatestStatusDateUtcID, "Latest Tweet Date (UTC)", "string", null); } DefineImageFileGraphMLAttribute(oGraphMLXmlDocument); DefineCustomMenuGraphMLAttributes(oGraphMLXmlDocument); DefineRelationshipGraphMLAttribute(oGraphMLXmlDocument); oGraphMLXmlDocument.DefineGraphMLAttribute(true, RelationshipDateUtcID, "Relationship Date (UTC)", "string", null); return (oGraphMLXmlDocument); }
//************************************************************************* // Method: CreateGraphMLXmlDocument() // /// <summary> /// Creates a GraphMLXmlDocument representing a network of Flickr users. /// </summary> /// /// <param name="bIncludeCommenterVertices"> /// true to include a vertex for each user who has commented on the user's /// photos. /// </param> /// /// <param name="bIncludeUserInformation"> /// true to include information about each user in the network. /// </param> /// /// <returns> /// A GraphMLXmlDocument representing a network of Flickr users. The /// document includes GraphML-attribute definitions but no vertices or /// edges. /// </returns> //************************************************************************* protected GraphMLXmlDocument CreateGraphMLXmlDocument( Boolean bIncludeCommenterVertices, Boolean bIncludeUserInformation ) { AssertValid(); GraphMLXmlDocument oGraphMLXmlDocument = new GraphMLXmlDocument(true); DefineRelationshipGraphMLAttribute(oGraphMLXmlDocument); if (bIncludeCommenterVertices) { oGraphMLXmlDocument.DefineGraphMLAttribute(true, CommentDateUtcID, "Comment Time (UTC)", "string", null); oGraphMLXmlDocument.DefineGraphMLAttribute(true, CommentUrlID, "Comment URL", "string", null); } if (bIncludeUserInformation) { oGraphMLXmlDocument.DefineGraphMLAttribute(false, RealNameID, "Real Name", "string", null); oGraphMLXmlDocument.DefineGraphMLAttribute(false, TotalPhotosID, "Total Photos", "int", null); oGraphMLXmlDocument.DefineGraphMLAttribute(false, IsProfessionalID, "Is Professional", "string", null); DefineImageFileGraphMLAttribute(oGraphMLXmlDocument); DefineCustomMenuGraphMLAttributes(oGraphMLXmlDocument); } return (oGraphMLXmlDocument); }