Ejemplo n.º 1
0
        public IActionResult Index(string screenname, string order)
        {
            // TODO handle hashtags separately
            int markovOrder;
            // default order is 2, if the parse failed
            if (!int.TryParse(order, out markovOrder))
                markovOrder = 2;

            // hack to avoid null pointer exception
            if (markovOrder > 5)
                markovOrder = 5;
            int tweetCount = 200;
            var generator = new MarkovGenerator(markovOrder, false);
            
            // how to handle hashtags? just keep a list of them along with a probability for each,
            // i.e. a single-prefix markov chain?
            // would also need a no-hashtag probability
            // no, that won't work, since there wouldn't be an end point, really. at least not one that makes sense.
            
            // what might work is keeping track of individual hashtag probabilities,
            // as well as a probability distribution of number of hashtags. (fun to get some stats on that, see if it's poisson-distributed)

            ViewData["Screenname"] = screenname;

            var auth = new SingleUserAuthorizer
            {
                CredentialStore = new SingleUserInMemoryCredentialStore
                {
                    ConsumerKey = _consumerKey,
                    ConsumerSecret = _consumerSecret,
                    AccessToken = _accessToken,
                    AccessTokenSecret = _accessTokenSecret
                }
            };

            var twitterCtx = new TwitterContext(auth);
            var timeline =
                (twitterCtx.Status.Where(tweet => tweet.Type == StatusType.User &&
                                                  tweet.ScreenName == screenname &&
                                                  tweet.Count == tweetCount))
                    .ToList();

            foreach (var tweet in timeline)
            {
                generator.ReadInput(tweet.Text);
            }

            int outputCount = 20;
            var outputList = new List<string>();
            for (int i = 0; i < outputCount; i++)
            {
                outputList.Add(generator.GenerateOutput());
            }

            //TODO add form
            //TODO use form data
            return View(outputList);
        }