Esempio n. 1
0
 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);
     }
 }
Esempio n. 2
0
        private void CombineWith(ShapeNode node, ShapeNode start, ShapeNode end)
        {
            if ((CombineVowels && node.Type() == CogFeatureSystem.VowelType) || (CombineConsonants && node.Type() == CogFeatureSystem.ConsonantType))
            {
                var strRep     = new StringBuilder();
                var origStrRep = new StringBuilder();
                strRep.Append(node.StrRep());
                origStrRep.Append(node.OriginalStrRep());
                ShapeNode n = start;
                while (n != end.Next)
                {
                    strRep.Append(n.StrRep());
                    origStrRep.Append(n.OriginalStrRep());
                    node.Annotation.FeatureStruct.Add(n.Annotation.FeatureStruct);
                    n = n.Next;
                }
                node.Annotation.FeatureStruct.AddValue(CogFeatureSystem.StrRep, strRep.ToString());
                node.Annotation.FeatureStruct.AddValue(CogFeatureSystem.OriginalStrRep, origStrRep.ToString());
                node.Annotation.FeatureStruct.AddValue(CogFeatureSystem.SegmentType, CogFeatureSystem.Complex);

                FeatureStruct firstFS;
                if (start.IsComplex())
                {
                    firstFS = start.Annotation.FeatureStruct.GetValue(CogFeatureSystem.First);
                }
                else
                {
                    firstFS = new FeatureStruct();
                    foreach (Feature feature in start.Annotation.FeatureStruct.Features.Where(f => !CogFeatureSystem.Instance.ContainsFeature(f)))
                    {
                        firstFS.AddValue(feature, start.Annotation.FeatureStruct.GetValue(feature));
                    }
                }
                node.Annotation.FeatureStruct.AddValue(CogFeatureSystem.First, firstFS);
            }
            else
            {
                ShapeNode n = start;
                while (n != end.Next)
                {
                    var newNode = n.DeepClone();
                    node.AddAfter(newNode);
                    node = newNode;
                    n    = n.Next;
                }
            }
        }
Esempio n. 3
0
        protected ShapeNode Combine(FeatureSymbol syllablePosition, Shape newShape, ShapeNode start, ShapeNode end)
        {
            ShapeNode newStart = null;

            if (start == end)
            {
                newStart = start.DeepClone();
                newStart.Annotation.FeatureStruct.AddValue(CogFeatureSystem.SyllablePosition, syllablePosition);
                newShape.Add(newStart);
            }
            else if ((_combineVowels && syllablePosition == CogFeatureSystem.Nucleus) || (_combineConsonants && syllablePosition != CogFeatureSystem.Nucleus))
            {
                var fs         = start.Annotation.FeatureStruct.DeepClone();
                var strRep     = new StringBuilder();
                var origStrRep = new StringBuilder();
                strRep.Append(start.StrRep());
                origStrRep.Append(start.OriginalStrRep());
                ShapeNode node      = start.Next;
                bool      isComplex = false;
                while (node != end.Next)
                {
                    strRep.Append(node.StrRep());
                    origStrRep.Append(node.OriginalStrRep());
                    fs.Add(node.Annotation.FeatureStruct);
                    node      = node.Next;
                    isComplex = true;
                }
                fs.AddValue(CogFeatureSystem.StrRep, strRep.ToString());
                fs.AddValue(CogFeatureSystem.OriginalStrRep, origStrRep.ToString());
                fs.AddValue(CogFeatureSystem.SegmentType, isComplex ? CogFeatureSystem.Complex : CogFeatureSystem.Simple);
                fs.AddValue(CogFeatureSystem.SyllablePosition, syllablePosition);
                if (isComplex)
                {
                    FeatureStruct firstFS;
                    if (start.IsComplex())
                    {
                        firstFS = start.Annotation.FeatureStruct.GetValue(CogFeatureSystem.First);
                    }
                    else
                    {
                        firstFS = new FeatureStruct();
                        foreach (Feature feature in start.Annotation.FeatureStruct.Features.Where(f => !CogFeatureSystem.Instance.ContainsFeature(f)))
                        {
                            firstFS.AddValue(feature, start.Annotation.FeatureStruct.GetValue(feature));
                        }
                    }
                    fs.AddValue(CogFeatureSystem.First, firstFS);
                }
                newStart = newShape.Add(fs);
            }
            else
            {
                ShapeNode node = start;
                while (node != end.Next)
                {
                    var newNode = node.DeepClone();
                    newNode.Annotation.FeatureStruct.AddValue(CogFeatureSystem.SyllablePosition, syllablePosition);
                    newShape.Add(newNode);
                    if (newStart == null)
                    {
                        newStart = newNode;
                    }
                    node = node.Next;
                }
            }

            Debug.Assert(newStart != null);
            return(newStart);
        }
Esempio n. 4
0
        protected void ProcessSyllable(ShapeNode startNode, ShapeNode endNode, Shape newShape)
        {
            ShapeNode newStartNode = null;
            ShapeNode node         = startNode;

            while (node.Type() == CogFeatureSystem.BoundaryType && node != endNode.Next)
            {
                ShapeNode newNode = node.DeepClone();
                newShape.Add(newNode);
                if (newStartNode == null)
                {
                    newStartNode = newNode;
                }
                node = node.Next;
            }

            ShapeNode onsetStart = node;

            while (node.Type() == CogFeatureSystem.ConsonantType && node != endNode.Next)
            {
                node = node.Next;
            }
            ShapeNode onsetEnd = node.Prev;

            if (onsetStart != node)
            {
                ShapeNode start = Combine(CogFeatureSystem.Onset, newShape, onsetStart, onsetEnd);
                if (newStartNode == null)
                {
                    newStartNode = start;
                }
            }

            if (node != endNode.Next)
            {
                ShapeNode nucleusStart = node;
                while (node.Type() == CogFeatureSystem.VowelType && node != endNode.Next)
                {
                    node = node.Next;
                }
                ShapeNode nucleusEnd = node.Prev;

                ShapeNode start = Combine(CogFeatureSystem.Nucleus, newShape, nucleusStart, nucleusEnd);
                if (newStartNode == null)
                {
                    newStartNode = start;
                }
            }

            if (node != endNode.Next)
            {
                ShapeNode codaStart = node;
                while (node.Type() == CogFeatureSystem.ConsonantType && node != endNode.Next)
                {
                    node = node.Next;
                }
                if (codaStart != node)
                {
                    ShapeNode codaEnd = node.Prev;
                    Combine(CogFeatureSystem.Coda, newShape, codaStart, codaEnd);
                }
            }

            while (node != endNode.Next)
            {
                newShape.Add(node.DeepClone());
                node = node.Next;
            }
            newShape.Annotations.Add(newStartNode, newShape.Last, FeatureStruct.New().Symbol(CogFeatureSystem.SyllableType).Value);
        }