void AssertCategory(string body, string expected)
        {
            var categorizer = new TweetCategorizer();
            var result      = categorizer.Categorize("2011/03/21 13:00:55\tbleis\t" + body);

            Assert.That(result.Categories, Is.EqualTo(new[] { expected }));
        }
        public void 普通のTweetがNormalに判定される()
        {
            var categorizer = new TweetCategorizer();
            var result      = categorizer.Categorize("2011/03/21 11:19:05\tbleis\tほげほげ");

            Assert.That(result.Categories, Is.EqualTo(new[] { "Normal" }));
        }
예제 #3
0
        public async System.Threading.Tasks.Task <ActionResult> Index()
        {
            /*
             * ===================================== PROSES DICTIONARY =====================================
             */

            dictionaries    = new Dictionary[5];
            dictionaries[0] = new Dictionary("DINAS_1"); dictionaries[0].convertToDictionary(user_input.dinas1);
            dictionaries[1] = new Dictionary("DINAS_2"); dictionaries[1].convertToDictionary(user_input.dinas2);
            dictionaries[2] = new Dictionary("DINAS_3"); dictionaries[2].convertToDictionary(user_input.dinas3);
            dictionaries[3] = new Dictionary("DINAS_4"); dictionaries[3].convertToDictionary(user_input.dinas4);
            dictionaries[4] = new Dictionary("DINAS_5"); dictionaries[4].convertToDictionary(user_input.dinas5);

            /*
             * ===================================== PROSES & UPDATE TWITTER =====================================
             */
            tweets = new Tweet[100];

            /* Parsing untuk Search API */
            Parser P          = new Parser();
            string inputQuery = user_input.keywords;
            string query      = P.Parse(inputQuery);
            string _address   = "https://api.twitter.com/1.1/search/tweets.json?q=" + query + "&count=100";

            // Create client and insert an OAuth message handler in the message path that
            // inserts an OAuth authentication header in the request
            HttpClient client = new HttpClient(new OAuthMessageHandler(new HttpClientHandler()));

            // Send asynchronous request to twitter and read the response as JToken
            HttpResponseMessage response = await client.GetAsync(_address);

            int i = 0;

            if (response.IsSuccessStatusCode)
            {
                JToken statuses1 = await response.Content.ReadAsAsync <JToken>();

                JToken statuses2 = statuses1.SelectToken("statuses");
                foreach (var status in statuses2)
                {
                    JToken user      = status.SelectToken("user");
                    string user_name = user["screen_name"].ToString();
                    string image_url = user["profile_image_url"].ToString();
                    string B         = status["text"].ToString();
                    string name      = user["name"].ToString();
                    string tweet_url = "http://twitter.com/statuses/" + status["id"].ToString();

                    /* Retrieve Kordinat lokasi tweet dan memasukkannya  ke tweet */
                    string location  = user["location"].ToString();
                    double latitude  = 0.0;
                    double longitude = 0.0;
                    if (location != null && location != "")
                    {
                        HttpClient MapClient  = new HttpClient();
                        string     mapRequest = P.ParserMaps(location);
                        Console.WriteLine("location " + mapRequest);
                        string addressForMap = "http://maps.googleapis.com/maps/api/geocode/json?address=" + mapRequest;
                        Console.WriteLine(addressForMap);
                        HttpResponseMessage responseMap = await MapClient.GetAsync(addressForMap);

                        responseMap.EnsureSuccessStatusCode();
                        JToken mapsJSON = await responseMap.Content.ReadAsAsync <JToken>();

                        JToken result = mapsJSON.SelectToken("results[0]");
                        if (result != null)
                        {
                            JToken geometry     = result.SelectToken("geometry");
                            JToken locationMaps = geometry.SelectToken("location");
                            latitude  = (double)locationMaps["lat"];
                            longitude = (double)locationMaps["lng"];
                        }
                    }
                    Tweet x = new Tweet(B, user_name, image_url, name, tweet_url, latitude, longitude);
                    x.analyzeMe(dictionaries, user_input.choice);
                    tweets[i] = x;
                    i++;
                }
            }
            TweetCategorizer tweetCategorized = new TweetCategorizer();

            tweetCategorized.Categorize(dictionaries, tweets, i);
            ViewBag.Tweets            = tweets;
            ViewBag.TweetsCategorized = tweetCategorized;
            return(View());
        }
        public void 複数の種類を含むTweetの判定結果に含まれるすべての種類が存在する(string body, string[] expectedCategories)
        {
            var categorizer = new TweetCategorizer();

            Assert.That(categorizer.Categorize("2011/12/23 00:00:00\tbleis\t" + body).Categories, Is.EquivalentTo(expectedCategories));
        }