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); }
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); }