AddTweetDateRangeToNetworkDescription
    (
        XmlDocument graphMLXmlDocument,
        NetworkDescriber networkDescriber
    )
    {
        Debug.Assert(graphMLXmlDocument != null);
        Debug.Assert(networkDescriber != null);

        XmlNamespaceManager oXmlNamespaceManager = new XmlNamespaceManager(
            graphMLXmlDocument.NameTable);

        oXmlNamespaceManager.AddNamespace("g",
            GraphMLXmlDocument.GraphMLNamespaceUri);

        DateTime oMinimumRelationshipDateUtc = DateTime.MaxValue;
        DateTime oMaximumRelationshipDateUtc = DateTime.MinValue;

        // Loop through the graph's edges.

        foreach ( XmlNode oEdgeXmlNode in
            graphMLXmlDocument.DocumentElement.SelectNodes(
                "g:graph/g:edge", oXmlNamespaceManager) )
        {
            // Get the value of the edge's "relationship" GraphML-Attribute.

            String sRelationship;

            if ( !TryGetEdgeGraphMLAttributeValue(oEdgeXmlNode,
                NodeXLGraphMLUtil.EdgeRelationshipID, oXmlNamespaceManager,
                out sRelationship) )
            {
                continue;
            }

            switch (sRelationship)
            {
                case TwitterGraphMLUtil.RepliesToRelationship:
                case TwitterGraphMLUtil.MentionsRelationship:
                case TwitterGraphMLUtil.NonRepliesToNonMentionsRelationship:

                    // Get the value of the edge's "relationship date"
                    // GraphML-Attribute.

                    String sRelationshipDateUtc;

                    if ( !TryGetEdgeGraphMLAttributeValue(oEdgeXmlNode,
                        TwitterGraphMLUtil.EdgeRelationshipDateUtcID,
                        oXmlNamespaceManager, out sRelationshipDateUtc) )
                    {
                        break;
                    }

                    DateTime oRelationshipDateUtc;

                    try
                    {
                        // Note that the relationship date may be in an
                        // unrecognized format.

                        oRelationshipDateUtc =
                            DateTimeUtil2.FromCultureInvariantString(
                                sRelationshipDateUtc);
                    }
                    catch (FormatException)
                    {
                        break;
                    }

                    if (oRelationshipDateUtc < oMinimumRelationshipDateUtc)
                    {
                        oMinimumRelationshipDateUtc = oRelationshipDateUtc;
                    }

                    if (oRelationshipDateUtc > oMaximumRelationshipDateUtc)
                    {
                        oMaximumRelationshipDateUtc = oRelationshipDateUtc;
                    }

                    break;

                default:

                    break;
            }
        }

        if (oMinimumRelationshipDateUtc != DateTime.MaxValue)
        {
            networkDescriber.AddSentence(
                "The tweets in the network were tweeted over the {0} period"
                + " from {1} to {2}."
                ,
                networkDescriber.FormatDuration(oMinimumRelationshipDateUtc, 
                    oMaximumRelationshipDateUtc),

                networkDescriber.FormatEventTime(oMinimumRelationshipDateUtc),
                networkDescriber.FormatEventTime(oMaximumRelationshipDateUtc)
                );
        }
    }
