GetNetworkInternal ( String sSearchTerm, WhatToInclude eWhatToInclude, Int32 iMaximumStatuses, RequestStatistics oRequestStatistics, GraphMLXmlDocument oGraphMLXmlDocument ) { Debug.Assert(!String.IsNullOrEmpty(sSearchTerm)); Debug.Assert(iMaximumStatuses > 0); Debug.Assert(iMaximumStatuses != Int32.MaxValue); Debug.Assert(oRequestStatistics != null); Debug.Assert(oGraphMLXmlDocument != null); AssertValid(); // The key is the Twitter user ID and the value is the corresponding // TwitterUser. Dictionary <String, TwitterUser> oUserIDDictionary = new Dictionary <String, TwitterUser>(); // First, append a vertex for each person who has tweeted the search // term. AppendVertexXmlNodesForSearchTerm(sSearchTerm, eWhatToInclude, iMaximumStatuses, oGraphMLXmlDocument, oUserIDDictionary, oRequestStatistics); // Now append a vertex for each person who was mentioned or replied to // by the first set of people, but who didn't tweet the search term // himself. AppendVertexXmlNodesForMentionsAndRepliesTo(eWhatToInclude, oGraphMLXmlDocument, oUserIDDictionary, oRequestStatistics); TwitterSearchNetworkGraphMLUtil.AppendVertexTooltipXmlNodes( oGraphMLXmlDocument, oUserIDDictionary); if (WhatToIncludeFlagIsSet(eWhatToInclude, WhatToInclude.FollowedEdges)) { // Look at each author's friends, and if a friend has also tweeted // the search term, add an edge between the author and the friend. AppendFriendEdgeXmlNodes(oUserIDDictionary, MaximumFriends, oGraphMLXmlDocument, oRequestStatistics); } AppendRepliesToAndMentionsEdgeXmlNodes(oGraphMLXmlDocument, oUserIDDictionary.Values, TwitterGraphMLUtil.TwitterUsersToUniqueScreenNames( oUserIDDictionary.Values) ); }
AppendRepliesToAndMentionsEdgeXmlNodes ( GraphMLXmlDocument oGraphMLXmlDocument, IEnumerable <TwitterUser> oTwitterUsers, HashSet <String> oUniqueScreenNames ) { Debug.Assert(oGraphMLXmlDocument != null); Debug.Assert(oTwitterUsers != null); Debug.Assert(oUniqueScreenNames != null); AssertValid(); ReportProgress("Examining relationships."); TwitterGraphMLUtil.AppendRepliesToAndMentionsEdgeXmlNodes( oGraphMLXmlDocument, oTwitterUsers, oUniqueScreenNames); }
AppendUserInformationFromValueDictionary ( Dictionary <String, Object> oUserValueDictionary, GraphMLXmlDocument oGraphMLXmlDocument, TwitterUser oTwitterUser, Boolean bIncludeStatistics, Boolean bIncludeLatestStatus, Boolean bExpandLatestStatusUrls ) { Debug.Assert(oUserValueDictionary != null); Debug.Assert(oGraphMLXmlDocument != null); Debug.Assert(oTwitterUser != null); AssertValid(); TwitterGraphMLUtil.AppendCommonUserInformationFromValueDictionary( oUserValueDictionary, oGraphMLXmlDocument, oTwitterUser); if (bIncludeStatistics) { TwitterGraphMLUtil.AppendUserStatisticsFromValueDictionary( oUserValueDictionary, oGraphMLXmlDocument, oTwitterUser); } // Process the user's latest status if requested. Object oStatusValueDictionaryAsObject; if ( bIncludeLatestStatus && oUserValueDictionary.TryGetValue("status", out oStatusValueDictionaryAsObject) && oStatusValueDictionaryAsObject is Dictionary <String, Object> ) { Dictionary <String, Object> oStatusValueDictionary = (Dictionary <String, Object>)oStatusValueDictionaryAsObject; AppendLatestStatusInformationFromValueDictionary( oStatusValueDictionary, oGraphMLXmlDocument, oTwitterUser, bIncludeLatestStatus, bExpandLatestStatusUrls); } }
AppendFriendEdgeXmlNodes ( Dictionary <String, TwitterUser> oUserIDDictionary, Int32 iMaximumPeoplePerRequest, GraphMLXmlDocument oGraphMLXmlDocument, RequestStatistics oRequestStatistics ) { Debug.Assert(oUserIDDictionary != null); Debug.Assert(iMaximumPeoplePerRequest > 0); Debug.Assert(oGraphMLXmlDocument != null); Debug.Assert(oRequestStatistics != null); AssertValid(); AppendFriendEdgeXmlNodes( TwitterGraphMLUtil.TwitterUsersToUniqueScreenNames( oUserIDDictionary.Values), oUserIDDictionary, iMaximumPeoplePerRequest, oGraphMLXmlDocument, oRequestStatistics); }
AppendLatestStatusInformationFromValueDictionary ( Dictionary <String, Object> oStatusValueDictionary, GraphMLXmlDocument oGraphMLXmlDocument, TwitterUser oTwitterUser, Boolean bIncludeLatestStatus, Boolean bExpandLatestStatusUrls ) { Debug.Assert(oStatusValueDictionary != null); Debug.Assert(oGraphMLXmlDocument != null); Debug.Assert(oTwitterUser != null); AssertValid(); TwitterStatus oTwitterStatus; if (!TwitterStatus.TryFromStatusValueDictionary( oStatusValueDictionary, bExpandLatestStatusUrls, out oTwitterStatus)) { return; } XmlNode oVertexXmlNode = oTwitterUser.VertexXmlNode; if (bIncludeLatestStatus) { // Add the status to the vertex XML node. oGraphMLXmlDocument.AppendGraphMLAttributeValue( oVertexXmlNode, TwitterGraphMLUtil.VertexLatestStatusID, oTwitterStatus.Text); String sLatestStatusUrls = oTwitterStatus.Urls; if (!String.IsNullOrEmpty(sLatestStatusUrls)) { oGraphMLXmlDocument.AppendGraphMLAttributeValue( oVertexXmlNode, TwitterGraphMLUtil.VertexLatestStatusUrlsID, sLatestStatusUrls); oGraphMLXmlDocument.AppendGraphMLAttributeValue( oVertexXmlNode, TwitterGraphMLUtil.VertexLatestStatusDomainsID, TwitterGraphMLUtil.UrlsToDomains(sLatestStatusUrls)); } String sLatestStatusHashtags = oTwitterStatus.Hashtags; if (!String.IsNullOrEmpty(sLatestStatusHashtags)) { oGraphMLXmlDocument.AppendGraphMLAttributeValue( oVertexXmlNode, TwitterGraphMLUtil.VertexLatestStatusHashtagsID, sLatestStatusHashtags); } if (!String.IsNullOrEmpty(oTwitterStatus.ParsedDateUtc)) { oGraphMLXmlDocument.AppendGraphMLAttributeValue( oVertexXmlNode, TwitterGraphMLUtil.VertexLatestStatusDateUtcID, oTwitterStatus.ParsedDateUtc); } TwitterGraphMLUtil. AppendLatitudeAndLongitudeGraphMLAttributeValues( oGraphMLXmlDocument, oVertexXmlNode, oTwitterStatus.Latitude, oTwitterStatus.Longitude); TwitterGraphMLUtil.AppendInReplyToStatusIDGraphMLAttributeValue( oGraphMLXmlDocument, oVertexXmlNode, oTwitterStatus.InReplyToStatusID); } oTwitterUser.Statuses.Add(oTwitterStatus); }