Esempio n. 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="movie"></param>
        /// <param name="parameters"></param>
        /// <returns></returns>
        public void GetMovieTrends(String movie, ref TMovieTrendsClass mTrends, params Object[] parameters)
        {
            //MovieTrendsClass mTrends = new MovieTrendsClass();

            int total = 10;

            if (parameters.Length > 0)
            {
                total = (int)parameters[0];
            }

            TSearchResultCollection searchResColl = this.SearchTwitter(movie, 1, 10);

            for (int index = 2; index < total; index++)
            {
                try
                {
                    searchResColl.Items.AddRange(this.SearchTwitter(movie, index, 10).Items);
                }
                catch { }
            }

            mTrends.FormTrend(searchResColl);
            return;// mTrends;
        }
Esempio n. 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="query"></param>
        /// <param name="offset"></param>
        /// <param name="count"></param>
        /// <returns></returns>
        public TSearchResultCollection SearchTwitter(String query, int offset, int limit)
        {
            TSearchResultCollection resultCollection = new TSearchResultCollection();

            resultCollection.Items = new List <TSearchResult>();
            xsd.feed feed = this.ProcessRequest(query, offset, limit);

            xsd.feedLink feedlinkAltSearch = (xsd.feedLink)Array.Find(feed.Items, fd => (fd is xsd.feedLink) && ((xsd.feedLink)fd).rel.Equals("alternate", StringComparison.InvariantCultureIgnoreCase));
            if (feedlinkAltSearch != null)
            {
                resultCollection.AlternateSearch = feedlinkAltSearch.href;
            }

            Object[] feedentries = Array.FindAll(feed.Items, fd => (fd is xsd.feedEntry));
            foreach (Object entryObj in feedentries)
            {
                xsd.feedEntry       entry  = (xsd.feedEntry)entryObj;
                TSearchResult       res    = new TSearchResult();
                xsd.feedEntryAuthor author = (xsd.feedEntryAuthor)Array.Find(entry.Items, en => (en is xsd.feedEntryAuthor));
                if (author != null)
                {
                    res.AuthorName        = author.name;
                    res.AuthorProfileLink = author.uri;
                }

                int index = Array.FindIndex(entry.ItemsElementName, enn => (enn == xsd.ItemsChoiceType.published));
                if (index != -1)
                {
                    res.PublishedDate = (DateTime)entry.Items[index];
                }

                index = Array.FindIndex(entry.ItemsElementName, enn => (enn == xsd.ItemsChoiceType.updated));
                if (index != -1)
                {
                    res.UpdatedDate = (DateTime)entry.Items[index];
                }

                xsd.feedEntryLink tweet = (xsd.feedEntryLink)Array.Find(entry.Items, en => (en is xsd.feedEntryLink && ((xsd.feedEntryLink)en).rel.Equals("alternate", StringComparison.InvariantCultureIgnoreCase)));
                if (tweet != null)
                {
                    res.TweetLink = tweet.href;
                }

                xsd.feedEntryLink image = (xsd.feedEntryLink)Array.Find(entry.Items, en => (en is xsd.feedEntryLink && ((xsd.feedEntryLink)en).rel.Equals("image", StringComparison.InvariantCultureIgnoreCase)));
                if (image != null)
                {
                    res.ProfileImageLink = image.href;
                }

                xsd.feedEntryContent content = (xsd.feedEntryContent)Array.Find(entry.Items, en => (en is xsd.feedEntryContent));
                if (content != null)
                {
                    res.Content = content.Value;
                }

                resultCollection.Items.Add(res);
            }

            return(resultCollection);
        }
