コード例 #1
0
        public override async Task <Message> HandleMessage(Message msg)
        {
            var tmsg = msg as ITokenisable;

            if (tmsg == null)
            {
                return(msg);
            }

            MessageContext context = new MessageContext(msg, this);

            string dfClass = await Class.SelectStringAsync(context);

            ClassIndex cindex = Bayes.GetClass(dfClass);

            if (cindex == null)
            {
                cindex = new ClassIndex {
                    Name = dfClass
                };
                Bayes.AddClass(cindex);
            }

            cindex.IncDocumentCount();

            foreach (string token in tmsg.Tokens)
            {
                cindex.IncTokenCount(token);
            }

            return(msg);
        }
コード例 #2
0
ファイル: BayesClass.cs プロジェクト: cwenham/Meep
        public Message Import(Message msg)
        {
            // Elimination of invalid messages
            var record = msg as RecordMessage;

            if (record is null)
            {
                return(null);
            }

            if (!record.Record.ContainsKey("Name"))
            {
                return(null);
            }

            if (!record.Record.ContainsKey("DocumentCount"))
            {
                return(null);
            }

            if (!record.Record.ContainsKey("TokensString"))
            {
                return(null);
            }

            //Okay, import it
            try
            {
                ClassIndex newClass = new ClassIndex
                {
                    Name          = record.Record["Name"] as string,
                    DocumentCount = (int)record.Record["DocumentCount"],
                    TokensString  = record.Record["TokensString"] as string
                };

                Bayes.AddClass(newClass);

                return(newClass);
            }
            catch (Exception ex)
            {
                logger.Error(ex, $"{ex.GetType().Name} thrown when importing ClassIndex: {ex.Message}");
            }

            return(null);
        }
コード例 #3
0
ファイル: BayesClass.cs プロジェクト: cwenham/Meep
        public Message Export(Message msg)
        {
            MessageContext context = new MessageContext(msg, this);
            string         sfFrom  = Smart.Format(From, context);

            if (!String.IsNullOrWhiteSpace(sfFrom))
            {
                return(Bayes.GetClass(sfFrom));
            }

            var allClasses = from k in Bayes.ClassNames
                             where !String.IsNullOrWhiteSpace(k)
                             select Bayes.GetClass(k);

            return(new Batch
            {
                DerivedFrom = msg,
                Name = this.Name,
                Messages = allClasses.ToList()
            });
        }