TryFromStatusValueDictionary ( Dictionary<String, Object> statusValueDictionary, Boolean expandStatusUrls, out TwitterStatus twitterStatus ) { Debug.Assert(statusValueDictionary != null); twitterStatus = null; // Get the status information. String statusID, statusText; if ( !TwitterJsonUtil.TryGetJsonValueFromDictionary( statusValueDictionary, "id_str", out statusID) || !TwitterJsonUtil.TryGetJsonValueFromDictionary( statusValueDictionary, "text", out statusText) ) { return (false); } String statusDateUtc; if ( TwitterJsonUtil.TryGetJsonValueFromDictionary( statusValueDictionary, "created_at", out statusDateUtc) ) { statusDateUtc = TwitterDateParser.ParseTwitterDate(statusDateUtc); } String latitude, longitude; TwitterGraphMLUtil.GetLatitudeAndLongitudeFromStatusValueDictionary( statusValueDictionary, out latitude, out longitude); String statusUrls, statusHashtags; TwitterGraphMLUtil.GetUrlsAndHashtagsFromStatusValueDictionary( statusValueDictionary, expandStatusUrls, out statusUrls, out statusHashtags); String inReplyToStatusID; TwitterJsonUtil.TryGetJsonValueFromDictionary( statusValueDictionary, "in_reply_to_status_id_str", out inReplyToStatusID); // Note that null date, coordinates, URLs hashtags, and in-reply-to-ID // are acceptable here. twitterStatus = new TwitterStatus( statusID, statusText, statusDateUtc, latitude, longitude, statusUrls, statusHashtags, inReplyToStatusID); return (true); }
AppendRepliesToAndMentionsEdgeXmlNodes ( GraphMLXmlDocument graphMLXmlDocument, TwitterStatusTextParser twitterStatusTextParser, HashSet <String> uniqueScreenNames, String screenName, TwitterStatus twitterStatus ) { Debug.Assert(graphMLXmlDocument != null); Debug.Assert(twitterStatusTextParser != null); Debug.Assert(uniqueScreenNames != null); Debug.Assert(!String.IsNullOrEmpty(screenName)); Debug.Assert(twitterStatus != null); String statusText = twitterStatus.Text; Boolean isReplyTo = false; Boolean isMentions = false; Debug.Assert(!String.IsNullOrEmpty(statusText)); String repliedToScreenName; String [] uniqueMentionedScreenNames; twitterStatusTextParser.GetScreenNames(statusText, out repliedToScreenName, out uniqueMentionedScreenNames); if (repliedToScreenName != null) { if ( repliedToScreenName != screenName && uniqueScreenNames.Contains(repliedToScreenName) ) { isReplyTo = true; AppendRepliesToAndMentionsEdgeXmlNode( graphMLXmlDocument, screenName, repliedToScreenName, RepliesToRelationship, twitterStatus); } } foreach (String mentionedScreenName in uniqueMentionedScreenNames) { if ( mentionedScreenName != screenName && uniqueScreenNames.Contains(mentionedScreenName) ) { isMentions = true; AppendRepliesToAndMentionsEdgeXmlNode( graphMLXmlDocument, screenName, mentionedScreenName, MentionsRelationship, twitterStatus); } } if (!isReplyTo && !isMentions) { // Append a self-loop edge to represent the tweet. AppendRepliesToAndMentionsEdgeXmlNode( graphMLXmlDocument, screenName, screenName, NonRepliesToNonMentionsRelationship, twitterStatus); } }
AppendRepliesToAndMentionsEdgeXmlNode ( GraphMLXmlDocument graphMLXmlDocument, String screenName1, String screenName2, String relationship, TwitterStatus twitterStatus ) { Debug.Assert(graphMLXmlDocument != null); Debug.Assert(!String.IsNullOrEmpty(screenName1)); Debug.Assert(!String.IsNullOrEmpty(screenName2)); Debug.Assert(!String.IsNullOrEmpty(relationship)); Debug.Assert(twitterStatus != null); XmlNode edgeXmlNode = NodeXLGraphMLUtil.AppendEdgeXmlNode( graphMLXmlDocument, screenName1, screenName2, relationship); String statusDateUtc = twitterStatus.ParsedDateUtc; Boolean hasStatusDateUtc = !String.IsNullOrEmpty(statusDateUtc); if (hasStatusDateUtc) { // The status's date is the relationship date. graphMLXmlDocument.AppendGraphMLAttributeValue(edgeXmlNode, EdgeRelationshipDateUtcID, statusDateUtc); } String statusText = twitterStatus.Text; graphMLXmlDocument.AppendGraphMLAttributeValue(edgeXmlNode, EdgeStatusID, statusText); String urls = twitterStatus.Urls; if (!String.IsNullOrEmpty(urls)) { graphMLXmlDocument.AppendGraphMLAttributeValue(edgeXmlNode, EdgeStatusUrlsID, urls); graphMLXmlDocument.AppendGraphMLAttributeValue(edgeXmlNode, EdgeStatusDomainsID, UrlsToDomains(urls)); } if (!String.IsNullOrEmpty(twitterStatus.Hashtags)) { graphMLXmlDocument.AppendGraphMLAttributeValue(edgeXmlNode, EdgeStatusHashtagsID, twitterStatus.Hashtags); } if (hasStatusDateUtc) { graphMLXmlDocument.AppendGraphMLAttributeValue(edgeXmlNode, EdgeStatusDateUtcID, statusDateUtc); } graphMLXmlDocument.AppendGraphMLAttributeValue(edgeXmlNode, EdgeStatusWebPageUrlID, FormatStatusWebPageUrl(screenName1, twitterStatus) ); AppendLatitudeAndLongitudeGraphMLAttributeValues( graphMLXmlDocument, edgeXmlNode, twitterStatus.Latitude, twitterStatus.Longitude); // Precede the ID with a single quote to force Excel to treat the // ID as text. Otherwise, it formats the ID, which is a large // number, in scientific notation. graphMLXmlDocument.AppendGraphMLAttributeValue(edgeXmlNode, NodeXLGraphMLUtil.ImportedIDID, "'" + twitterStatus.ID); AppendInReplyToStatusIDGraphMLAttributeValue(graphMLXmlDocument, edgeXmlNode, twitterStatus.InReplyToStatusID); }
AppendRepliesToAndMentionsEdgeXmlNodes ( GraphMLXmlDocument graphMLXmlDocument, TwitterStatusTextParser twitterStatusTextParser, HashSet<String> uniqueScreenNames, Boolean includeRepliesToEdges, Boolean includeMentionsEdges, Boolean includeNonRepliesToNonMentionsEdges, String screenName, TwitterStatus twitterStatus, Boolean includeStatus ) { Debug.Assert(graphMLXmlDocument != null); Debug.Assert(twitterStatusTextParser != null); Debug.Assert(uniqueScreenNames != null); Debug.Assert( !String.IsNullOrEmpty(screenName) ); Debug.Assert(twitterStatus != null); String statusText = twitterStatus.Text; Boolean isReplyTo = false; Boolean isMentions = false; Debug.Assert( !String.IsNullOrEmpty(statusText) ); String repliedToScreenName; String [] uniqueMentionedScreenNames; twitterStatusTextParser.GetScreenNames(statusText, out repliedToScreenName, out uniqueMentionedScreenNames); if (repliedToScreenName != null) { if ( repliedToScreenName != screenName && uniqueScreenNames.Contains(repliedToScreenName) ) { isReplyTo = true; if (includeRepliesToEdges) { AppendRepliesToAndMentionsEdgeXmlNode( graphMLXmlDocument, screenName, repliedToScreenName, RepliesToRelationship, twitterStatus, includeStatus); } } } foreach (String mentionedScreenName in uniqueMentionedScreenNames) { if ( mentionedScreenName != screenName && uniqueScreenNames.Contains(mentionedScreenName) ) { isMentions = true; if (includeMentionsEdges) { AppendRepliesToAndMentionsEdgeXmlNode( graphMLXmlDocument, screenName, mentionedScreenName, MentionsRelationship, twitterStatus, includeStatus); } } } if (includeNonRepliesToNonMentionsEdges && !isReplyTo && !isMentions) { // Append a self-loop edge to represent the tweet. AppendRepliesToAndMentionsEdgeXmlNode( graphMLXmlDocument, screenName, screenName, NonRepliesToNonMentionsRelationship, twitterStatus, includeStatus); } }
FormatStatusWebPageUrl ( String screenName, TwitterStatus twitterStatus ) { Debug.Assert( !String.IsNullOrEmpty(screenName) ); Debug.Assert(twitterStatus != null); return ( String.Format( TwitterApiUrls.StatusWebPageUrlPattern , screenName, twitterStatus.ID ) ); }
AppendRepliesToAndMentionsEdgeXmlNode ( GraphMLXmlDocument graphMLXmlDocument, String screenName1, String screenName2, String relationship, TwitterStatus twitterStatus, Boolean includeStatus ) { Debug.Assert(graphMLXmlDocument != null); Debug.Assert( !String.IsNullOrEmpty(screenName1) ); Debug.Assert( !String.IsNullOrEmpty(screenName2) ); Debug.Assert( !String.IsNullOrEmpty(relationship) ); Debug.Assert(twitterStatus != null); XmlNode edgeXmlNode = NodeXLGraphMLUtil.AppendEdgeXmlNode( graphMLXmlDocument, screenName1, screenName2, relationship); String statusDateUtc = twitterStatus.ParsedDateUtc; Boolean hasStatusDateUtc = !String.IsNullOrEmpty(statusDateUtc); if (hasStatusDateUtc) { // The status's date is the relationship date. graphMLXmlDocument.AppendGraphMLAttributeValue(edgeXmlNode, EdgeRelationshipDateUtcID, statusDateUtc); } if (includeStatus) { String statusText = twitterStatus.Text; graphMLXmlDocument.AppendGraphMLAttributeValue(edgeXmlNode, EdgeStatusID, statusText); String urls = twitterStatus.Urls; if ( !String.IsNullOrEmpty(urls) ) { graphMLXmlDocument.AppendGraphMLAttributeValue(edgeXmlNode, EdgeStatusUrlsID, urls); graphMLXmlDocument.AppendGraphMLAttributeValue( edgeXmlNode, EdgeStatusDomainsID, UrlsToDomains(urls) ); } if ( !String.IsNullOrEmpty(twitterStatus.Hashtags) ) { graphMLXmlDocument.AppendGraphMLAttributeValue(edgeXmlNode, EdgeStatusHashtagsID, twitterStatus.Hashtags); } if (hasStatusDateUtc) { graphMLXmlDocument.AppendGraphMLAttributeValue(edgeXmlNode, EdgeStatusDateUtcID, statusDateUtc); } graphMLXmlDocument.AppendGraphMLAttributeValue(edgeXmlNode, EdgeStatusWebPageUrlID, FormatStatusWebPageUrl(screenName1, twitterStatus) ); AppendLatitudeAndLongitudeGraphMLAttributeValues( graphMLXmlDocument, edgeXmlNode, twitterStatus.Latitude, twitterStatus.Longitude); // Precede the ID with a single quote to force Excel to treat the // ID as text. Otherwise, it formats the ID, which is a large // number, in scientific notation. graphMLXmlDocument.AppendGraphMLAttributeValue(edgeXmlNode, NodeXLGraphMLUtil.ImportedIDID, "'" + twitterStatus.ID); AppendInReplyToStatusIDGraphMLAttributeValue(graphMLXmlDocument, edgeXmlNode, twitterStatus.InReplyToStatusID); } }