Exemplo n.º 1
0
        public Shape Segment(string str)
        {
            IEnumerable <ShapeNode> nodes;
            int errorPos;

            if (GetShapeNodes(str, out nodes, out errorPos))
            {
                var shape = new Shape(_spanFactory, begin => new ShapeNode(_spanFactory, begin ? HCFeatureSystem.LeftSideAnchor : HCFeatureSystem.RightSideAnchor));
                shape.AddRange(nodes);
                return(shape);
            }

            throw new InvalidShapeException(str, errorPos);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Converts the specified string to a phonetic shape. It matches the longest possible segment
        /// first. If the string segmented successfully, this will return -1, otherwise it will return
        /// the position where the error occurred.
        /// </summary>
        /// <param name="str">The string.</param>
        /// <param name="shape">The shape.</param>
        public int TrySegment(string str, out Shape shape)
        {
            IEnumerable <ShapeNode> nodes;
            int errorPos;

            if (GetShapeNodes(str, out nodes, out errorPos))
            {
                shape = new Shape(_spanFactory, begin => new ShapeNode(_spanFactory, begin ? HCFeatureSystem.LeftSideAnchor : HCFeatureSystem.RightSideAnchor));
                shape.AddRange(nodes);
                return(errorPos);
            }

            shape = null;
            return(errorPos);
        }