예제 #1
0
        public static bool TryGetMatchingSoundClass(this IEnumerable <SoundClass> soundClasses, SegmentPool segmentPool, ShapeNode node, out SoundClass soundClass)
        {
            Annotation <ShapeNode> stemAnn = ((Shape)node.List).Annotations.First(ann => ann.Type() == CogFeatureSystem.StemType);
            ShapeNode left = null;

            if (stemAnn.Range.Contains(node) || node.Annotation.CompareTo(stemAnn) > 0)
            {
                ShapeNode leftNode = node.GetPrev(NodeFilter);
                if (leftNode != null)
                {
                    left = stemAnn.Range.Contains(leftNode) ? leftNode : node.List.Begin;
                }
            }

            Ngram <Segment> target = stemAnn.Range.Contains(node) ? segmentPool.Get(node) : Segment.Anchor;

            ShapeNode right = null;

            if (stemAnn.Range.Contains(node) || node.Annotation.CompareTo(stemAnn) < 0)
            {
                ShapeNode rightNode = node.GetNext(NodeFilter);
                if (rightNode != null)
                {
                    right = stemAnn.Range.Contains(rightNode) ? rightNode : node.List.End;
                }
            }

            soundClass = soundClasses.FirstOrDefault(sc => sc.Matches(left, target, right));
            return(soundClass != null);
        }
예제 #2
0
        public static SoundContext ToSoundContext(this ShapeNode node, SegmentPool segmentPool, IEnumerable <SoundClass> soundClasses)
        {
            ShapeNode  prevNode = node.GetPrev(NodeFilter);
            SoundClass leftEnv;

            if (!soundClasses.TryGetMatchingSoundClass(segmentPool, prevNode, out leftEnv))
            {
                leftEnv = null;
            }
            ShapeNode  nextNode = node.GetNext(NodeFilter);
            SoundClass rightEnv;

            if (!soundClasses.TryGetMatchingSoundClass(segmentPool, nextNode, out rightEnv))
            {
                rightEnv = null;
            }
            return(new SoundContext(leftEnv, segmentPool.Get(node), rightEnv));
        }
예제 #3
0
        public static bool TryGetMatchingSoundClass(this IEnumerable<SoundClass> soundClasses, SegmentPool segmentPool, ShapeNode node, out SoundClass soundClass)
        {
            Annotation<ShapeNode> stemAnn = ((Shape) node.List).Annotations.First(ann => ann.Type() == CogFeatureSystem.StemType);
            ShapeNode left = null;
            if (stemAnn.Span.Contains(node) || node.Annotation.CompareTo(stemAnn) > 0)
            {
                ShapeNode leftNode = node.GetPrev(NodeFilter);
                if (leftNode != null)
                    left = stemAnn.Span.Contains(leftNode) ? leftNode : node.List.Begin;
            }

            Ngram<Segment> target = stemAnn.Span.Contains(node) ? segmentPool.Get(node) : Segment.Anchor;

            ShapeNode right = null;
            if (stemAnn.Span.Contains(node) || node.Annotation.CompareTo(stemAnn) < 0)
            {
                ShapeNode rightNode = node.GetNext(NodeFilter);
                if (rightNode != null)
                    right = stemAnn.Span.Contains(rightNode) ? rightNode : node.List.End;
            }

            soundClass = soundClasses.FirstOrDefault(sc => sc.Matches(left, target, right));
            return soundClass != null;
        }
예제 #4
0
 public static SoundContext ToSoundContext(this ShapeNode node, SegmentPool segmentPool, IEnumerable<SoundClass> soundClasses)
 {
     ShapeNode prevNode = node.GetPrev(NodeFilter);
     SoundClass leftEnv;
     if (!soundClasses.TryGetMatchingSoundClass(segmentPool, prevNode, out leftEnv))
         leftEnv = null;
     ShapeNode nextNode = node.GetNext(NodeFilter);
     SoundClass rightEnv;
     if (!soundClasses.TryGetMatchingSoundClass(segmentPool, nextNode, out rightEnv))
         rightEnv = null;
     return new SoundContext(leftEnv, segmentPool.Get(node), rightEnv);
 }