Ejemplo n.º 1
0
        public Segment Get(ShapeNode node)
        {
            if (node == null)
                return null;

            return _segments.GetOrAdd(node.StrRep(), s =>
                {
                    FeatureStruct fs = node.Annotation.FeatureStruct.DeepClone();
                    fs.RemoveValue(CogFeatureSystem.OriginalStrRep);
                    fs.RemoveValue(CogFeatureSystem.SyllablePosition);
                    fs.Freeze();
                    return new Segment(fs);
                });
        }
Ejemplo n.º 2
0
        public Segment Get(ShapeNode node)
        {
            if (node == null)
            {
                return(null);
            }

            return(_segments.GetOrAdd(node.StrRep(), s =>
            {
                FeatureStruct fs = node.Annotation.FeatureStruct.DeepClone();
                fs.RemoveValue(CogFeatureSystem.OriginalStrRep);
                fs.RemoveValue(CogFeatureSystem.SyllablePosition);
                fs.Freeze();
                return new Segment(fs);
            }));
        }
Ejemplo n.º 3
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.Clone();
                    node.AddAfter(newNode);
                    node = newNode;
                    n    = n.Next;
                }
            }
        }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
0
 public Segment GetExisting(ShapeNode node)
 {
     return(GetExisting(node.StrRep()));
 }
Ejemplo n.º 6
0
 private void AssertShapeNodeEqual(ShapeNode actualNode, string expectedStrRep, FeatureSymbol expectedType)
 {
     Assert.That(actualNode.StrRep(), Is.EqualTo(expectedStrRep));
     Assert.That(actualNode.Type(), Is.EqualTo(expectedType));
 }
Ejemplo n.º 7
0
 public Segment GetExisting(ShapeNode node)
 {
     return GetExisting(node.StrRep());
 }
Ejemplo n.º 8
0
 private void AssertShapeNodeEqual(ShapeNode actualNode, string expectedStrRep, FeatureSymbol expectedType)
 {
     Assert.That(actualNode.StrRep(), Is.EqualTo(expectedStrRep));
     Assert.That(actualNode.Type(), Is.EqualTo(expectedType));
 }
Ejemplo n.º 9
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;
                }
            }
        }