Exemplo n.º 1
0
        private async void FreeWriter_KeyDown(object sender, KeyEventArgs e)
        {
            var textBlock = sender as TextBlock;

            if (e.Key == Key.Enter && !textBlock.Text.IsNullOrWhiteSpace())
            {
                var chunks       = textBlock.Text.SplitRemoveEmpty('.', '!', '?').ToList();
                var orchestrator = new AnalysisOrchestrator(new RawTextFragment(chunks.Take(chunks.Count - 1), "free snippet"));
                await orchestrator.ProcessAsync();
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Asynchronously processes all documents in the project in a comprehensive manner.
        /// </summary>
        /// <returns>A System.Threading.Tasks.Task representing the asynchronous processing operation.</returns>
        public async Task ParseDocuments()
        {
            var resourceLoadingNotifier = new ResourceNotifier();
            var analysisOrchestrator    = new AnalysisOrchestrator(FileManager.TxtFiles);

            var loadingEvents        = ConfigureLoadingEvents(resourceLoadingNotifier);
            var loadedEvents         = ConfigureLoadedEventStream(resourceLoadingNotifier);
            var analysisUpdateEvents = ConfigureAnalysisUpdateEvents(analysisOrchestrator);

            Observable.Merge(
                loadingEvents.Select(pattern => pattern.EventArgs),
                loadedEvents.Select(pattern => pattern.EventArgs),
                analysisUpdateEvents.Select(pattern => pattern.EventArgs)
                )
            .Select(pattern => new
            {
                pattern.Message,
                Progress = pattern.PercentWorkRepresented
            })
            .SubscribeOn(System.Threading.SynchronizationContext.Current)
            .Subscribe(onNext: async e =>
            {
                progressLabel.Content = e.Message;
                progressBar.ToolTip   = e.Message;
                var animateStep       = 0.028 * e.Progress;
                for (var i = 0; i < 33; ++i)
                {
                    progressBar.Value += animateStep;
                    await Task.Yield();
                }
            });
            var timer = System.Diagnostics.Stopwatch.StartNew();

            ResultsScreen.Documents = await analysisOrchestrator.ProcessAsync();

            progressBar.Value = 100;
            var completetionMessage = $"Processing Complete. Time: {timer.ElapsedMilliseconds / 1000f} seconds";

            progressLabel.Content             = completetionMessage;
            progressBar.ToolTip               = completetionMessage;
            proceedtoResultsButton.Visibility = Visibility.Visible;
            NativeMethods.StartFlashing(this);
            await Task.WhenAll(ResultsScreen.CreateWeightViewsForAllDocumentsAsync(), ResultsScreen.BuildTextViewsForAllDocumentsAsync());

            ProcessingCompleted(this, new EventArgs());
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            var fragment      = new RawTextFragment(rawText, "Test");
            var percent       = 0d;
            var notfier       = new ResourceNotifier();
            var setsProcessed = 0;

            notfier.ResourceLoading += (s, e) =>
            {
                Logger.Log($"Sets Processed {++setsProcessed}");
            };
            notfier.ResourceLoaded += (s, e) =>
            {
                percent = Math.Min(100, percent + e.PercentWorkRepresented);
                Logger.Log($"Update : {e.Message} Percent : {percent += e.PercentWorkRepresented} MS : {e.ElapsedMiliseconds}");
            };
            var orchestrator =
                new AnalysisOrchestrator(new RawTextFragment(
                                             File.ReadAllLines(@".\..\..\testDocs\testDoc1.txt"), "testDoc1")
                                         );

            orchestrator.ProgressChanged += (s, e) =>
            {
                percent = Math.Min(100, percent + e.PercentWorkRepresented);
                Logger.Log($"Update : {e.Message} Percent : {percent}");
            };

            var document = orchestrator.ProcessAsync().Result.First();

            var x = document.Entities.FirstOrDefault();

            x.Match()
            .Case((IReferencer r) => r.Referencers != null ? r.RefersTo.Text : r.Text)
            .Result(x.Text);
            Logger.Log(document);
            foreach (var phrase in document.Phrases)
            {
                Logger.Log(phrase);
            }
            Input.WaitForKey(ConsoleKey.Escape);
        }
Exemplo n.º 4
0
        private async Task <Document> ProcessUserDocument(UserDocument source, WorkItem workItem)
        {
            var analyzer = new AnalysisOrchestrator(source);

            analyzer.ProgressChanged += (s, e) =>
            {
                workItem.PercentComplete = Math.Round(
                    value: Math.Min(workItem.PercentComplete + e.PercentWorkRepresented, 100),
                    digits: 0,
                    mode: MidpointRounding.AwayFromZero
                    );
                workItem.StatusMessage = e.Message;
                workItem.State         = TaskState.Ongoing;
            };
            var processedDocument = await analyzer.ProcessAsync();

            workItem.PercentComplete = 100;
            workItem.StatusMessage   = "Analysis Complete.";
            workItem.State           = TaskState.Complete;
            return(processedDocument.First());
        }