< Summary

Class:Microsoft.Azure.CognitiveServices.FormRecognizer.Models.ElementReference
Assembly:Microsoft.Azure.CognitiveServices.Vision.FormRecognizer
File(s):C:\Git\azure-sdk-for-net\sdk\cognitiveservices\FormRecognizer\src\Customizations\ElementReference.cs
C:\Git\azure-sdk-for-net\sdk\cognitiveservices\FormRecognizer\src\Generated\Models\ElementReference.cs
Covered lines:0
Uncovered lines:26
Coverable lines:26
Total lines:120
Line coverage:0% (0 of 26)
Covered branches:0
Total branches:4
Branch coverage:0% (0 of 4)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
get_Page()-0%100%
.ctor()-0%100%
get_PageIndex()-0%100%
get_LineIndex()-0%100%
.ctor(...)-0%100%
get_WordIndex()-0%100%
ResolveWord(...)-0%100%
get_RefProperty()-0%100%
Resolve()-0%0%
.ctor()-0%100%
.ctor(...)-0%100%
get_RefProperty()-0%100%

File(s)

C:\Git\azure-sdk-for-net\sdk\cognitiveservices\FormRecognizer\src\Customizations\ElementReference.cs

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using System.Linq;
 4using System.Text.RegularExpressions;
 5
 6namespace Microsoft.Azure.CognitiveServices.FormRecognizer.Models
 7{
 8    using Newtonsoft.Json;
 9    using System.Collections;
 10    using System.Collections.Generic;
 11    using System.Linq;
 12
 13    public partial class ElementReference {
 14        private string _resolvedRefProperty = null;
 15        private int _pageIndex;
 16        private int _lineIndex;
 17        private int _wordIndex;
 18
 19        /// <summary>
 20        /// Number of the page containing the element.
 21        /// </summary>
 022        public int Page { get { Resolve(); return _pageIndex + 1; } }
 23
 024        /// <summary>
 25        /// Index of the page containing the element (0-indexed).
 26        /// </summary>
 027        public int PageIndex { get { Resolve(); return _pageIndex; } }
 28
 29        /// <summary>
 30        /// Index of the line within the page containing the element (0-indexed).
 31        /// </summary>
 032        public int LineIndex { get { Resolve(); return _lineIndex; } }
 33
 034        /// <summary>
 35        /// Index of the word within the line containing the element (0-indexed).
 036        /// </summary>
 037        public int WordIndex { get { Resolve(); return _wordIndex; } }
 38
 39        /// <summary>
 40        /// Returns the word referenced by the JSON pointer element reference.
 41        /// </summary>
 42        public Word ResolveWord(ReadReceiptResult result)
 43        {
 44            try
 45            {
 046                return result.RecognitionResults[PageIndex].Lines[LineIndex].Words[WordIndex];
 47            }
 048            catch (Exception e)
 49            {
 50                //throw new ArgumentException("Invalid element reference.");
 051                throw new ArgumentException("Invalid element reference, {0}", e);
 52            }
 053        }
 54
 55        private void Resolve()
 56        {
 057            if (_resolvedRefProperty != RefProperty)
 58            {
 059                var match = Regex.Match(RefProperty, @"^#/recognitionResults/(\d+)/lines/(\d+)/words/(\d+)$");
 060                if (!match.Success)
 61                {
 062                    throw new ArgumentException("Invalid element reference.");
 63                }
 064                _pageIndex = int.Parse(match.Groups[1].Value);
 065                _lineIndex = int.Parse(match.Groups[2].Value);
 066                _wordIndex = int.Parse(match.Groups[3].Value);
 067                _resolvedRefProperty = RefProperty;
 68            }
 069        }
 70    }
 71}

C:\Git\azure-sdk-for-net\sdk\cognitiveservices\FormRecognizer\src\Generated\Models\ElementReference.cs

#LineLine coverage
 1// <auto-generated>
 2// Copyright (c) Microsoft Corporation. All rights reserved.
 3// Licensed under the MIT License. See License.txt in the project root for
 4// license information.
 5//
 6// Code generated by Microsoft (R) AutoRest Code Generator.
 7// Changes may cause incorrect behavior and will be lost if the code is
 8// regenerated.
 9// </auto-generated>
 10
 11namespace Microsoft.Azure.CognitiveServices.FormRecognizer.Models
 12{
 13    using Newtonsoft.Json;
 14    using System.Linq;
 15
 16    /// <summary>
 17    /// Reference to an OCR word.
 18    /// </summary>
 19    public partial class ElementReference
 20    {
 21        /// <summary>
 22        /// Initializes a new instance of the ElementReference class.
 23        /// </summary>
 024        public ElementReference()
 25        {
 26            CustomInit();
 027        }
 28
 29        /// <summary>
 30        /// Initializes a new instance of the ElementReference class.
 31        /// </summary>
 032        public ElementReference(string refProperty = default(string))
 33        {
 034            RefProperty = refProperty;
 35            CustomInit();
 036        }
 37
 38        /// <summary>
 39        /// An initialization method that performs custom operations like setting defaults
 40        /// </summary>
 41        partial void CustomInit();
 42
 43        /// <summary>
 44        /// </summary>
 45        [JsonProperty(PropertyName = "$ref")]
 046        public string RefProperty { get; set; }
 47
 48    }
 49}