コード例 #1
0
ファイル: MainWindow.xaml.cs プロジェクト: EricDahlvang/lucy
        private void ShowResults()
        {
            try
            {
                if (lucyModel != this.editor.Document.Text)
                {
                    LoadModel();
                }

                var text = this.query?.Text?.Trim() ?? string.Empty;
                if (text.Length > 0)
                {
                    var sw = new System.Diagnostics.Stopwatch();
                    sw.Start();
                    var results = engine.MatchEntities(text, includeInternal: this.showInternal.IsChecked.Value);
                    sw.Stop();

                    this.tabs.SelectedIndex = 2;
                    this.labelBox.Text      = $"{sw.ElapsedMilliseconds} ms\n" + String.Join("\n", results.Select(s => LucyEngine.VisualizeEntity(text, s, showSpans: true, showHierarchy: false)));
                    this.entitiesBox.Text   = String.Join("\n", results.Select(s => LucyEngine.VisualizeEntity(text, s, showSpans: false, showHierarchy: true)));

                    //var activity = new Activity(ActivityTypes.Message) { Text = text };
                    //var tc = new TurnContext(new TestAdapter(), activity);
                    //var dc = new DialogContext(new DialogSet(), tc, new DialogState());
                    //var recognizerResult = recognizer.RecognizeAsync(dc, activity).Result;
                    //// this.recognizerBox.Text = JsonConvert.SerializeObject(recognizerResult, new JsonSerializerSettings() { Formatting = Formatting.Indented, NullValueHandling = NullValueHandling.Ignore });
                    //this.recognizerBox.Text = new Serializer().Serialize(JObject.FromObject(recognizerResult).ToObject<ExpandoObject>());
                }
            }
            catch (SemanticErrorException err)
            {
                this.error.Content    = err.Message;
                this.error.Visibility = Visibility.Visible;
                this.editor.ScrollToLine(err.Start.Line);
                var line = this.editor.Document.GetLineByNumber(err.Start.Line - 1);
                this.editor.Select(line.Offset, line.Length);
            }
            catch (SyntaxErrorException err)
            {
                this.error.Content    = err.Message;
                this.error.Visibility = Visibility.Visible;
                this.editor.ScrollToLine(err.Start.Line);
                var line = this.editor.Document.GetLineByNumber(err.Start.Line - 1);
                this.editor.Select(line.Offset, line.Length);
            }
            catch (Exception err)
            {
                this.error.Content    = err.Message;
                this.error.Visibility = Visibility.Visible;
            }
        }
コード例 #2
0
        async Task OnTextChanged(string value)
        {
            try
            {
                var yaml = await yamlEditor.GetValue();

                var text = value.Trim() ?? string.Empty;
                IEnumerable <LucyEntity> results = null;
                if (text.Length == 0)
                {
                    return;
                }
#if embedded
                if (lucyModel != yaml)
                {
                    LoadModel(yaml);
                }

                var sw = new System.Diagnostics.Stopwatch();
                sw.Start();
                results = engine.MatchEntities(text);
                sw.Stop();
                this.Elapsed = $"{sw.Elapsed.TotalMilliseconds} ms";
#else
                var sw = new System.Diagnostics.Stopwatch();
                sw.Start();
                var result = await Http.PostAsJsonAsync("entities", new EntitiesRequest
                {
                    yaml = yaml,
                    text = text
                });

                sw.Stop();
                // this.Elapsed = $"Network: {sw.Elapsed.TotalMilliseconds} ms";
                var entityResponse = JsonConvert.DeserializeObject <EntitiesResponse>(await result.Content.ReadAsStringAsync());

                this.Elapsed = $"{entityResponse.elapsed} ms";

                if (!String.IsNullOrEmpty(entityResponse.message))
                {
                    this.Error = entityResponse.message;
                    this.alertBox.Show();
                }
                else
                {
                    this.alertBox.Hide();
                }
                results = entityResponse.entities;
#endif

                this.TopResultVisible  = true;
                this.AllResultsVisible = false;
                this.TopResult         = LucyEngine.VisualEntities(text, results);
                this.EntityResults     = String.Join("\n\n", results.Select(entity => LucyEngine.VisualizeEntity(text, entity)));
            }
            catch (SemanticErrorException err)
            {
                this.Error = err.Message;
                this.alertBox.Show();
                //this.editor.ScrollToLine(err.Start.Line);
                //var line = this.editor.Document.GetLineByNumber(err.Start.Line - 1);
                //this.editor.Select(line.Offset, line.Length);
            }
            catch (SyntaxErrorException err)
            {
                this.Error = err.Message;
                this.alertBox.Show();
                //this.error.Visibility = Visibility.Visible;
                //this.editor.ScrollToLine(err.Start.Line);
                //var line = this.editor.Document.GetLineByNumber(err.Start.Line - 1);
                //this.editor.Select(line.Offset, line.Length);
            }
            catch (Exception err)
            {
                this.Error = err.Message;
                this.alertBox.Show();
                //this.error.Content = err.Message;
                //this.error.Visibility = Visibility.Visible;
            }
        }