private void AddNode(ShapeNode node, State <Shape, ShapeNode> state, string id) { Arc <Shape, ShapeNode> arc = state.Arcs.FirstOrDefault(a => node.Annotation.FeatureStruct.ValueEquals(a.Input.FeatureStruct)); ShapeNode nextNode = node.GetNext(n => _filter(n.Annotation)); State <Shape, ShapeNode> nextState; if (arc != null) { nextState = arc.Target; if (nextNode == node.List.End) { nextState.IsAccepting = true; nextState.AcceptInfos.Add(new AcceptInfo <Shape, ShapeNode>(id, (shape, match) => true, _shapeCount)); } } else { nextState = nextNode == node.List.End ? _fsa.CreateAcceptingState(id, (shape, match) => true, _shapeCount) : _fsa.CreateState(); FeatureStruct condition = node.Annotation.FeatureStruct.Clone(); condition.Freeze(); state.Arcs.Add(condition, nextState); } if (nextNode != node.List.End) { AddNode(nextNode, nextState, id); } }
private void SyllabifyAnnotation(Word word, Annotation <ShapeNode> ann, Shape newShape) { if (word.Shape.GetNodes(ann.Span).Any(n => n.Type() == CogFeatureSystem.ToneLetterType || n.StrRep() == ".")) { ShapeNode[] annNodes = word.Shape.GetNodes(ann.Span).ToArray(); int i; for (i = 0; i < annNodes.Length && annNodes[i].Type().IsOneOf(CogFeatureSystem.ToneLetterType, CogFeatureSystem.BoundaryType); i++) { newShape.Add(annNodes[i].DeepClone()); } ShapeNode syllableStart = annNodes[i]; ShapeNode node = syllableStart.GetNext(n => n.Type().IsOneOf(CogFeatureSystem.ToneLetterType, CogFeatureSystem.BoundaryType)); while (ann.Span.Contains(node)) { if (syllableStart != node) { ProcessSyllable(syllableStart, node.Prev, newShape); } newShape.Add(node.DeepClone()); syllableStart = node.Next; node = node.GetNext(n => n.Type().IsOneOf(CogFeatureSystem.ToneLetterType, CogFeatureSystem.BoundaryType)); } if (ann.Span.Contains(syllableStart)) { ProcessSyllable(syllableStart, ann.Span.End, newShape); } } else { SyllabifyUnmarkedAnnotation(word, ann, newShape); } }
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); }
private void AddNode(ShapeNode node, State<Shape, ShapeNode> state, string id) { Arc<Shape, ShapeNode> arc = state.Arcs.FirstOrDefault(a => node.Annotation.FeatureStruct.ValueEquals(a.Input.FeatureStruct)); ShapeNode nextNode = node.GetNext(n => _filter(n.Annotation)); State<Shape, ShapeNode> nextState; if (arc != null) { nextState = arc.Target; if (nextNode == node.List.End) { nextState.IsAccepting = true; nextState.AcceptInfos.Add(new AcceptInfo<Shape, ShapeNode>(id, (shape, match) => true, _shapeCount)); } } else { nextState = nextNode == node.List.End ? _fsa.CreateAcceptingState(id, (shape, match) => true, _shapeCount) : _fsa.CreateState(); FeatureStruct condition = node.Annotation.FeatureStruct.DeepClone(); condition.Freeze(); state.Arcs.Add(condition, nextState); } if (nextNode != node.List.End) AddNode(nextNode, nextState, id); }
private static Match <ComplexConcParagraphData, ShapeNode> GetNextMatch(Match <ComplexConcParagraphData, ShapeNode> match) { ShapeNode nextNode = match.Span.GetEnd(match.Matcher.Direction); if (((FeatureSymbol)nextNode.Annotation.FeatureStruct.GetValue <SymbolicFeatureValue>("type")).ID != "bdry") { nextNode = nextNode.GetNext(match.Matcher.Direction); } return(match.Matcher.Match(match.Input, nextNode)); }
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)); }
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; }