Ejemplo n.º 1
0
        public PostInteraction ReadInteraction(XmlNode nodeRepresentation)
        {
            PostInteraction interaction = new PostInteraction();

            interaction.Post       = new Post();
            interaction.Post.Title = "";
            foreach (XmlNode child in nodeRepresentation.ChildNodes)
            {
                if (child.Name == this.PostUrl_Tag)
                {
                    interaction.Post.Source = this.ReadText(child);
                    continue;
                }
                if (child.Name == this.PostVisited_Tag)
                {
                    interaction.Visited = this.ReadBool(child);
                    continue;
                }
                if (child.Name == this.PostStarred_Tag)
                {
                    interaction.Starred = this.ReadBool(child);
                    continue;
                }
                if (child.Name == this.PostTitle_Tag)
                {
                    interaction.Post.Title = this.ReadText(child);
                    continue;
                }
            }
            return(interaction);
        }
Ejemplo n.º 2
0
        private AnalyzedPost analyzePost(Post post)
        {
            string title = post.Title;
            double score = this.scoreTitle(title);

            List <AnalyzedString> titleComponents = new List <AnalyzedString>();
            List <String>         words           = new List <String>(title.Split(new char[] { ' ' }));

            for (int i = 0; i < words.Count; i++)
            {
                List <String> hypotheticalWords = new List <String>(words);
                hypotheticalWords.RemoveAt(i);
                double hypotheticalScore = this.scoreTitle(string.Join(" ", hypotheticalWords));
                double difference        = score.CompareTo(hypotheticalScore);
                titleComponents.Add(new AnalyzedString(words[i], difference));
            }
            for (int i = titleComponents.Count - 1; i >= 1; i--)
            {
                if (titleComponents[i].Score == titleComponents[i - 1].Score)
                {
                    titleComponents[i - 1] = new AnalyzedString(titleComponents[i - 1].Text + " " + titleComponents[i].Text, titleComponents[i].Score);
                    titleComponents.RemoveAt(i);
                }
            }


            PostInteraction interaction = this.postDatabase.Get(post);

            if (interaction.Visited)
            {
                score -= 1;
            }

            return(new AnalyzedPost(interaction, score, titleComponents));
        }
Ejemplo n.º 3
0
        public string ConvertToString(PostInteraction post)
        {
            Dictionary <string, string> properties = new Dictionary <string, string>();

            properties[this.PostUrl_Tag]   = this.XmlEscape(post.Post.Source);
            properties[this.PostTitle_Tag] = this.XmlEscape(post.Post.Title);
            if (post.Visited)
            {
                properties[this.PostVisited_Tag] = this.ConvertToStringBody(true);
            }
            if (post.Starred)
            {
                properties[this.PostStarred_Tag] = this.ConvertToStringBody(true);
            }
            return(this.ConvertToString(properties, PostTag));
        }
        public PostInteraction Get(Post post)
        {
            string key = post.Source;

            if (this.keyedInteractions.ContainsKey(key))
            {
                PostInteraction interaction = this.keyedInteractions[key];
                interaction.Post = post;
                return(interaction);
            }
            else
            {
                PostInteraction interaction = new PostInteraction();
                interaction.Post = post;
                this.Add(interaction);
                return(interaction);
            }
        }
        public void ShrinkToSize(int size)
        {
            if (this.orderedInteractions.Count <= size)
            {
                return;
            }

            int numToRemove = this.orderedInteractions.Count - size;
            List <PostInteraction> newOrderedInteractions             = new List <PostInteraction>();
            Dictionary <string, PostInteraction> newKeyedInteractions = new Dictionary <string, PostInteraction>();
            int numSkipped = 0;

            for (int i = 0; i < this.orderedInteractions.Count; i++)
            {
                bool include = false;
                if (numSkipped >= numToRemove)
                {
                    include = true;
                }
                else
                {
                    if (this.orderedInteractions[i].Starred)
                    {
                        include = true;
                    }
                }
                if (include)
                {
                    PostInteraction interaction = this.orderedInteractions[i];
                    newOrderedInteractions.Add(interaction);
                    newKeyedInteractions.Add(interaction.Post.Source, interaction);
                }
                else
                {
                    numSkipped++;
                }
            }
            this.orderedInteractions = newOrderedInteractions;
            this.keyedInteractions   = newKeyedInteractions;
        }
 public void Add(PostInteraction interaction)
 {
     this.orderedInteractions.Add(interaction);
     this.keyedInteractions[interaction.Post.Source] = interaction;
 }
Ejemplo n.º 7
0
 public AnalyzedPost(PostInteraction Interaction, double Score, List <AnalyzedString> analyzedTitle)
 {
     this.Interaction     = Interaction;
     this.Score           = Score;
     this.TitleComponents = analyzedTitle;
 }
Ejemplo n.º 8
0
 private void PostView_PostClicked(PostInteraction interaction)
 {
     this.savePostDatabase();
     Device.OpenUri(new Uri(interaction.Post.Source));
 }
Ejemplo n.º 9
0
 private void PostView_PostStarred(PostInteraction post)
 {
     this.savePostDatabase();
 }