Exemple #2
0
        GetNetworkDescription
        (
            StatusCriteria oStatusCriteria,
            XmlDocument oGraphMLXmlDocument
        )
        {
            Debug.Assert(oStatusCriteria != null);
            Debug.Assert(oGraphMLXmlDocument != null);
            AssertValid();

            const String Int32FormatString = "N0";

            NetworkDescriber oNetworkDescriber = new NetworkDescriber();

            Int32 iVertexCount = GetVertexCount(oGraphMLXmlDocument);

            oNetworkDescriber.AddSentence(

                "The graph represents a network of {0} Twitter {1} whose tweets in"
                + " the requested range contained \"{2}\", or who {3} replied to"
                + " or mentioned in those tweets."
                ,
                iVertexCount.ToString(Int32FormatString),
                StringUtil.MakePlural("user", iVertexCount),
                oStatusCriteria.SearchTerm,
                iVertexCount > 1 ? "were" : "was"
                );

            oNetworkDescriber.AddNetworkTime(NetworkSource);

            if (oStatusCriteria.HasDateRange)
            {
                oNetworkDescriber.AddSentenceNewParagraph(

                    "The requested date range was from {0} through {1}."
                    ,
                    oNetworkDescriber.FormatEventTime(
                        oStatusCriteria.MinimumStatusDateUtc),

                    oNetworkDescriber.FormatEventTime(
                        oStatusCriteria.MaximumStatusDateUtc)
                    );
            }
            else
            {
                oNetworkDescriber.AddSentenceNewParagraph(

                    "The requested start date was {0} and the maximum number of"
                    + " tweets (going backward in time) was {1}."
                    ,
                    oNetworkDescriber.FormatEventTime(
                        oStatusCriteria.MaximumStatusDateUtc),

                    oStatusCriteria.MaximumStatusesGoingBackward.ToString(
                        Int32FormatString)
                    );
            }

            oNetworkDescriber.StartNewParagraph();

            TweetDateRangeAnalyzer.AddTweetDateRangeToNetworkDescription(
                oGraphMLXmlDocument, oNetworkDescriber);

            oNetworkDescriber.AddSentenceNewParagraph(
                "There is an edge for each \"replies-to\" relationship in a tweet,"
                + " an edge for each \"mentions\" relationship in a tweet, and a"
                + " self-loop edge for each tweet that is not a \"replies-to\" or"
                + " \"mentions\"."
                );

            return(oNetworkDescriber.ConcatenateSentences());
        }
    GetNetworkDescription
    (
        String sSearchTerm,
        DateTime oMinimumStatusDateUtc,
        DateTime oMaximumStatusDateUtc,
        String sGraphServerUserName,
        String sGraphServerPassword,
        XmlDocument oGraphMLXmlDocument
    )
    {
        Debug.Assert( !String.IsNullOrEmpty(sSearchTerm) );
        Debug.Assert(oMaximumStatusDateUtc >= oMinimumStatusDateUtc);
        Debug.Assert( !String.IsNullOrEmpty(sGraphServerUserName) );
        Debug.Assert( !String.IsNullOrEmpty(sGraphServerPassword) );
        Debug.Assert(oGraphMLXmlDocument != null);
        AssertValid();

        const String Int32FormatString = "N0";

        NetworkDescriber oNetworkDescriber = new NetworkDescriber();

        Int32 iVertexCount = GetVertexCount(oGraphMLXmlDocument);

        oNetworkDescriber.AddSentence(

            "The graph represents a network of {0} Twitter {1} whose tweets in"
            + " the requested date range contained \"{2}\", or who {3} replied"
            + " to or mentioned in those tweets."
            ,
            iVertexCount.ToString(Int32FormatString),
            StringUtil.MakePlural("user", iVertexCount),
            sSearchTerm,
			iVertexCount > 1 ? "were" : "was"
            );

        oNetworkDescriber.AddNetworkTime(NetworkSource);

        oNetworkDescriber.AddSentenceNewParagraph(

            "The requested date range was from {0} through {1}."
            ,
            oNetworkDescriber.FormatEventTime(oMinimumStatusDateUtc),
            oNetworkDescriber.FormatEventTime(oMaximumStatusDateUtc)
            );

        oNetworkDescriber.StartNewParagraph();

        TweetDateRangeAnalyzer.AddTweetDateRangeToNetworkDescription(
            oGraphMLXmlDocument, oNetworkDescriber);

        oNetworkDescriber.AddSentenceNewParagraph(
            "There is an edge for each \"replies-to\" relationship in a tweet,"
            + " an edge for each \"mentions\" relationship in a tweet, and a"
            + " self-loop edge for each tweet that is not a \"replies-to\" or"
            + " \"mentions\"."
            );

        return ( oNetworkDescriber.ConcatenateSentences() );
    }
        AddTweetDateRangeToNetworkDescription
        (
            XmlDocument graphMLXmlDocument,
            NetworkDescriber networkDescriber
        )
        {
            Debug.Assert(graphMLXmlDocument != null);
            Debug.Assert(networkDescriber != null);

            XmlNamespaceManager oXmlNamespaceManager = new XmlNamespaceManager(
                graphMLXmlDocument.NameTable);

            oXmlNamespaceManager.AddNamespace("g",
                                              GraphMLXmlDocument.GraphMLNamespaceUri);

            DateTime oMinimumRelationshipDateUtc = DateTime.MaxValue;
            DateTime oMaximumRelationshipDateUtc = DateTime.MinValue;

            // Loop through the graph's edges.

            foreach (XmlNode oEdgeXmlNode in
                     graphMLXmlDocument.DocumentElement.SelectNodes(
                         "g:graph/g:edge", oXmlNamespaceManager))
            {
                // Get the value of the edge's "relationship" GraphML-Attribute.

                String sRelationship;

                if (!TryGetEdgeGraphMLAttributeValue(oEdgeXmlNode,
                                                     NodeXLGraphMLUtil.EdgeRelationshipID, oXmlNamespaceManager,
                                                     out sRelationship))
                {
                    continue;
                }

                switch (sRelationship)
                {
                case TwitterGraphMLUtil.RepliesToRelationship:
                case TwitterGraphMLUtil.MentionsRelationship:
                case TwitterGraphMLUtil.NonRepliesToNonMentionsRelationship:

                    // Get the value of the edge's "relationship date"
                    // GraphML-Attribute.

                    String sRelationshipDateUtc;

                    if (!TryGetEdgeGraphMLAttributeValue(oEdgeXmlNode,
                                                         TwitterGraphMLUtil.EdgeRelationshipDateUtcID,
                                                         oXmlNamespaceManager, out sRelationshipDateUtc))
                    {
                        break;
                    }

                    DateTime oRelationshipDateUtc;

                    try
                    {
                        // Note that the relationship date may be in an
                        // unrecognized format.

                        oRelationshipDateUtc =
                            DateTimeUtil2.FromCultureInvariantString(
                                sRelationshipDateUtc);
                    }
                    catch (FormatException)
                    {
                        break;
                    }

                    if (oRelationshipDateUtc < oMinimumRelationshipDateUtc)
                    {
                        oMinimumRelationshipDateUtc = oRelationshipDateUtc;
                    }

                    if (oRelationshipDateUtc > oMaximumRelationshipDateUtc)
                    {
                        oMaximumRelationshipDateUtc = oRelationshipDateUtc;
                    }

                    break;

                default:

                    break;
                }
            }

            if (oMinimumRelationshipDateUtc != DateTime.MaxValue)
            {
                networkDescriber.AddSentence(
                    "The tweets in the network were tweeted over the {0} period"
                    + " from {1} to {2}."
                    ,
                    networkDescriber.FormatDuration(oMinimumRelationshipDateUtc,
                                                    oMaximumRelationshipDateUtc),

                    networkDescriber.FormatEventTime(oMinimumRelationshipDateUtc),
                    networkDescriber.FormatEventTime(oMaximumRelationshipDateUtc)
                    );
            }
        }