示例#1
0
 async void APIOnSearchResultHandler(TextSearcher sender, PageResults pageResults)
 {
     // Dispatch on the Controller thread, otherwise updating the `SearchResults` list will throw an exception.
     await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => {
         foreach (var result in pageResults.Results)
         {
             SearchResults.Add(new SearchResultFormatter(result));
         }
     });
 }
示例#2
0
        private IOcrPage DoublePass(RasterImage image)
        {
            //first pass with default settings
            IOcrPage page = _ocrEngine.CreatePage(image.Clone(), OcrImageSharingMode.AutoDispose);

            page.Recognize(null);

            //second pass with mobile image processing set to true
            _ocrEngine.SettingManager.SetBooleanValue("Recognition.Preprocess.MobileImagePreprocess", true);
            IOcrPage mobilePage = _ocrEngine.CreatePage(image.Clone(), OcrImageSharingMode.AutoDispose);

            mobilePage.Recognize(null);

            //get the confidence of both pages
            PageResults firstPassResults  = GetPageConfidence(page);
            PageResults secondPassResults = GetPageConfidence(mobilePage);

            double confidenceDif = firstPassResults.Confidence - secondPassResults.Confidence;

            IOcrPage    highestConfidence;
            PageResults pageResultsHighest;

            if (confidenceDif > 2)
            {
                highestConfidence  = page;
                pageResultsHighest = firstPassResults;
            }
            else
            {
                highestConfidence  = mobilePage;
                pageResultsHighest = secondPassResults;
            }

            if (pageResultsHighest.TotalWords < 20)
            {
                IOcrPage thirdPass = highestConfidence.Copy();
                thirdPass.Unrecognize();
                OcrZone singleZone = new OcrZone()
                {
                    Bounds = new LeadRect(0, 0, image.Width, image.Height)
                };
                thirdPass.Zones.Add(singleZone);
                thirdPass.Recognize(null);
                PageResults thirdResults        = GetPageConfidence(thirdPass);
                double      confidencetDifThird = thirdResults.Confidence - pageResultsHighest.Confidence;
                if (confidenceDif > 5)
                {
                    highestConfidence  = thirdPass;
                    pageResultsHighest = thirdResults;
                }
            }

            return(highestConfidence);
        }
示例#3
0
        public MainWindow()
        {
            InitializeComponent();

            CurrentPageAuth         = new PageAuth();
            CurrentPageMenu         = new PageMenu();
            CurrentPageResults      = new PageResults();
            CurrentPagePrescription = new PagePrescription();
            CurrentPageRedactor     = new PageRedactor();
            CurrentPageTest         = new PageTest();
            CurrentPageTestsList    = new PageTestsList();
            CurrentPageRes          = new PageRes();

            CurrentBackButton = BackButton;
            CurrentLabelName  = LabelName;
            CurrentFrame      = MainFrame;

            MainFrame.Navigate(CurrentPageAuth);
        }
示例#4
0
        /// <summary>
        /// Produces recursive search in current folder.
        /// </summary>
        /// <param name="commandText">SQL command text for search in a folder.</param>
        /// <param name="searchString">A phrase to search.</param>
        /// <param name="offset">The number of children to skip before returning the remaining items. Start listing from from next item.</param>
        /// <param name="nResults">The number of items to return.</param>
        private async Task <PageResults> GetSearchResultsAsync(string commandText, string searchString, bool includeSnippet, long?offset, long?nResults)
        {
            PageResults folderSearchResults = await Context.ExecuteItemPagedHierarchyAsync(
                Path,
                commandText,
                offset,
                nResults,
                "@Parent", ItemId,
                "@SearchString", searchString);

            foreach (IHierarchyItemAsync item in folderSearchResults.Page)
            {
                if (includeSnippet && item is DavFile)
                {
                    (item as DavFile).Snippet = "Not Implemented";
                }
            }

            return(folderSearchResults);
        }
