示例#1
0
        private void Speak()
        {
            string text = string.Empty;

            Journal.EventsRow er = j.Events.FindByID(selectedEventID);
            if (er == null)
            {
                return;
            }
            if (!er.IsSubjectNull())
            {
                text = er.Subject.ToLower() + " ...";
            }
            if (!er.IsBodyNull())
            {
                text += er.Body.ToLower();
            }
            text = Regex.Replace(text, @"<\s*?lj\s*?user\s*?=\s*?\""?(\w*?)\""?\s*?>", "$1");
            text = Regex.Replace(text, "<.+?>", " ");
            text = text.Replace("\"", "'").Replace("&nbsp;", " ");
            if (!chkShowBalloon.Checked)
            {
                text = string.Format("\\map=\"{0}\"=\"\"\\", text);
            }
            agent.Stop(null);
            request = agent.Speak(text, null);
            if (animations.Count > 0)
            {
                agent.Play((string)animations[(new Random()).Next(animations.Count)]);
            }
        }
示例#2
0
 public void AddEvent(Journal.EventsRow er)
 {
     flm.Reset();
     System.Drawing.Bitmap b  = null;
     Journal.UserPicsRow   ur = null;
     if (!er.IsPictureKeywordNull())
     {
         ur = j.UserPics.FindByPicKeyword(er.PictureKeyword);
     }
     if (ur != null)
     {
         b = new Bitmap(SimpleCache.Cache.GetStream(ur.PicURL));
     }
     else if (!j.Options[0].IsDefaultPicURLNull() && er.Poster == j.Options[0].UserName)
     {
         b = new Bitmap(SimpleCache.Cache.GetStream(j.Options[0].DefaultPicURL));
     }
     if (b != null)
     {
         MemoryStream ms = new MemoryStream();
         b.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
         flm.AddBlock(new RepObj[] { new RepImageMM(ms, Double.NaN, Double.NaN) });
     }
     flm.AddBlock(fp_Header, "Poster: " + er.Poster);
     flm.AddBlock(fp_Header, "Date: " + er.Date.ToString());
     flm.NewLine(fp_Header.rLineFeed);
     foreach (string s in er.Body.Replace("\r", "").Split('\n'))
     {
         flm.AddBlock(Format(s));;
     }
 }
示例#3
0
        static private void BuildHitCount()
        {
            ArrayList     al           = null;
            ArrayList     categoryList = new ArrayList();
            Regex         r            = new Regex("<.+>", RegexOptions.Compiled | RegexOptions.Multiline);
            StringBuilder sb           = new StringBuilder();

            // wordlists
            wordLists = new Hashtable();
            using (StreamReader sr = new StreamReader(
                       Assembly.GetExecutingAssembly().GetManifestResourceStream(_ridWordsResource)))
            {
                while (sr.Peek() > -1)
                {
                    string s = sr.ReadLine();
                    if (s.StartsWith("\t"))
                    {
                        al = new ArrayList();
                        wordLists.Add(s.Substring(1), al);
                        categoryList.Add(s.Substring(1));
                    }
                    else
                    {
                        al.Add(s);
                    }
                }
            }
            categories  = (string[])categoryList.ToArray(typeof(string));
            hitCounts   = new Hashtable();
            frequencies = new Hashtable();
            foreach (string category in categories)
            {
                hitCounts.Add(category, new int[j.Events.Count]);
                frequencies.Add(category, new double[j.Events.Count]);
            }
            wordLengths = new int[j.Events.Count];

            for (int row = 0; row < j.Events.Count; ++row)
            {
                int lastPercentComplete = 0;
                IDictionaryEnumerator ide;
                Journal.EventsRow     er = j.Events[row];
                string[] words;
                sb.Length = 0;
                if (!er.IsSubjectNull())
                {
                    sb.Append(r.Replace(er.Subject, string.Empty).ToLower());
                    sb.Append(' ');
                }
                if (!er.IsBodyNull())
                {
                    sb.Append(r.Replace(er.Body, string.Empty).ToLower());
                }
                words            = sb.ToString().Split(' ', '\n', '\t', '.', ',', '?');
                wordLengths[row] = words.Length;
                ide = wordLists.GetEnumerator();
                while (ide.MoveNext())
                {
                    al = (ArrayList)ide.Value;
                    int[]    hitCount  = (int[])hitCounts[ide.Key];
                    double[] frequency = (double[])frequencies[ide.Key];
                    foreach (string word in words)
                    {
                        foreach (string catWord in al)
                        {
                            int i;
                            if (word == null || word.Length == 0 || catWord[0] > word[0])
                            {
                                break;
                            }
                            if (catWord[0] != word[0])
                            {
                                continue;
                            }
                            i = catWord.Length - 1;
                            // this is poor lemmatization, but an eyeball guesstimate of the dictionary
                            // shows it should work for about 95% of all cases
                            if (catWord[i] == '*')
                            {
                                if (word.Length >= i && word.Length < i + 3 && word.Substring(0, i) ==
                                    catWord.Substring(0, i))
                                {
                                    hitCount[row]++;
                                    break;
                                }
                            }
                            else if (catWord == word)
                            {
                                hitCount[row]++;
                                break;
                            }
                        }
                    }
                    frequency[row] = ((double)hitCount[row]) / ((double)wordLengths[row]);
                }
                if (((95 * row) / j.Events.Count) - lastPercentComplete >= 5)
                {
                    lastPercentComplete = (95 * row) / j.Events.Count;
                    ascb(new AnalysisStatusEventArgs(AnalysisStatus.Analyzing, lastPercentComplete));
                }
            }
        }
示例#4
0
        /// <summary>
        /// Returns a graph that provides an over-time RID Analysis.
        /// </summary>
        /// <param name="categories">The categories to report.</param>
        /// <param name="title">The title of the graph.</param>
        /// <param name="width">The width of the graph to return.</param>
        /// <param name="height">The height of the graph to return.</param>
        /// <param name="baseline">The baseline to use.</param>
        /// <returns>a graph that provides an over-time RID Analysis.</returns>
        static public GraphPane GetOverTimeGraph(string[] categories, string title, int width, int height,
                                                 RIDBaselines baseline)
        {
            GraphPane pane;
            CurveItem curve;
            Random    r = new Random();

            pane = new GraphPane(new Rectangle(0, 0, width, height),
                                 title + " Over Time (%)", string.Empty, string.Empty);

            foreach (string category in categories)
            {
                NormalDist nd;
                SortedList sl = new SortedList();
                Hashtable  counts = new Hashtable();
                double     mean = 0, variance = 0;
                double[]   x, y;

                foreach (string findCategory in RIDAnalysis.categories)
                {
                    if (findCategory.StartsWith(category))
                    {
                        mean     += (double)averages[(int)baseline][findCategory];
                        variance += Math.Pow((double)stdDev[(int)baseline][findCategory], 2);
                    }
                }
                for (int i = 0; i < j.Events.Count; ++i)
                {
                    Journal.EventsRow er = j.Events[i];
                    double            d  = 0F;
                    DateTime          dt;
                    if (er.IsDateNull())
                    {
                        continue;
                    }
                    dt = new DateTime(er.Date.Year, er.Date.Month, 1);

                    foreach (string findCategory in RIDAnalysis.categories)
                    {
                        if (findCategory.StartsWith(category))
                        {
                            d += ((double[])frequencies[findCategory])[i];
                        }
                    }

                    if (sl.ContainsKey(dt))
                    {
                        sl[dt]     = (double)sl[dt] + d;
                        counts[dt] = (int)counts[dt] + 1;
                    }
                    else
                    {
                        sl.Add(dt, d);
                        counts.Add(dt, 1);
                    }
                }
                if (variance > 0F)
                {
                    nd = new NormalDist(mean, variance);
                    foreach (object key in counts.Keys)
                    {
                        sl[key] = nd.CDF(((double)sl[key]) / ((double)(int)counts[key])) * 100F;
                    }
                }
                else
                {
                    foreach (object key in counts.Keys)
                    {
                        sl[key] = (double)50F;
                    }
                }

                x = new double[sl.Count];
                y = new double[sl.Count];
                for (int i = 0; i < sl.Count; ++i)
                {
                    DateTime dt = (DateTime)sl.GetKey(i);
                    double   d  = (double)sl.GetByIndex(i);
                    x[i] = (double)new XDate(dt.Year, dt.Month, dt.Day);
                    y[i] = double.IsNaN(d) ? 0F : d;
                }
                curve = pane.AddCurve(category.Substring(category.LastIndexOf(':') + 1), x, y,
                                      Color.FromArgb(r.Next(200), r.Next(200), r.Next(200)),
                                      SymbolType.Diamond);
            }
            pane.XAxis.Type        = AxisType.Date;
            pane.XAxis.ScaleFormat = "&yyyy";
            pane.XAxis.IsShowGrid  = true;
            pane.YAxis.IsShowGrid  = true;
            pane.YAxis.Min         = 0;
            pane.YAxis.Max         = 100;
            pane.XAxis.GridColor   = Color.LightGray;
            pane.YAxis.GridColor   = Color.LightGray;
            pane.AxisBackColor     = Color.LightCyan;
            pane.Legend.IsVisible  = true;
            pane.AxisChange();
            return(pane);
        }
示例#5
0
        /// <summary>
        /// Output a transformed entry to the HTML stream.
        /// </summary>
        private void WriteEvent(TextWriter tw, Journal.EventsRow er, Journal.UserPicsDataTable updt,
                                Journal.MoodsDataTable mdt)
        {
            ArrayList idstack = new ArrayList();

            foreach (string block in _rblock.Split(entry))
            {
                if (block.StartsWith("<%"))
                {
                    string id = block.Substring(2, block.Length - 4).Trim().ToLower();
                    // check the id stack for additions
                    if (id.StartsWith("!"))
                    {
                        string idToBlock = id.Substring(1);
                        switch (idToBlock)
                        {
                        case "userpicurl":
                            if ((!er.IsPosterNull() && er.Poster != options.UserName) ||
                                ((er.IsPictureKeywordNull() || updt.FindByPicKeyword(er.PictureKeyword) == null) &&
                                 (options.IsDefaultPicURLNull())))
                            {
                                idstack.Add(idToBlock);
                            }
                            break;

                        case "currentmood":
                            if (er.IsCurrentMoodNull() && (er.IsCurrentMoodIDNull() ||
                                                           mdt.FindByID(er.CurrentMoodID) == null))
                            {
                                idstack.Add(idToBlock);
                            }
                            break;

                        case "securityiconpath":
                            if (er.IsSecurityNull() || (er.Security != "usemask" && er.Security != "private"))
                            {
                                idstack.Add(idToBlock);
                            }
                            break;

                        default:
                            if (!er.Table.Columns.Contains(idToBlock) || er.IsNull(idToBlock))
                            {
                                idstack.Add(idToBlock);
                            }
                            break;
                        }
                        continue;
                    }
                    // check the id stack for removals
                    else if (id.StartsWith("/!"))
                    {
                        idstack.Remove(id.Substring(2));
                        continue;
                    }
                    else
                    {
                        // we don't output anything until the stack is empty
                        if (idstack.Count > 0)
                        {
                            continue;
                        }
                        switch (id)
                        {
                        case "userpicurl":
                            if (er.IsPosterNull() || er.Poster == options.UserName)
                            {
                                Journal.UserPicsRow ur = null;
                                if (!er.IsPictureKeywordNull())
                                {
                                    ur = updt.FindByPicKeyword(er.PictureKeyword);
                                }
                                if (ur != null)
                                {
                                    tw.Write(ur.PicURL);
                                }
                                else if (!options.IsDefaultPicURLNull())
                                {
                                    tw.Write(options.DefaultPicURL);
                                }
                            }
                            break;

                        case "currentmood":
                            if (!er.IsCurrentMoodNull())
                            {
                                WritePreparedText(tw, er.CurrentMood, entrySearchString);
                            }
                            else if (!er.IsCurrentMoodIDNull() && mdt.FindByID(er.CurrentMoodID) != null)
                            {
                                WritePreparedText(tw, mdt.FindByID(er.CurrentMoodID).Name, entrySearchString);
                            }
                            break;

                        case "securityiconpath":
                            if (!er.IsSecurityNull() && er.Security == "usemask")
                            {
                                tw.Write(hjws.ProtectedIconPath);
                            }
                            else if (!er.IsSecurityNull() && er.Security == "private")
                            {
                                tw.Write(hjws.PrivateIconPath);
                            }
                            break;

                        case "posterusername":
                            if (!options.IsUseJournalNull() && !er.IsPosterNull())
                            {
                                tw.Write(er.Poster);
                            }
                            else
                            {
                                tw.Write(options.UserName);
                            }
                            break;

                        default:
                            if (id == "subject" || id == "currentmusic" || id == "body")
                            {
                                WritePreparedText(tw, er[id].ToString(), entrySearchString);
                            }
                            else if (er.Table.Columns.Contains(id))
                            {
                                tw.Write(er[id]);
                            }
                            break;
                        }
                    }
                }
                else
                {
                    if (idstack.Count == 0)
                    {
                        tw.Write(block);
                    }
                }
            }
        }