Esempio n. 1
0
        public async Task TextMatchAsync(TextMatchBankStatement3Command command, ITextClassifier matcher)
        {
            var unmatched = State.PredictionResults.Where(x => x.PredictedValue == SubCategories.Uncategorised).ToArray();

            Trace.WriteLine($"{Id} unmatched {unmatched.Count()}");

            var matched = new List <KeyValuePair <PredictionResult, TextClassificationResult> >();

            foreach (var item in unmatched)
            {
                item.Method = PredictionMethod.KeywordMatch;
                var result = await matcher.Match(item.Request.Description);

                if (result.Classifier != null && result.Classifier.SubCategory != SubCategories.Uncategorised)
                {
                    matched.Add(new KeyValuePair <PredictionResult, TextClassificationResult>(item, result));
                }
            }

            Trace.WriteLine($"{Id} matched {matched.Count()}");
            var ev = new BankStatementTextMatched3Event
            {
                Unmatched = unmatched,
                Matched   = matched
            };

            Emit(ev);

            await Task.CompletedTask;
        }
Esempio n. 2
0
        private async Task ImportCharges()
        {
            foreach (var item in PocketBookImporter.Import(@"C:/dev/vita/data/pocketbook-export-mckelt-20180422.csv"))
            {
                var found = _chargesRepository.Find(x => x.SearchPhrase == item.Description);
                var xxx   = found.ToList();
                if (xxx.Any())
                {
                    Log.Debug("charge skipped {desc}", item.Description);
                    continue;
                }

                var result = await _textClassifier.Match(item.Description);

                Log.Debug("charge publish {desc}", item.Description);
                var dic = new Dictionary <string, string> {
                    { item.GetType().FullName, JsonConvert.SerializeObject(item) }
                };
                Util.WaitFor(1);
                var charge = new Charge
                {
                    Id                 = Guid.NewGuid(),
                    AccountName        = item.AccountName.ToLowerInvariant(),
                    Category           = result.Classifier.CategoryType,
                    SubCategory        = result.Classifier.SubCategory,
                    SearchPhrase       = result.SearchPhrase,
                    Keywords           = item.Tags,
                    Notes              = item.Notes,
                    CreatedUtc         = DateTime.UtcNow,
                    BankName           = item.Bank,
                    JsonData           = dic,
                    TransactionUtcDate = Convert.ToDateTime(item.Date)
                };

                if (result.Locality != null)
                {
                    charge.LocalityId = result.Locality.Id;
                }
                if (result.Company != null)
                {
                    charge.CompanyId = result.Company.Id;
                }

                await _busControl.Publish(new ChargeSeedRequest
                {
                    Charge = charge
                });

                _chargesRepository.Insert(charge);
            }
        }
Esempio n. 3
0
        public async Task <IActionResult> Warmup()
        {
            Log.Debug("Warmup {time}", DateTime.UtcNow.ToShortTimeString());
            var watch = Stopwatch.StartNew();
            await _predict.PredictAsync(new PredictionRequest());

            _textClassifier.UseCache = true;
            await _textClassifier.Match("coles");

            watch.Stop();

            string msg = ($"warmup took {watch.ElapsedMilliseconds} milliseconds");

            return(Ok(msg));
        }
Esempio n. 4
0
        private async Task <IEnumerable <TextClassificationResult> > GetTextClassifiers()
        {
            var list = new List <TextClassificationResult>();

            foreach (var det in _account.StatementData.Details)
            {
                var match = await _textClassifier.Match(det.Text);

                Console.WriteLine(match.Classifier != null
                    ? $"{det.Text}  {match.Classifier.SubCategory}"
                    : $"{det.Text}  NONE");

                list.Add(match);
            }

            return(list);
        }