Esempio n. 3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="searchResColl"></param>
        public void FormTrend(TSearchResultCollection searchResColl)
        {
            if (searchResColl == null || searchResColl.Items == null || searchResColl.Items.Count == 0)
            {
                return;
            }
            Regex regex = new Regex(@"\W");

            foreach (TSearchResult result in searchResColl.Items)
            {
                String text = result.Content.Replace("<b>", string.Empty).Replace("</b>", string.Empty);
                text = regex.Replace(text, this.SimpleMatchEvaluator);
                text = text.ToLowerInvariant();
                foreach (TwitterDBScore dbScore in this.dbScoreList)
                {
                    if (text.Contains(" " + dbScore.PrimaryWord + " "))
                    {
                        int  startPosition = text.IndexOf(dbScore.PrimaryWord);
                        bool found         = false;
                        int  newseek       = (startPosition - 15) < 0 ? 0 : startPosition - 15;
                        foreach (KeyValuePair <string, int> keyVal in dbScore.StrenghWords)
                        {
                            if (text.Contains(keyVal.Key) && (text.IndexOf(keyVal.Key, newseek) < startPosition && text.IndexOf(keyVal.Key, newseek) != -1))
                            {
                                found = true;
                                if (keyVal.Value > 0)
                                {
                                    this.Positive += keyVal.Value;
                                }
                                if (keyVal.Value < 0)
                                {
                                    this.Negative += keyVal.Value;
                                }
                            }
                        }
                        if (!found)
                        {
                            if (dbScore.PrimaryWordStrength > 0)
                            {
                                this.Positive += dbScore.PrimaryWordStrength;
                            }
                            if (dbScore.PrimaryWordStrength < 0)
                            {
                                this.Negative += dbScore.PrimaryWordStrength;
                            }
                        }
                    }
                }
                //String[] parts = text.Split(' ');
                //foreach (String part in parts)
                //{
                //    String tpart = part.ToLowerInvariant().Trim();
                //    if (this.Trend.ContainsKey(tpart))
                //        this.Trend[tpart] += 1;
                //    else
                //        this.Trend.Add(tpart, 1);
                //}
            }
        }
Esempio n. 4
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="query"></param>
        /// <param name="offset"></param>
        /// <param name="count"></param>
        /// <returns></returns>
        public TSearchResultCollection SearchTwitter(String query, int offset, int limit)
        {
            TSearchResultCollection resultCollection = new TSearchResultCollection();
            resultCollection.Items = new List<TSearchResult>();
            xsd.feed feed = this.ProcessRequest(query, offset, limit);

            xsd.feedLink feedlinkAltSearch = (xsd.feedLink)Array.Find(feed.Items, fd => (fd is xsd.feedLink) && ((xsd.feedLink)fd).rel.Equals("alternate", StringComparison.InvariantCultureIgnoreCase));
            if (feedlinkAltSearch != null)
                resultCollection.AlternateSearch = feedlinkAltSearch.href;

            Object[] feedentries = Array.FindAll(feed.Items, fd => (fd is xsd.feedEntry));
            foreach (Object entryObj in feedentries)
            {
                xsd.feedEntry entry = (xsd.feedEntry)entryObj;
                TSearchResult res = new TSearchResult();
                xsd.feedEntryAuthor author = (xsd.feedEntryAuthor)Array.Find(entry.Items, en => (en is xsd.feedEntryAuthor));
                if (author != null)
                {
                    res.AuthorName = author.name;
                    res.AuthorProfileLink = author.uri;
                }

                int index = Array.FindIndex(entry.ItemsElementName, enn => (enn == xsd.ItemsChoiceType.published));
                if(index != -1)
                    res.PublishedDate = (DateTime)entry.Items[index];

                index = Array.FindIndex(entry.ItemsElementName, enn => (enn == xsd.ItemsChoiceType.updated));
                if (index != -1)
                    res.UpdatedDate = (DateTime)entry.Items[index];

                xsd.feedEntryLink tweet = (xsd.feedEntryLink)Array.Find(entry.Items, en => (en is xsd.feedEntryLink && ((xsd.feedEntryLink)en).rel.Equals("alternate", StringComparison.InvariantCultureIgnoreCase)));
                if (tweet != null)
                    res.TweetLink = tweet.href;

                xsd.feedEntryLink image = (xsd.feedEntryLink)Array.Find(entry.Items, en => (en is xsd.feedEntryLink && ((xsd.feedEntryLink)en).rel.Equals("image", StringComparison.InvariantCultureIgnoreCase)));
                if (image != null)
                    res.ProfileImageLink = image.href;

                xsd.feedEntryContent content = (xsd.feedEntryContent)Array.Find(entry.Items, en => (en is xsd.feedEntryContent));
                if (content != null)
                    res.Content = content.Value;

                resultCollection.Items.Add(res);
            }

            return resultCollection;
        }