Utility methods for creating Twitter GraphML XML documents for use with the NodeXL Excel Template.
Наследование: Object
Пример #1
0
        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);
        }
        GetMentionsAndRepliesToScreenNames
        (
            Dictionary <String, TwitterUser> userIDDictionary
        )
        {
            Debug.Assert(userIDDictionary != null);

            HashSet <String> uniqueScreenNamesWhoTweetedSearchTerm =
                TwitterGraphMLUtil.TwitterUsersToUniqueScreenNames(
                    userIDDictionary.Values);

            HashSet <String> uniqueMentionsAndRepliesToScreenNames =
                new HashSet <String>();

            TwitterStatusTextParser twitterStatusTextParser =
                new TwitterStatusTextParser();

            foreach (TwitterUser twitterUser in userIDDictionary.Values)
            {
                foreach (TwitterStatus twitterStatus in twitterUser.Statuses)
                {
                    String    repliesToScreenName;
                    String [] uniqueMentionsScreenNames;

                    twitterStatusTextParser.GetScreenNames(twitterStatus.Text,
                                                           out repliesToScreenName,
                                                           out uniqueMentionsScreenNames);

                    if (
                        repliesToScreenName != null
                        &&
                        !uniqueScreenNamesWhoTweetedSearchTerm.Contains(
                            repliesToScreenName))
                    {
                        uniqueMentionsAndRepliesToScreenNames.Add(
                            repliesToScreenName);
                    }

                    foreach (String uniqueMentionsScreenName in
                             uniqueMentionsScreenNames)
                    {
                        if (!uniqueScreenNamesWhoTweetedSearchTerm.Contains(
                                uniqueMentionsScreenName))
                        {
                            uniqueMentionsAndRepliesToScreenNames.Add(
                                uniqueMentionsScreenName);
                        }
                    }
                }
            }

            return(uniqueMentionsAndRepliesToScreenNames.ToArray());
        }
        TryAppendVertexXmlNode
        (
            Dictionary <String, Object> userValueDictionary,
            Boolean userTweetedSearchTerm,
            GraphMLXmlDocument graphMLXmlDocument,
            Dictionary <String, TwitterUser> userIDDictionary,
            out TwitterUser twitterUser
        )
        {
            Debug.Assert(userValueDictionary != null);
            Debug.Assert(graphMLXmlDocument != null);
            Debug.Assert(userIDDictionary != null);

            twitterUser = null;

            String screenName, userID;

            if (
                !TwitterJsonUtil.TryGetJsonValueFromDictionary(userValueDictionary,
                                                               "screen_name", out screenName)
                ||
                !TwitterJsonUtil.TryGetJsonValueFromDictionary(userValueDictionary,
                                                               "id_str", out userID)
                )
            {
                return(false);
            }

            screenName = screenName.ToLower();

            Boolean isFirstTweetForAuthor =
                TwitterGraphMLUtil.TryAppendVertexXmlNode(
                    screenName, userID, graphMLXmlDocument, userIDDictionary,
                    out twitterUser);

            if (isFirstTweetForAuthor)
            {
                TwitterGraphMLUtil.AppendCommonUserInformationFromValueDictionary(
                    userValueDictionary, graphMLXmlDocument, twitterUser);

                TwitterGraphMLUtil.AppendUserStatisticsFromValueDictionary(
                    userValueDictionary, graphMLXmlDocument, twitterUser);

                AppendTweetedSearchTermGraphMLAttributeValue(
                    graphMLXmlDocument, twitterUser, userTweetedSearchTerm);
            }

            return(true);
        }
        CreateGraphMLXmlDocument()
        {
            GraphMLXmlDocument graphMLXmlDocument = new GraphMLXmlDocument(true);

            TwitterGraphMLUtil.DefineVertexStatisticsGraphMLAttributes(
                graphMLXmlDocument);

            TwitterGraphMLUtil.DefineCommonGraphMLAttributes(graphMLXmlDocument);

            graphMLXmlDocument.DefineVertexStringGraphMLAttributes(
                VertexTweetedSearchTermID, "Tweeted Search Term?");

            graphMLXmlDocument.DefineVertexStringGraphMLAttributes(
                VertexToolTipID, "Tooltip");

            TwitterGraphMLUtil.DefineEdgeStatusGraphMLAttributes(
                graphMLXmlDocument);

            return(graphMLXmlDocument);
        }