示例#5
0
        public async Task Returns_OkResult_With_PageResults()
        {
            // Arrange
            const int pageSize       = 15;
            const int pageIndex      = 2;
            const int totalItems     = 31;
            const int totalPageCount = 3;

            var queryResults = new PageResults <Country>
            {
                PageSize  = pageSize,
                PageIndex = pageIndex,
                Total     = totalItems
            };

            GetMock <ICountryListService>()
            .Setup(x => x.Get(
                       It.Is <PageParams>(p => p.PageSize == pageSize && p.PageIndex == pageIndex)
                       ))
            .Returns(Task.FromResult(queryResults));

            // Act
            var apiParams = new ApiParams
            {
                PageIndex = pageIndex,
                PageLimit = pageSize
            };
            var result = await ClassUnderTest.List(apiParams);

            // Assert
            var okResult    = Assert.IsType <OkObjectResult>(result.Result);
            var returnValue = Assert.IsType <VmPage <VmCountryList> >(okResult.Value);

            returnValue.PageSize.Should().Be(pageSize);
            returnValue.PageIndex.Should().Be(pageIndex);
            returnValue.TotalCount.Should().Be(totalItems);
            returnValue.TotalPageCount.Should().Be(totalPageCount);
        }
示例#6
0
        public async Task <PageResults <Blog> > GetAllAsync(BlogPaging blogPaging)
        {
            var result = new PageResults <Blog>();

            using (var connection = new SqlConnection(_config.GetConnectionString("DefaultConnection")))
            {
                await connection.OpenAsync();

                using (var multi = await connection.QueryMultipleAsync("Blog_GetAll",
                                                                       new
                {
                    Offset = (blogPaging.Page - 1) * blogPaging.PageSize,
                    PageSize = blogPaging.PageSize
                },
                                                                       commandType: System.Data.CommandType.StoredProcedure
                                                                       ))
                {
                    result.Items      = multi.Read <Blog>();
                    result.TotalCount = multi.ReadFirst <int>();
                }
            }

            return(result);
        }
示例#7
0
        private PageResults GetPageConfidence(IOcrPage ocrPage)
        {
            IOcrPageCharacters pageCharacters = ocrPage.GetRecognizedCharacters();
            double             pageConfidence = 0;
            int certainWords   = 0;
            int totalWords     = 0;
            int totalZoneWords = 0;
            int textZoneCount  = 0;

            for (int i = 0; i < ocrPage.Zones.Count; i++)
            {
                IOcrZoneCharacters zoneCharacters = pageCharacters.FindZoneCharacters(i);
                if (zoneCharacters.Count == 0)
                {
                    continue;
                }

                textZoneCount++;
                double zoneConfidence = 0;
                int    characterCount = 0;
                double wordConfidence = 0;
                totalZoneWords = 0;
                bool newWord = true;
                foreach (var ocrCharacter in zoneCharacters)
                {
                    if (newWord)
                    {
                        wordConfidence = 0;
                        characterCount = 0;
                        wordConfidence = 1000;
                    }
                    if (ocrCharacter.Confidence < wordConfidence)
                    {
                        wordConfidence = ocrCharacter.Confidence;
                    }
                    characterCount++;

                    if ((ocrCharacter.Position & OcrCharacterPosition.EndOfWord) == OcrCharacterPosition.EndOfWord || (ocrCharacter.Position & OcrCharacterPosition.EndOfLine) == OcrCharacterPosition.EndOfLine)
                    {
                        if (characterCount > 3)
                        {
                            if (ocrCharacter.WordIsCertain)
                            {
                                certainWords++;
                            }
                            totalWords++;
                            totalZoneWords++;
                            zoneConfidence += wordConfidence;
                        }

                        newWord = true;
                    }
                    else
                    {
                        newWord = false;
                    }
                }

                if (totalZoneWords > 0)
                {
                    zoneConfidence /= totalZoneWords;
                    pageConfidence += zoneConfidence;
                }
                else
                {
                    zoneConfidence  = 0;
                    pageConfidence += zoneConfidence;
                }
            }
            if (textZoneCount > 0)
            {
                pageConfidence /= textZoneCount;
            }
            else
            {
                pageConfidence = 0;
            }

            PageResults results = new PageResults(pageConfidence, certainWords, totalWords);

            return(results);
        }