Exemplo n.º 1
0
        private void _tagger_AddTag(object sender, TaggerEventArgs e)
        {
            //Stopwatch.StartNew();
            if (SituationIndex.TagsetCounter.Count != 0)
            {
                SituationIndex.AddSituationToIndex(e.messages, e.Id, e.Tag);

                foreach (var id in e.messages)
                {
                    if (!MessageContainer.Messages[id].Situations.ContainsKey(e.Tag))
                    {
                        MessageContainer.Messages[id].Situations.Add(e.Tag, SituationIndex.TagsetCounter[e.Tag]);
                    }
                    else
                    {
                        //MessageContainer.Messages[id].Situations[e.Tag]
                        _tagger.DisplayTagErrorMessage();
                    }
                }
                _tagger.AddSituationIndexItem(e.Tag + " " + SituationIndex.TagsetCounter[e.Tag].ToString());
                var count = SituationIndex.Index[e.Tag].Count;
                SituationIndex.TagsetCounter[e.Tag]++;
            }
            else
            {
                foreach (var str in TagsetIndex.Index[_service.ProjectTagset])
                {
                    SituationIndex.TagsetCounter.Add(str, 0);
                    _tagger.AddSituationIndexItem(e.Tag + " " + SituationIndex.TagsetCounter[e.Tag].ToString());
                }
            }
            _tagger.UpdateSituationCount(SituationIndex.SituationCount());
        }
        private void SetSimpleCounts()
        {
            int        prev     = 0;                                                                //prev id
            List <int> windows  = new List <int>();                                                 // all windows lengths;
            int        count    = 0;                                                                //all messages in all situations
            int        symcount = 0;                                                                //all symbols in all situations
            int        sitcount = SituationIndex.SituationCount();                                  //the number of all situations

            HashSet <string>         usersInSituation             = new HashSet <string>();         //counts all unique users in a situation
            Dictionary <string, int> userPerSituationPerTagCounts = new Dictionary <string, int>(); //the sum of unique users in each tag

            foreach (var kvp in SituationIndex.TagsetCounter)
            {
                userPerSituationPerTagCounts.Add(kvp.Key, 0);
                this.AverageUsersInSituationPerTag.Add(kvp.Key, 0);
            }

            foreach (var kvp in SituationIndex.Index)
            {
                count += kvp.Value.Values.Count;
                foreach (var dict in kvp.Value)
                {
                    prev = dict.Value[0];
                    foreach (var index in dict.Value)
                    {
                        if (index - prev > 1)
                        {
                            count++;
                            windows.Add(index - prev);
                        }
                        prev      = index;
                        symcount += LuceneService.DirReader.Document(index).GetField(ProjectInfo.TextFieldKey).GetStringValue().Length;
                        usersInSituation.Add(LuceneService.DirReader.Document(index).GetField(ProjectInfo.SenderFieldKey).GetStringValue());
                    }

                    userPerSituationPerTagCounts[kvp.Key] += usersInSituation.Count;
                    usersInSituation.Clear();
                }
            }
            this.NumberOfDocs             = count;
            this.AverageMessagesPerUnit   = count / sitcount;
            this.NumberOfSymbols          = symcount;
            this.AverageLength            = symcount / count;
            this.AverageWindowLength      = windows.Sum() / windows.Count;
            this.AverageUsersPerSituation = userPerSituationPerTagCounts.Values.Sum() / sitcount;
            foreach (var kvp in userPerSituationPerTagCounts)
            {
                this.AverageUsersInSituationPerTag[kvp.Key] = kvp.Value / SituationIndex.Index[kvp.Key].Count;
                this.SituationsPerTag.Add(kvp.Key, SituationIndex.Index[kvp.Key].Count);
                this.AllFields.Add("Average number of users in " + kvp.Key, AverageUsersInSituationPerTag[kvp.Key]);
                this.AllFields.Add(kvp.Key, SituationIndex.Index[kvp.Key].Count);
            }

            this.AllFields.Add("Number of tagged messages", this.NumberOfDocs);
            this.AllFields.Add("Number of symbols", this.NumberOfSymbols);
            this.AllFields.Add("Average number of messages per situation", this.AverageUsersPerSituation);
            this.AllFields.Add("Average length of a tagged message", AverageLength);
            this.AllFields.Add("Average window length", AverageWindowLength);
            this.AllFields.Add("Number of windows", windows.Count);
        }
Exemplo n.º 3
0
        private void _tagger_RemoveTag(object sender, TaggerEventArgs args)
        {
            SituationIndex.RemoveMessageFromSituation(args.Tag, args.Id, args.messages[0]);
            MessageContainer.Messages[args.messages[0]].Situations.Remove(args.Tag);


            if (SituationIndex.Index[args.Tag][args.Id].Count == 0)
            {
                DeleteOrEditTag(args, true);
            }
        }
