示例#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
        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()
            });
        }