private ClassifierResult ComputeResult(string text, Document document, string documentPath, ClassifierDocumentType[] documentTypes, int evidencePage)
        {
            // example of unsuccessful classification
            if (documentTypes == null || !documentTypes.Any() || document.Pages.Length <= evidencePage)
            {
                return(null);
            }

            // take first word from the evidence page in the document and consider it as evidence for the classification
            var firstWord           = document.Pages[evidencePage].Sections[0].WordGroups[0].Words[0];
            var firstWordValueToken = new ResultsValueTokens(0, (float)document.Pages[evidencePage].Size.Width, (float)document.Pages[evidencePage].Size.Height, new[] { firstWord.Box });

            // return first document type, with evidecing based on the first word in the document
            var classificationResult = new ClassificationResult(
                // consider the first document type requested
                documentTypes.First().DocumentTypeId,
                // fill in document id from the Document Object Model information
                document.DocumentId,
                // simulate a 85% confidence
                0.85f,
                // take OCR confidence of the words used for evidencing
                firstWord.OcrConfidence,
                // build the evidencing information
                new ResultsContentReference(firstWord.IndexInText, firstWord.Text.Length, new[] { firstWordValueToken }),
                // consider the classification applying to the entire document (all pages)
                new ResultsDocumentBounds(document.Pages.Length, document.Length));

            return(new ClassifierResult
            {
                Classifications = new[] { classificationResult }
            });
        }
예제 #2
0
        private static ResultsValue CreateResultsValue(int wordIndex, Document document, string value = null)
        {
            var word           = document.Pages[0].Sections.SelectMany(s => s.WordGroups).SelectMany(w => w.Words).ToArray()[wordIndex];
            var wordValueToken = new ResultsValueTokens(word.IndexInText, word.Text.Length, 0, (float)document.Pages[0].Size.Width, (float)document.Pages[0].Size.Height, new[] { word.Box });
            var reference      = new ResultsContentReference(word.IndexInText, word.Text.Length, new[] { wordValueToken });

            return(new ResultsValue(value ?? word.Text, reference, 0.9f, word.OcrConfidence));
        }
예제 #3
0
        private static ResultsDataPoint CreateBooleanFieldDataPoint(Field firstBooleanField, Document document)
        {
            var booleanToken      = new ResultsValueTokens(0, (float)document.Pages[0].Size.Width, (float)document.Pages[0].Size.Height, new[] { Box.CreateChecked(50, 100, 200, 300) });
            var reference         = new ResultsContentReference(0, 0, new[] { booleanToken });
            var firstBooleanValue = new ResultsValue("Yes", reference, 0.9f, 1f);

            return(new ResultsDataPoint(
                       firstBooleanField.FieldId,
                       firstBooleanField.FieldName,
                       firstBooleanField.Type,
                       new[] { firstBooleanValue }));
        }