Exemplo n.º 4
0
        private void DeleteOrEditTag(TaggerEventArgs args, bool type)
        {
            foreach (var id in SituationIndex.Index[args.Tag][args.Id])
            {
                MessageContainer.Messages[id].Situations.Remove(args.Tag);
            }

            if (type)
            {
                _tagger.UpdateSituationCount(SituationIndex.SituationCount());
            }
            else
            {
                var tag = args.AdditionalInfo["Change"].ToString();

                var count  = SituationIndex.TagsetCounter[tag];
                var count2 = SituationIndex.Index[tag].Count;
                var list   = SituationIndex.Index[args.Tag][args.Id];

                SituationIndex.TagsetCounter[tag]++;
                SituationIndex.AddSituationToIndex(list, count, tag);
                foreach (var id in list)
                {
                    MessageContainer.Messages[id].Situations.Add(tag, count);
                }
                _tagger.AddSituationIndexItem(tag + " " + count);
            }

            SituationIndex.RemoveSituationFromIndex(args.Id, args.Tag);
            SituationIndex.TagsetCounter[args.Tag]--;

            _tagger.DeleteSituationIndexItem(args.Tag + " " + args.Id.ToString());



            if (args.Id < SituationIndex.Index[args.Tag].Count + 1)
            {
                for (int i = args.Id + 1; i <= SituationIndex.Index[args.Tag].Count; i++)
                {
                    var list = SituationIndex.Index[args.Tag][i];
                    foreach (var id in list)
                    {
                        MessageContainer.Messages[id].Situations[args.Tag]--;
                    }

                    SituationIndex.RemoveSituationFromIndex(i, args.Tag);
                    SituationIndex.AddSituationToIndex(list, i - 1, args.Tag);

                    _tagger.DeleteSituationIndexItem(args.Tag + " " + i.ToString());
                    _tagger.AddSituationIndexItem(args.Tag + " " + (i - 1).ToString());
                }
            }
        }
Exemplo n.º 5
0
        private void LoadTagged(object sender, EventArgs e)
        {
            if (_service.SituationContainer.Count == 0)
            {
                if (File.Exists(ProjectInfo.SavedTagsPath))
                {
                    using (StreamReader reader = new StreamReader(ProjectInfo.SavedTagsPath))
                    {
                        string line;
                        while ((line = reader.ReadLine()) != null)
                        {
                            var MessageIdAndSituations = line.Split(' ');
                            _service.SituationContainer.Add(Int32.Parse(MessageIdAndSituations[0]), MessageIdAndSituations[1]);

                            var situationsSet = MessageIdAndSituations[1].Split(new char[] { '+' }, StringSplitOptions.RemoveEmptyEntries);

                            foreach (var situation in situationsSet)
                            {
                                var splitSituation = situation.Split('-');
                                int sitId          = int.Parse(splitSituation[1]);
                                if (SituationIndex.Index.ContainsKey(splitSituation[0]))
                                {
                                    if (!SituationIndex.Index[splitSituation[0]].ContainsKey(sitId))
                                    {
                                        SituationIndex.Index[splitSituation[0]].Add(sitId, new List <int>());
                                        SituationIndex.Index[splitSituation[0]][sitId].Add(int.Parse(MessageIdAndSituations[0]));
                                    }
                                    else
                                    {
                                        SituationIndex.Index[splitSituation[0]][sitId].Add(int.Parse(MessageIdAndSituations[0]));
                                    }
                                }
                                else
                                {
                                    SituationIndex.Index.Add(splitSituation[0], new Dictionary <int, List <int> >());
                                    SituationIndex.Index[splitSituation[0]].Add(sitId, new List <int>());
                                    SituationIndex.Index[splitSituation[0]][sitId].Add(int.Parse(MessageIdAndSituations[0]));
                                }

                                //TODO: Revise and add a wrapper ASAP
                                _tagger.AddSituationIndexItem(splitSituation[0] + " " + splitSituation[1]);
                            }
                        }
                    }
                    _service.TaggedIds = _service.SituationContainer.Keys.ToList();
                    _service.TaggedIds.Sort();
                    _tagger.UpdateSituationCount(SituationIndex.SituationCount());
                }
            }
        }
        private void InsertTagsInDynamicMessage(int id, int offset)
        {
            var arr = _service.SituationContainer[id].Split(new char[] { '+' }, StringSplitOptions.RemoveEmptyEntries);

            foreach (var item in arr)
            {
                var s = item.Split('-');
                if (id <= MessageContainer.Messages.Count + offset)
                {
                    if (!MessageContainer.Messages[id].Situations.ContainsKey(s[0]))
                    {
                        MessageContainer.Messages[id].Situations.Add(s[0], Int32.Parse(s[1]));
                        SituationIndex.RetrieveDictFromMessageContainer(MessageContainer.Messages[id]);
                    }
                }
            }
        }
        private void _view_OpenIndexedCorpus(object sender, OpenEventArgs e)
        {
            //ProjectInfo.CurrentIndexPath = _main.CurrentIndexPath;
            ProjectInfo.UnloadData();

            _service.UnloadData();
            SituationIndex.UnloadData();
            ProjectInfo.LoadProject(e.Path);
            if (LuceneService.OpenIndex())
            {
                MessageContainer.Messages = new List <DynamicMessage>();
                _main.SetLineCount(ProjectInfo.Data.LineCount);
                _main.FileLoadState = true;


                AddDocumentsToDisplay(2000);
                _main.ShowDates(ProjectInfo.Data.MessagesPerDay.Keys.ToList());
                //_main.UpdateNgramState(_ngrammer.IndexExists);
            }
            else
            {
                MessageBox.Show("No index");
            }
        }
Exemplo n.º 8
0
 public void AddSituation(List <int> messages, int id, string situation)
 {
     SituationIndex.AddSituationToIndex(messages, id, situation);
 }