Exemplo n.º 1
0
        private int Diff(FeatureStruct fs1, FeatureStruct fs2, SymbolicFeature feature)
        {
            SymbolicFeatureValue pValue;

            if (!fs1.TryGetValue(feature, out pValue))
            {
                return(0);
            }
            SymbolicFeatureValue qValue;

            if (!fs2.TryGetValue(feature, out qValue))
            {
                return(0);
            }

            int sum   = 0;
            int count = 0;

            foreach (FeatureSymbol pSymbol in pValue.Values)
            {
                foreach (FeatureSymbol qSymbol in qValue.Values)
                {
                    sum += Math.Abs(_valueMetrics[pSymbol] - _valueMetrics[qSymbol]);
                    count++;
                }
            }

            return(sum / count);
        }
Exemplo n.º 2
0
        static CogFeatureSystem()
        {
            AnchorType = new FeatureSymbol(Guid.NewGuid().ToString()) {Description = "anchor"};
            VowelType = new FeatureSymbol(Guid.NewGuid().ToString()) {Description = "vowel"};
            ConsonantType = new FeatureSymbol(Guid.NewGuid().ToString()) {Description = "consonant"};
            ToneLetterType = new FeatureSymbol(Guid.NewGuid().ToString()) {Description = "toneLetter"};
            BoundaryType = new FeatureSymbol(Guid.NewGuid().ToString()) {Description = "boundary"};
            SyllableType = new FeatureSymbol(Guid.NewGuid().ToString()) {Description = "syllable"};
            StemType = new FeatureSymbol(Guid.NewGuid().ToString()) {Description = "stem"};
            PrefixType = new FeatureSymbol(Guid.NewGuid().ToString()) {Description = "prefix"};
            SuffixType = new FeatureSymbol(Guid.NewGuid().ToString()) {Description = "suffix"};

            Type = new SymbolicFeature(Guid.NewGuid().ToString(), AnchorType, VowelType, ConsonantType, ToneLetterType, BoundaryType, SyllableType, StemType, PrefixType, SuffixType) {Description = "Type"};

            Complex = new FeatureSymbol(Guid.NewGuid().ToString()) {Description = "complex"};
            Simple = new FeatureSymbol(Guid.NewGuid().ToString()) {Description = "simple"};

            SegmentType = new SymbolicFeature(Guid.NewGuid().ToString(), Complex, Simple) {Description = "SegmentType"};

            OriginalStrRep = new StringFeature(Guid.NewGuid().ToString()) {Description = "OriginalStrRep"};
            StrRep = new StringFeature(Guid.NewGuid().ToString()) {Description = "StrRep"};

            First = new ComplexFeature(Guid.NewGuid().ToString()) {Description = "First"};

            Onset = new FeatureSymbol(Guid.NewGuid().ToString()) {Description = "onset"};
            Nucleus = new FeatureSymbol(Guid.NewGuid().ToString()) {Description = "nucleus"};
            Coda = new FeatureSymbol(Guid.NewGuid().ToString()) {Description = "coda"};

            SyllablePosition = new SymbolicFeature(Guid.NewGuid().ToString(), Onset, Nucleus, Coda) {Description = "SyllablePosition"};

            Instance = new CogFeatureSystem();
        }
Exemplo n.º 3
0
        private int Diff(FeatureStruct fs1, FeatureStruct fs2, SymbolicFeature feature)
        {
            SymbolicFeatureValue pValue;

            if (!fs1.TryGetValue(feature, out pValue))
            {
                pValue = null;
            }
            SymbolicFeatureValue qValue;

            if (!fs2.TryGetValue(feature, out qValue))
            {
                qValue = null;
            }

            if (pValue == null && qValue == null)
            {
                return(0);
            }

            FeatureSymbol[] values1 = pValue == null?feature.PossibleSymbols.ToArray() : pValue.Values.ToArray();

            FeatureSymbol[] values2 = qValue == null?feature.PossibleSymbols.ToArray() : qValue.Values.ToArray();

            if (values2.Length > values1.Length)
            {
                FeatureSymbol[] temp = values1;
                values1 = values2;
                values2 = temp;
            }
            return((int)Math.Round(values1.Average(s1 => values2.Min(s2 => Math.Abs(_valueMetrics[s1] - _valueMetrics[s2])))));
        }
Exemplo n.º 4
0
 public FeatureViewModel(SymbolicFeature feature, FeatureSymbol symbol)
 {
     _feature = feature;
     _values = new ReadOnlyCollection<FeatureValueViewModel>(feature.PossibleSymbols.Select(s => new FeatureValueViewModel(s)).ToArray());
     if (symbol != null)
         _selectedValue = _values.Single(fv => fv.DomainSymbol == symbol);
     else if (_values.Count > 0)
         _selectedValue = _values[0];
 }
        public SymbolicFeature AddPartsOfSpeech(IEnumerable <FeatureSymbol> pos)
        {
            var posFeature = new SymbolicFeature(PartOfSpeechID, pos)
            {
                Description = "POS"
            };

            base.Add(posFeature);
            return(posFeature);
        }
Exemplo n.º 6
0
        public void Migrate(SegmentPool segmentPool, CogProject project)
        {
            if (project.FeatureSystem.ContainsFeature("airstream"))
                return;

            var pulmonic = new FeatureSymbol("pulmonic");
            var ejective = new FeatureSymbol("ejective");
            var implosive = new FeatureSymbol("implosive");
            var click = new FeatureSymbol("click");
            var airstream = new SymbolicFeature("airstream",
                pulmonic,
                ejective,
                implosive,
                click) {Description = "Airstream"};
            project.FeatureSystem.Add(airstream);

            AddValue(project.Segmenter.Modifiers, "ʼ", ejective);

            AddValue(project.Segmenter.Consonants, "ɓ", implosive);
            AddValue(project.Segmenter.Consonants, "ɗ", implosive);
            AddValue(project.Segmenter.Consonants, "ʄ", implosive);
            AddValue(project.Segmenter.Consonants, "ɠ", implosive);
            AddValue(project.Segmenter.Consonants, "ʛ", implosive);

            FeatureSymbol affricate;
            if (project.FeatureSystem.TryGetSymbol("affricate", out affricate))
            {
                project.Segmenter.Consonants.AddSymbolBasedOn("ʘ", "p", affricate, click);
                project.Segmenter.Consonants.AddSymbolBasedOn("ǀ", "θ", affricate, click);
                project.Segmenter.Consonants.AddSymbolBasedOn("ǁ", "ɬ", affricate, click);
            }
            project.Segmenter.Consonants.AddSymbolBasedOn("ǃ", "t", click);
            project.Segmenter.Consonants.AddSymbolBasedOn("ǂ", "c", click);

            foreach (Symbol symbol in project.Segmenter.Vowels.ToArray())
                AddValue(project.Segmenter.Vowels, symbol, pulmonic);

            foreach (Symbol symbol in project.Segmenter.Consonants.Where(s => !s.FeatureStruct.ContainsFeature("airstream")).ToArray())
                AddValue(project.Segmenter.Consonants, symbol, pulmonic);

            foreach (KeyValuePair<string, IWordAligner> aligner in project.WordAligners.Where(kvp => kvp.Value is Aline).ToArray())
            {
                var aline = (Aline) aligner.Value;
                Dictionary<SymbolicFeature, int> featWeights = aline.FeatureWeights.ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
                featWeights[airstream] = 5;
                Dictionary<FeatureSymbol, int> valueMetrics = aline.ValueMetrics.ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
                valueMetrics[pulmonic] = 100;
                valueMetrics[ejective] = 66;
                valueMetrics[implosive] = 33;
                valueMetrics[click] = 0;
                project.WordAligners[aligner.Key] = new Aline(segmentPool, aline.RelevantVowelFeatures, aline.RelevantConsonantFeatures.Concat(airstream),
                    featWeights, valueMetrics, aline.Settings);
            }
        }
Exemplo n.º 7
0
 public FeatureViewModel(SymbolicFeature feature, FeatureSymbol symbol)
 {
     _feature = feature;
     _values  = new ReadOnlyCollection <FeatureValueViewModel>(feature.PossibleSymbols.Select(s => new FeatureValueViewModel(s)).ToArray());
     if (symbol != null)
     {
         _selectedValue = _values.Single(fv => fv.DomainSymbol == symbol);
     }
     else if (_values.Count > 0)
     {
         _selectedValue = _values[0];
     }
 }
Exemplo n.º 8
0
        public RelevantFeatureViewModel(SymbolicFeature feature, int weight, bool vowel, bool consonant, IReadOnlyDictionary<FeatureSymbol, int> valueMetrics)
        {
            _feature = feature;
            _weight = weight;
            _vowel = vowel;
            _consonant = consonant;

            var values = new List<RelevantValueViewModel>();
            foreach (FeatureSymbol symbol in feature.PossibleSymbols)
            {
                var vm = new RelevantValueViewModel(symbol, valueMetrics[symbol]);
                vm.PropertyChanged += ChildPropertyChanged;
                values.Add(vm);
            }
            _values = new ReadOnlyList<RelevantValueViewModel>(values);
        }
Exemplo n.º 9
0
        public RelevantFeatureViewModel(SymbolicFeature feature, int weight, bool vowel, bool consonant, IReadOnlyDictionary <FeatureSymbol, int> valueMetrics)
        {
            _feature   = feature;
            _weight    = weight;
            _vowel     = vowel;
            _consonant = consonant;

            var values = new List <RelevantValueViewModel>();

            foreach (FeatureSymbol symbol in feature.PossibleSymbols)
            {
                var vm = new RelevantValueViewModel(symbol, valueMetrics[symbol]);
                vm.PropertyChanged += ChildPropertyChanged;
                values.Add(vm);
            }
            _values = new ReadOnlyList <RelevantValueViewModel>(values);
        }
Exemplo n.º 10
0
        static HCFeatureSystem()
        {
            Anchor = new FeatureSymbol(Guid.NewGuid().ToString()) { Description = "anchor" };
            Segment = new FeatureSymbol(Guid.NewGuid().ToString()) { Description = "segment" };
            Boundary = new FeatureSymbol(Guid.NewGuid().ToString()) { Description = "boundary" };
            Morph = new FeatureSymbol(Guid.NewGuid().ToString()) { Description = "morph" };

            Type = new SymbolicFeature(Guid.NewGuid().ToString(), Anchor, Segment, Boundary, Morph) { Description = "Type" };

            Dirty = new FeatureSymbol(Guid.NewGuid().ToString()) { Description = "Dirty" };
            Clean = new FeatureSymbol(Guid.NewGuid().ToString()) { Description = "Clean" };

            Modified = new SymbolicFeature(Guid.NewGuid().ToString(), Dirty, Clean)
                {
                    Description = "Modified",
                    DefaultValue = new SymbolicFeatureValue(Clean)
                };

            Deleted = new FeatureSymbol(Guid.NewGuid().ToString()) {Description = "Deleted"};
            NotDeleted = new FeatureSymbol(Guid.NewGuid().ToString()) {Description = "NotDeleted"};

            Deletion = new SymbolicFeature(Guid.NewGuid().ToString(), Deleted, NotDeleted)
                {
                    Description = "Deletion",
                    DefaultValue = new SymbolicFeatureValue(NotDeleted)
                };

            LeftSide = new FeatureSymbol(Guid.NewGuid().ToString()) { Description = "LeftSide" };
            RightSide = new FeatureSymbol(Guid.NewGuid().ToString()) { Description = "RightSide" };

            AnchorType = new SymbolicFeature(Guid.NewGuid().ToString(), LeftSide, RightSide) { Description = "AnchorType" };

            StrRep = new StringFeature(Guid.NewGuid().ToString()) {Description = "StrRep"};

            Allomorph = new StringFeature(Guid.NewGuid().ToString()) {Description = "Allomorph"};

            Instance = new HCFeatureSystem();

            LeftSideAnchor = FeatureStruct.New().Symbol(Anchor).Symbol(LeftSide).Value;
            RightSideAnchor = FeatureStruct.New().Symbol(Anchor).Symbol(RightSide).Value;
        }
Exemplo n.º 11
0
 public FeatureViewModel(SymbolicFeature feature)
     : this(feature, null)
 {
 }
Exemplo n.º 12
0
 public SymbolicFeature AddPartsOfSpeech(IEnumerable<FeatureSymbol> pos)
 {
     var posFeature = new SymbolicFeature(PartOfSpeechID, pos) {Description = "POS"};
     base.Add(posFeature);
     return posFeature;
 }
Exemplo n.º 13
0
 public FeatureViewModel(SymbolicFeature feature)
     : this(feature, null)
 {
 }
Exemplo n.º 14
0
        static HCFeatureSystem()
        {
            Anchor = new FeatureSymbol(Guid.NewGuid().ToString())
            {
                Description = "anchor"
            };
            Segment = new FeatureSymbol(Guid.NewGuid().ToString())
            {
                Description = "segment"
            };
            Boundary = new FeatureSymbol(Guid.NewGuid().ToString())
            {
                Description = "boundary"
            };
            Morph = new FeatureSymbol(Guid.NewGuid().ToString())
            {
                Description = "morph"
            };

            Type = new SymbolicFeature(Guid.NewGuid().ToString(), Anchor, Segment, Boundary, Morph)
            {
                Description = "Type"
            };

            Dirty = new FeatureSymbol(Guid.NewGuid().ToString())
            {
                Description = "Dirty"
            };
            Clean = new FeatureSymbol(Guid.NewGuid().ToString())
            {
                Description = "Clean"
            };

            Modified = new SymbolicFeature(Guid.NewGuid().ToString(), Dirty, Clean)
            {
                Description  = "Modified",
                DefaultValue = new SymbolicFeatureValue(Clean)
            };

            Deleted = new FeatureSymbol(Guid.NewGuid().ToString())
            {
                Description = "Deleted"
            };
            NotDeleted = new FeatureSymbol(Guid.NewGuid().ToString())
            {
                Description = "NotDeleted"
            };

            Deletion = new SymbolicFeature(Guid.NewGuid().ToString(), Deleted, NotDeleted)
            {
                Description  = "Deletion",
                DefaultValue = new SymbolicFeatureValue(NotDeleted)
            };

            LeftSide = new FeatureSymbol(Guid.NewGuid().ToString())
            {
                Description = "LeftSide"
            };
            RightSide = new FeatureSymbol(Guid.NewGuid().ToString())
            {
                Description = "RightSide"
            };

            AnchorType = new SymbolicFeature(Guid.NewGuid().ToString(), LeftSide, RightSide)
            {
                Description = "AnchorType"
            };

            StrRep = new StringFeature(Guid.NewGuid().ToString())
            {
                Description = "StrRep"
            };

            Allomorph = new StringFeature(Guid.NewGuid().ToString())
            {
                Description = "Allomorph"
            };

            Instance = new HCFeatureSystem();

            LeftSideAnchor  = FeatureStruct.New().Symbol(Anchor).Symbol(LeftSide).Value;
            RightSideAnchor = FeatureStruct.New().Symbol(Anchor).Symbol(RightSide).Value;
        }
Exemplo n.º 15
0
        public virtual void FixtureSetUp()
        {
            SpanFactory = new IntegerSpanFactory();

            PhoneticFeatSys = new FeatureSystem
            {
                new SymbolicFeature("son", new FeatureSymbol("son+", "+"), new FeatureSymbol("son-", "-"), new FeatureSymbol("son?", "?"))
                {
                    DefaultSymbolID = "son?"
                },
                new SymbolicFeature("syl", new FeatureSymbol("syl+", "+"), new FeatureSymbol("syl-", "-"), new FeatureSymbol("syl?", "?"))
                {
                    DefaultSymbolID = "syl?"
                },
                new SymbolicFeature("cons", new FeatureSymbol("cons+", "+"), new FeatureSymbol("cons-", "-"), new FeatureSymbol("cons?", "?"))
                {
                    DefaultSymbolID = "cons?"
                },
                new SymbolicFeature("high", new FeatureSymbol("high+", "+"), new FeatureSymbol("high-", "-"), new FeatureSymbol("high?", "?"))
                {
                    DefaultSymbolID = "high?"
                },
                new SymbolicFeature("back", new FeatureSymbol("back+", "+"), new FeatureSymbol("back-", "-"), new FeatureSymbol("back?", "?"))
                {
                    DefaultSymbolID = "back?"
                },
                new SymbolicFeature("front", new FeatureSymbol("front+", "+"), new FeatureSymbol("front-", "-"), new FeatureSymbol("front?", "?"))
                {
                    DefaultSymbolID = "front?"
                },
                new SymbolicFeature("low", new FeatureSymbol("low+", "+"), new FeatureSymbol("low-", "-"), new FeatureSymbol("low?", "?"))
                {
                    DefaultSymbolID = "low?"
                },
                new SymbolicFeature("rnd", new FeatureSymbol("rnd+", "+"), new FeatureSymbol("rnd-", "-"), new FeatureSymbol("rnd?", "?"))
                {
                    DefaultSymbolID = "rnd?"
                },
                new SymbolicFeature("ant", new FeatureSymbol("ant+", "+"), new FeatureSymbol("ant-", "-"), new FeatureSymbol("ant?", "?"))
                {
                    DefaultSymbolID = "ant?"
                },
                new SymbolicFeature("cor", new FeatureSymbol("cor+", "+"), new FeatureSymbol("cor-", "-"), new FeatureSymbol("cor?", "?"))
                {
                    DefaultSymbolID = "cor?"
                },
                new SymbolicFeature("voice", new FeatureSymbol("voice+", "+"), new FeatureSymbol("voice-", "-"), new FeatureSymbol("voice?", "?"))
                {
                    DefaultSymbolID = "voice?"
                },
                new SymbolicFeature("cont", new FeatureSymbol("cont+", "+"), new FeatureSymbol("cont-", "-"), new FeatureSymbol("cont?", "?"))
                {
                    DefaultSymbolID = "cont?"
                },
                new SymbolicFeature("nas", new FeatureSymbol("nas+", "+"), new FeatureSymbol("nas-", "-"), new FeatureSymbol("nas?", "?"))
                {
                    DefaultSymbolID = "nas?"
                },
                new SymbolicFeature("str", new FeatureSymbol("str+", "+"), new FeatureSymbol("str-", "-"), new FeatureSymbol("str?", "?"))
                {
                    DefaultSymbolID = "str?"
                },
                new StringFeature("strRep")
            };

            WordFeatSys = new FeatureSystem
            {
                new SymbolicFeature("POS", new FeatureSymbol("noun"), new FeatureSymbol("verb"), new FeatureSymbol("adj"), new FeatureSymbol("adv"), new FeatureSymbol("det"))
            };

            Word = new FeatureSymbol("Word");
            NP   = new FeatureSymbol("NP");
            VP   = new FeatureSymbol("VP");
            Seg  = new FeatureSymbol("Seg");
            Bdry = new FeatureSymbol("Bdry");
            Allo = new FeatureSymbol("Allo");

            Type = new SymbolicFeature("Type", Word, NP, VP, Seg, Bdry, Allo);

            TypeFeatSys = new FeatureSystem {
                Type
            };

            Characters = new Dictionary <char, FeatureStruct>
            {
                { 'b', FeatureStruct.New(PhoneticFeatSys)
                  .Symbol(Seg)
                  .Symbol("son-")
                  .Symbol("syl-")
                  .Symbol("cons+")
                  .Symbol("high-")
                  .Symbol("ant+")
                  .Symbol("cor-")
                  .Symbol("voice+")
                  .Symbol("cont-")
                  .Symbol("nas-")
                  .Symbol("str-").Value },
                { 'd', FeatureStruct.New(PhoneticFeatSys)
                  .Symbol(Seg)
                  .Symbol("son-")
                  .Symbol("syl-")
                  .Symbol("cons+")
                  .Symbol("high-")
                  .Symbol("ant+")
                  .Symbol("cor+")
                  .Symbol("voice+")
                  .Symbol("cont-")
                  .Symbol("nas-")
                  .Symbol("str-").Value },
                { 'g', FeatureStruct.New(PhoneticFeatSys)
                  .Symbol(Seg)
                  .Symbol("son-")
                  .Symbol("syl-")
                  .Symbol("cons+")
                  .Symbol("high+")
                  .Symbol("ant-")
                  .Symbol("cor-")
                  .Symbol("voice+")
                  .Symbol("cont-")
                  .Symbol("nas-")
                  .Symbol("str-").Value },
                { 'p', FeatureStruct.New(PhoneticFeatSys)
                  .Symbol(Seg)
                  .Symbol("son-")
                  .Symbol("syl-")
                  .Symbol("cons+")
                  .Symbol("high-")
                  .Symbol("ant+")
                  .Symbol("cor-")
                  .Symbol("voice-")
                  .Symbol("cont-")
                  .Symbol("nas-")
                  .Symbol("str-").Value },
                { 't', FeatureStruct.New(PhoneticFeatSys)
                  .Symbol(Seg)
                  .Symbol("son-")
                  .Symbol("syl-")
                  .Symbol("cons+")
                  .Symbol("high-")
                  .Symbol("ant+")
                  .Symbol("cor+")
                  .Symbol("voice-")
                  .Symbol("cont-")
                  .Symbol("nas-")
                  .Symbol("str-").Value },
                { 'q', FeatureStruct.New(PhoneticFeatSys)
                  .Symbol(Seg)
                  .Symbol("son-")
                  .Symbol("syl-")
                  .Symbol("cons+")
                  .Symbol("high+")
                  .Symbol("ant-")
                  .Symbol("cor-")
                  .Symbol("voice-")
                  .Symbol("cont-")
                  .Symbol("nas-")
                  .Symbol("str-").Value },
                { 'c', FeatureStruct.New(PhoneticFeatSys)
                  .Symbol(Seg)
                  .Symbol("son-")
                  .Symbol("syl-")
                  .Symbol("cons+")
                  .Symbol("high+")
                  .Symbol("ant-")
                  .Symbol("cor-")
                  .Symbol("voice-")
                  .Symbol("cont-")
                  .Symbol("nas-")
                  .Symbol("str-").Value },
                { 'k', FeatureStruct.New(PhoneticFeatSys)
                  .Symbol(Seg)
                  .Symbol("son-")
                  .Symbol("syl-")
                  .Symbol("cons+")
                  .Symbol("high+")
                  .Symbol("ant-")
                  .Symbol("cor-")
                  .Symbol("voice-")
                  .Symbol("cont-")
                  .Symbol("nas-")
                  .Symbol("str-").Value },
                { 'x', FeatureStruct.New(PhoneticFeatSys)
                  .Symbol(Seg)
                  .Symbol("son-")
                  .Symbol("syl-")
                  .Symbol("cons+")
                  .Symbol("high+")
                  .Symbol("ant-")
                  .Symbol("cor-")
                  .Symbol("voice-")
                  .Symbol("cont-")
                  .Symbol("nas-")
                  .Symbol("str-").Value },
                { 'j', FeatureStruct.New(PhoneticFeatSys)
                  .Symbol(Seg)
                  .Symbol("son-")
                  .Symbol("syl-")
                  .Symbol("cons+")
                  .Symbol("high+")
                  .Symbol("ant-")
                  .Symbol("cor+")
                  .Symbol("voice+")
                  .Symbol("cont-")
                  .Symbol("nas-")
                  .Symbol("str+").Value },
                { 's', FeatureStruct.New(PhoneticFeatSys)
                  .Symbol(Seg)
                  .Symbol("son-")
                  .Symbol("syl-")
                  .Symbol("cons+")
                  .Symbol("high-")
                  .Symbol("ant+")
                  .Symbol("cor+")
                  .Symbol("voice-")
                  .Symbol("cont+")
                  .Symbol("nas-")
                  .Symbol("str+").Value },
                { 'z', FeatureStruct.New(PhoneticFeatSys)
                  .Symbol(Seg)
                  .Symbol("son-")
                  .Symbol("syl-")
                  .Symbol("cons+")
                  .Symbol("high-")
                  .Symbol("ant+")
                  .Symbol("cor+")
                  .Symbol("voice+")
                  .Symbol("cont+")
                  .Symbol("nas-")
                  .Symbol("str+").Value },
                { 'f', FeatureStruct.New(PhoneticFeatSys)
                  .Symbol(Seg)
                  .Symbol("son-")
                  .Symbol("syl-")
                  .Symbol("cons+")
                  .Symbol("high-")
                  .Symbol("ant+")
                  .Symbol("cor-")
                  .Symbol("voice-")
                  .Symbol("cont+")
                  .Symbol("nas-")
                  .Symbol("str+").Value },
                { 'v', FeatureStruct.New(PhoneticFeatSys)
                  .Symbol(Seg)
                  .Symbol("son-")
                  .Symbol("syl-")
                  .Symbol("cons+")
                  .Symbol("high-")
                  .Symbol("ant+")
                  .Symbol("cor-")
                  .Symbol("voice+")
                  .Symbol("cont+")
                  .Symbol("nas-")
                  .Symbol("str+").Value },
                { 'w', FeatureStruct.New(PhoneticFeatSys)
                  .Symbol(Seg)
                  .Symbol("son+")
                  .Symbol("syl-")
                  .Symbol("cons-")
                  .Symbol("high+")
                  .Symbol("back+")
                  .Symbol("front-")
                  .Symbol("low-")
                  .Symbol("rnd+")
                  .Symbol("ant-")
                  .Symbol("cor-").Value },
                { 'y', FeatureStruct.New(PhoneticFeatSys)
                  .Symbol(Seg)
                  .Symbol("son+")
                  .Symbol("syl-")
                  .Symbol("cons-")
                  .Symbol("high+")
                  .Symbol("back-")
                  .Symbol("front+")
                  .Symbol("low-")
                  .Symbol("rnd-")
                  .Symbol("ant-")
                  .Symbol("cor-").Value },
                { 'h', FeatureStruct.New(PhoneticFeatSys)
                  .Symbol(Seg)
                  .Symbol("son+")
                  .Symbol("syl-")
                  .Symbol("cons-")
                  .Symbol("high-")
                  .Symbol("back-")
                  .Symbol("front-")
                  .Symbol("low+")
                  .Symbol("ant-")
                  .Symbol("cor-")
                  .Symbol("voice-")
                  .Symbol("cont+")
                  .Symbol("nas-")
                  .Symbol("str-").Value },
                { 'r', FeatureStruct.New(PhoneticFeatSys)
                  .Symbol(Seg)
                  .Symbol("son+")
                  .Symbol("syl-")
                  .Symbol("cons+")
                  .Symbol("high-")
                  .Symbol("back-")
                  .Symbol("front-")
                  .Symbol("low-")
                  .Symbol("ant-")
                  .Symbol("cor+")
                  .Symbol("voice+")
                  .Symbol("cont+")
                  .Symbol("nas-")
                  .Symbol("str-").Value },
                { 'l', FeatureStruct.New(PhoneticFeatSys)
                  .Symbol(Seg)
                  .Symbol("son+")
                  .Symbol("syl-")
                  .Symbol("cons+")
                  .Symbol("high-")
                  .Symbol("back-")
                  .Symbol("front-")
                  .Symbol("low-")
                  .Symbol("ant+")
                  .Symbol("cor+")
                  .Symbol("voice+")
                  .Symbol("cont+")
                  .Symbol("nas-")
                  .Symbol("str-").Value },
                { 'm', FeatureStruct.New(PhoneticFeatSys)
                  .Symbol(Seg)
                  .Symbol("son+")
                  .Symbol("syl-")
                  .Symbol("cons+")
                  .Symbol("high-")
                  .Symbol("low-")
                  .Symbol("ant+")
                  .Symbol("cor-")
                  .Symbol("voice+")
                  .Symbol("cont-")
                  .Symbol("nas+")
                  .Symbol("str-").Value },
                { 'n', FeatureStruct.New(PhoneticFeatSys)
                  .Symbol(Seg)
                  .Symbol("son+")
                  .Symbol("syl-")
                  .Symbol("cons+")
                  .Symbol("high-")
                  .Symbol("low-")
                  .Symbol("ant+")
                  .Symbol("cor+")
                  .Symbol("voice+")
                  .Symbol("cont-")
                  .Symbol("nas+")
                  .Symbol("str-").Value },
                { 'N', FeatureStruct.New(PhoneticFeatSys)
                  .Symbol(Seg)
                  .Symbol("son+")
                  .Symbol("syl-")
                  .Symbol("cons+")
                  .Symbol("high-")
                  .Symbol("low-")
                  .Symbol("ant+")
                  .Symbol("cor?")
                  .Symbol("voice+")
                  .Symbol("cont-")
                  .Symbol("nas+")
                  .Symbol("str-").Value },
                { 'a', FeatureStruct.New(PhoneticFeatSys)
                  .Symbol(Seg)
                  .Symbol("son+")
                  .Symbol("syl+")
                  .Symbol("cons-")
                  .Symbol("high-")
                  .Symbol("back-")
                  .Symbol("front+")
                  .Symbol("low+")
                  .Symbol("rnd-").Value },
                { 'e', FeatureStruct.New(PhoneticFeatSys)
                  .Symbol(Seg)
                  .Symbol("son+")
                  .Symbol("syl+")
                  .Symbol("cons-")
                  .Symbol("high-")
                  .Symbol("back-")
                  .Symbol("front+")
                  .Symbol("low-")
                  .Symbol("rnd-").Value },
                { 'i', FeatureStruct.New(PhoneticFeatSys)
                  .Symbol(Seg)
                  .Symbol("son+")
                  .Symbol("syl+")
                  .Symbol("cons-")
                  .Symbol("high+")
                  .Symbol("back-")
                  .Symbol("front+")
                  .Symbol("low-")
                  .Symbol("rnd-").Value },
                { 'o', FeatureStruct.New(PhoneticFeatSys)
                  .Symbol(Seg)
                  .Symbol("son+")
                  .Symbol("syl+")
                  .Symbol("cons-")
                  .Symbol("high-")
                  .Symbol("back+")
                  .Symbol("front-")
                  .Symbol("low+")
                  .Symbol("rnd-").Value },
                { 'u', FeatureStruct.New(PhoneticFeatSys)
                  .Symbol(Seg)
                  .Symbol("son+")
                  .Symbol("syl+")
                  .Symbol("cons-")
                  .Symbol("high+")
                  .Symbol("back+")
                  .Symbol("front-")
                  .Symbol("low-")
                  .Symbol("rnd+").Value },
                { '+', FeatureStruct.New(PhoneticFeatSys)
                  .Symbol(Bdry)
                  .Feature("strRep").EqualTo("+").Value },
                { ',', FeatureStruct.New(PhoneticFeatSys)
                  .Symbol(Bdry)
                  .Feature("strRep").EqualTo(",").Value },
                { ' ', FeatureStruct.New(PhoneticFeatSys)
                  .Symbol(Bdry)
                  .Feature("strRep").EqualTo(" ").Value },
                { '.', FeatureStruct.New(PhoneticFeatSys)
                  .Symbol(Bdry)
                  .Feature("strRep").EqualTo(".").Value }
            };
        }
Exemplo n.º 16
0
        public virtual void FixtureSetUp()
        {
            SpanFactory = new IntegerSpanFactory();

            PhoneticFeatSys = new FeatureSystem
            {
                new SymbolicFeature("son", new FeatureSymbol("son+", "+"), new FeatureSymbol("son-", "-"), new FeatureSymbol("son?", "?")) {DefaultSymbolID = "son?"},
                new SymbolicFeature("syl", new FeatureSymbol("syl+", "+"), new FeatureSymbol("syl-", "-"), new FeatureSymbol("syl?", "?")) {DefaultSymbolID = "syl?"},
                new SymbolicFeature("cons", new FeatureSymbol("cons+", "+"), new FeatureSymbol("cons-", "-"), new FeatureSymbol("cons?", "?")) {DefaultSymbolID = "cons?"},
                new SymbolicFeature("high", new FeatureSymbol("high+", "+"), new FeatureSymbol("high-", "-"), new FeatureSymbol("high?", "?")) {DefaultSymbolID = "high?"},
                new SymbolicFeature("back", new FeatureSymbol("back+", "+"), new FeatureSymbol("back-", "-"), new FeatureSymbol("back?", "?")) {DefaultSymbolID = "back?"},
                new SymbolicFeature("front", new FeatureSymbol("front+", "+"), new FeatureSymbol("front-", "-"), new FeatureSymbol("front?", "?")) {DefaultSymbolID = "front?"},
                new SymbolicFeature("low", new FeatureSymbol("low+", "+"), new FeatureSymbol("low-", "-"), new FeatureSymbol("low?", "?")) {DefaultSymbolID = "low?"},
                new SymbolicFeature("rnd", new FeatureSymbol("rnd+", "+"), new FeatureSymbol("rnd-", "-"), new FeatureSymbol("rnd?", "?")) {DefaultSymbolID = "rnd?"},
                new SymbolicFeature("ant", new FeatureSymbol("ant+", "+"), new FeatureSymbol("ant-", "-"), new FeatureSymbol("ant?", "?")) {DefaultSymbolID = "ant?"},
                new SymbolicFeature("cor", new FeatureSymbol("cor+", "+"), new FeatureSymbol("cor-", "-"), new FeatureSymbol("cor?", "?")) {DefaultSymbolID = "cor?"},
                new SymbolicFeature("voice", new FeatureSymbol("voice+", "+"), new FeatureSymbol("voice-", "-"), new FeatureSymbol("voice?", "?")) {DefaultSymbolID = "voice?"},
                new SymbolicFeature("cont", new FeatureSymbol("cont+", "+"), new FeatureSymbol("cont-", "-"), new FeatureSymbol("cont?", "?")) {DefaultSymbolID = "cont?"},
                new SymbolicFeature("nas", new FeatureSymbol("nas+", "+"), new FeatureSymbol("nas-", "-"), new FeatureSymbol("nas?", "?")) {DefaultSymbolID = "nas?"},
                new SymbolicFeature("str", new FeatureSymbol("str+", "+"), new FeatureSymbol("str-", "-"), new FeatureSymbol("str?", "?")) {DefaultSymbolID = "str?"},
                new StringFeature("strRep")
            };

            WordFeatSys = new FeatureSystem
            {
                new SymbolicFeature("POS", new FeatureSymbol("noun"), new FeatureSymbol("verb"), new FeatureSymbol("adj"), new FeatureSymbol("adv"), new FeatureSymbol("det"))
            };

            Word = new FeatureSymbol("Word");
            NP = new FeatureSymbol("NP");
            VP = new FeatureSymbol("VP");
            Seg = new FeatureSymbol("Seg");
            Bdry = new FeatureSymbol("Bdry");
            Allo = new FeatureSymbol("Allo");

            Type = new SymbolicFeature("Type", Word, NP, VP, Seg, Bdry, Allo);

            TypeFeatSys = new FeatureSystem {Type};

            Characters = new Dictionary<char, FeatureStruct>
            {
                {'b', FeatureStruct.New(PhoneticFeatSys)
                        .Symbol(Seg)
                        .Symbol("son-")
                        .Symbol("syl-")
                        .Symbol("cons+")
                        .Symbol("high-")
                        .Symbol("ant+")
                        .Symbol("cor-")
                        .Symbol("voice+")
                        .Symbol("cont-")
                        .Symbol("nas-")
                        .Symbol("str-").Value},
                {'d', FeatureStruct.New(PhoneticFeatSys)
                        .Symbol(Seg)
                        .Symbol("son-")
                        .Symbol("syl-")
                        .Symbol("cons+")
                        .Symbol("high-")
                        .Symbol("ant+")
                        .Symbol("cor+")
                        .Symbol("voice+")
                        .Symbol("cont-")
                        .Symbol("nas-")
                        .Symbol("str-").Value},
                {'g', FeatureStruct.New(PhoneticFeatSys)
                        .Symbol(Seg)
                        .Symbol("son-")
                        .Symbol("syl-")
                        .Symbol("cons+")
                        .Symbol("high+")
                        .Symbol("ant-")
                        .Symbol("cor-")
                        .Symbol("voice+")
                        .Symbol("cont-")
                        .Symbol("nas-")
                        .Symbol("str-").Value},
                {'p', FeatureStruct.New(PhoneticFeatSys)
                        .Symbol(Seg)
                        .Symbol("son-")
                        .Symbol("syl-")
                        .Symbol("cons+")
                        .Symbol("high-")
                        .Symbol("ant+")
                        .Symbol("cor-")
                        .Symbol("voice-")
                        .Symbol("cont-")
                        .Symbol("nas-")
                        .Symbol("str-").Value},
                {'t', FeatureStruct.New(PhoneticFeatSys)
                        .Symbol(Seg)
                        .Symbol("son-")
                        .Symbol("syl-")
                        .Symbol("cons+")
                        .Symbol("high-")
                        .Symbol("ant+")
                        .Symbol("cor+")
                        .Symbol("voice-")
                        .Symbol("cont-")
                        .Symbol("nas-")
                        .Symbol("str-").Value},
                {'q', FeatureStruct.New(PhoneticFeatSys)
                        .Symbol(Seg)
                        .Symbol("son-")
                        .Symbol("syl-")
                        .Symbol("cons+")
                        .Symbol("high+")
                        .Symbol("ant-")
                        .Symbol("cor-")
                        .Symbol("voice-")
                        .Symbol("cont-")
                        .Symbol("nas-")
                        .Symbol("str-").Value},
                {'c', FeatureStruct.New(PhoneticFeatSys)
                        .Symbol(Seg)
                        .Symbol("son-")
                        .Symbol("syl-")
                        .Symbol("cons+")
                        .Symbol("high+")
                        .Symbol("ant-")
                        .Symbol("cor-")
                        .Symbol("voice-")
                        .Symbol("cont-")
                        .Symbol("nas-")
                        .Symbol("str-").Value},
                {'k', FeatureStruct.New(PhoneticFeatSys)
                        .Symbol(Seg)
                        .Symbol("son-")
                        .Symbol("syl-")
                        .Symbol("cons+")
                        .Symbol("high+")
                        .Symbol("ant-")
                        .Symbol("cor-")
                        .Symbol("voice-")
                        .Symbol("cont-")
                        .Symbol("nas-")
                        .Symbol("str-").Value},
                {'x', FeatureStruct.New(PhoneticFeatSys)
                        .Symbol(Seg)
                        .Symbol("son-")
                        .Symbol("syl-")
                        .Symbol("cons+")
                        .Symbol("high+")
                        .Symbol("ant-")
                        .Symbol("cor-")
                        .Symbol("voice-")
                        .Symbol("cont-")
                        .Symbol("nas-")
                        .Symbol("str-").Value},
                {'j', FeatureStruct.New(PhoneticFeatSys)
                        .Symbol(Seg)
                        .Symbol("son-")
                        .Symbol("syl-")
                        .Symbol("cons+")
                        .Symbol("high+")
                        .Symbol("ant-")
                        .Symbol("cor+")
                        .Symbol("voice+")
                        .Symbol("cont-")
                        .Symbol("nas-")
                        .Symbol("str+").Value},
                {'s', FeatureStruct.New(PhoneticFeatSys)
                        .Symbol(Seg)
                        .Symbol("son-")
                        .Symbol("syl-")
                        .Symbol("cons+")
                        .Symbol("high-")
                        .Symbol("ant+")
                        .Symbol("cor+")
                        .Symbol("voice-")
                        .Symbol("cont+")
                        .Symbol("nas-")
                        .Symbol("str+").Value},
                {'z', FeatureStruct.New(PhoneticFeatSys)
                        .Symbol(Seg)
                        .Symbol("son-")
                        .Symbol("syl-")
                        .Symbol("cons+")
                        .Symbol("high-")
                        .Symbol("ant+")
                        .Symbol("cor+")
                        .Symbol("voice+")
                        .Symbol("cont+")
                        .Symbol("nas-")
                        .Symbol("str+").Value},
                {'f', FeatureStruct.New(PhoneticFeatSys)
                        .Symbol(Seg)
                        .Symbol("son-")
                        .Symbol("syl-")
                        .Symbol("cons+")
                        .Symbol("high-")
                        .Symbol("ant+")
                        .Symbol("cor-")
                        .Symbol("voice-")
                        .Symbol("cont+")
                        .Symbol("nas-")
                        .Symbol("str+").Value},
                {'v', FeatureStruct.New(PhoneticFeatSys)
                        .Symbol(Seg)
                        .Symbol("son-")
                        .Symbol("syl-")
                        .Symbol("cons+")
                        .Symbol("high-")
                        .Symbol("ant+")
                        .Symbol("cor-")
                        .Symbol("voice+")
                        .Symbol("cont+")
                        .Symbol("nas-")
                        .Symbol("str+").Value},
                {'w', FeatureStruct.New(PhoneticFeatSys)
                        .Symbol(Seg)
                        .Symbol("son+")
                        .Symbol("syl-")
                        .Symbol("cons-")
                        .Symbol("high+")
                        .Symbol("back+")
                        .Symbol("front-")
                        .Symbol("low-")
                        .Symbol("rnd+")
                        .Symbol("ant-")
                        .Symbol("cor-").Value},
                {'y', FeatureStruct.New(PhoneticFeatSys)
                        .Symbol(Seg)
                        .Symbol("son+")
                        .Symbol("syl-")
                        .Symbol("cons-")
                        .Symbol("high+")
                        .Symbol("back-")
                        .Symbol("front+")
                        .Symbol("low-")
                        .Symbol("rnd-")
                        .Symbol("ant-")
                        .Symbol("cor-").Value},
                {'h', FeatureStruct.New(PhoneticFeatSys)
                        .Symbol(Seg)
                        .Symbol("son+")
                        .Symbol("syl-")
                        .Symbol("cons-")
                        .Symbol("high-")
                        .Symbol("back-")
                        .Symbol("front-")
                        .Symbol("low+")
                        .Symbol("ant-")
                        .Symbol("cor-")
                        .Symbol("voice-")
                        .Symbol("cont+")
                        .Symbol("nas-")
                        .Symbol("str-").Value},
                {'r', FeatureStruct.New(PhoneticFeatSys)
                        .Symbol(Seg)
                        .Symbol("son+")
                        .Symbol("syl-")
                        .Symbol("cons+")
                        .Symbol("high-")
                        .Symbol("back-")
                        .Symbol("front-")
                        .Symbol("low-")
                        .Symbol("ant-")
                        .Symbol("cor+")
                        .Symbol("voice+")
                        .Symbol("cont+")
                        .Symbol("nas-")
                        .Symbol("str-").Value},
                {'l', FeatureStruct.New(PhoneticFeatSys)
                        .Symbol(Seg)
                        .Symbol("son+")
                        .Symbol("syl-")
                        .Symbol("cons+")
                        .Symbol("high-")
                        .Symbol("back-")
                        .Symbol("front-")
                        .Symbol("low-")
                        .Symbol("ant+")
                        .Symbol("cor+")
                        .Symbol("voice+")
                        .Symbol("cont+")
                        .Symbol("nas-")
                        .Symbol("str-").Value},
                {'m', FeatureStruct.New(PhoneticFeatSys)
                        .Symbol(Seg)
                        .Symbol("son+")
                        .Symbol("syl-")
                        .Symbol("cons+")
                        .Symbol("high-")
                        .Symbol("low-")
                        .Symbol("ant+")
                        .Symbol("cor-")
                        .Symbol("voice+")
                        .Symbol("cont-")
                        .Symbol("nas+")
                        .Symbol("str-").Value},
                {'n', FeatureStruct.New(PhoneticFeatSys)
                        .Symbol(Seg)
                        .Symbol("son+")
                        .Symbol("syl-")
                        .Symbol("cons+")
                        .Symbol("high-")
                        .Symbol("low-")
                        .Symbol("ant+")
                        .Symbol("cor+")
                        .Symbol("voice+")
                        .Symbol("cont-")
                        .Symbol("nas+")
                        .Symbol("str-").Value},
                {'N', FeatureStruct.New(PhoneticFeatSys)
                        .Symbol(Seg)
                        .Symbol("son+")
                        .Symbol("syl-")
                        .Symbol("cons+")
                        .Symbol("high-")
                        .Symbol("low-")
                        .Symbol("ant+")
                        .Symbol("cor?")
                        .Symbol("voice+")
                        .Symbol("cont-")
                        .Symbol("nas+")
                        .Symbol("str-").Value},
                {'a', FeatureStruct.New(PhoneticFeatSys)
                        .Symbol(Seg)
                        .Symbol("son+")
                        .Symbol("syl+")
                        .Symbol("cons-")
                        .Symbol("high-")
                        .Symbol("back-")
                        .Symbol("front+")
                        .Symbol("low+")
                        .Symbol("rnd-").Value},
                {'e', FeatureStruct.New(PhoneticFeatSys)
                        .Symbol(Seg)
                        .Symbol("son+")
                        .Symbol("syl+")
                        .Symbol("cons-")
                        .Symbol("high-")
                        .Symbol("back-")
                        .Symbol("front+")
                        .Symbol("low-")
                        .Symbol("rnd-").Value},
                {'i', FeatureStruct.New(PhoneticFeatSys)
                        .Symbol(Seg)
                        .Symbol("son+")
                        .Symbol("syl+")
                        .Symbol("cons-")
                        .Symbol("high+")
                        .Symbol("back-")
                        .Symbol("front+")
                        .Symbol("low-")
                        .Symbol("rnd-").Value},
                {'o', FeatureStruct.New(PhoneticFeatSys)
                        .Symbol(Seg)
                        .Symbol("son+")
                        .Symbol("syl+")
                        .Symbol("cons-")
                        .Symbol("high-")
                        .Symbol("back+")
                        .Symbol("front-")
                        .Symbol("low+")
                        .Symbol("rnd-").Value},
                {'u', FeatureStruct.New(PhoneticFeatSys)
                        .Symbol(Seg)
                        .Symbol("son+")
                        .Symbol("syl+")
                        .Symbol("cons-")
                        .Symbol("high+")
                        .Symbol("back+")
                        .Symbol("front-")
                        .Symbol("low-")
                        .Symbol("rnd+").Value},
                {'+', FeatureStruct.New(PhoneticFeatSys)
                        .Symbol(Bdry)
                        .Feature("strRep").EqualTo("+").Value},
                {',', FeatureStruct.New(PhoneticFeatSys)
                        .Symbol(Bdry)
                        .Feature("strRep").EqualTo(",").Value},
                {' ', FeatureStruct.New(PhoneticFeatSys)
                        .Symbol(Bdry)
                        .Feature("strRep").EqualTo(" ").Value},
                {'.', FeatureStruct.New(PhoneticFeatSys)
                        .Symbol(Bdry)
                        .Feature("strRep").EqualTo(".").Value}
            };
        }
Exemplo n.º 17
0
        private static CogProject LoadProject(SpanFactory <ShapeNode> spanFactory, SegmentPool segmentPool, XDocument doc)
        {
            var project = new CogProject(spanFactory);

            XElement root = doc.Root;

            Debug.Assert(root != null);
            if (root.GetDefaultNamespace() != DefaultNamespace)
            {
                throw new ConfigException("The specified file is not a valid Cog config file");
            }
            doc.Validate(Schema, (sender, args) =>
            {
                switch (args.Severity)
                {
                case XmlSeverityType.Error:
                    throw new ConfigException("The specified file is not a valid Cog config file", args.Exception);
                }
            });
            segmentPool.Reset();
            project.Version = (int)root.Attribute("version");
            var      featSys     = new FeatureSystem();
            XElement featSysElem = root.Element(Cog + "FeatureSystem");

            Debug.Assert(featSysElem != null);
            foreach (XElement featureElem in featSysElem.Elements(Cog + "Feature"))
            {
                var feat = new SymbolicFeature((string)featureElem.Attribute("id"), featureElem.Elements(Cog + "Value")
                                               .Select(e => new FeatureSymbol((string)e.Attribute("id"), (string)e.Attribute("name"))))
                {
                    Description = (string)featureElem.Attribute("name")
                };
                featSys.Add(feat);
            }
            featSys.Freeze();
            project.FeatureSystem = featSys;

            XElement segmentationElem = root.Element(Cog + "Segmentation");

            Debug.Assert(segmentationElem != null);
            XElement vowelsElem = segmentationElem.Element(Cog + "Vowels");

            if (vowelsElem != null)
            {
                XAttribute maxLenAttr = vowelsElem.Attribute("maxLength");
                if (maxLenAttr != null)
                {
                    project.Segmenter.MaxVowelLength = (int)maxLenAttr;
                }

                ParseSymbols(project.FeatureSystem, vowelsElem, project.Segmenter.Vowels);
            }

            XElement consElem = segmentationElem.Element(Cog + "Consonants");

            if (consElem != null)
            {
                XAttribute maxLenAttr = consElem.Attribute("maxLength");
                if (maxLenAttr != null)
                {
                    project.Segmenter.MaxConsonantLength = (int)maxLenAttr;
                }

                ParseSymbols(project.FeatureSystem, consElem, project.Segmenter.Consonants);
            }

            XElement modsElem = segmentationElem.Element(Cog + "Modifiers");

            if (modsElem != null)
            {
                ParseSymbols(project.FeatureSystem, modsElem, project.Segmenter.Modifiers);
            }

            XElement bdrysElem = segmentationElem.Element(Cog + "Boundaries");

            if (bdrysElem != null)
            {
                ParseSymbols(project.FeatureSystem, bdrysElem, project.Segmenter.Boundaries);
            }

            XElement tonesElem = segmentationElem.Element(Cog + "ToneLetters");

            if (tonesElem != null)
            {
                ParseSymbols(project.FeatureSystem, tonesElem, project.Segmenter.ToneLetters);
            }

            XElement joinersElem = segmentationElem.Element(Cog + "Joiners");

            if (joinersElem != null)
            {
                ParseSymbols(project.FeatureSystem, joinersElem, project.Segmenter.Joiners);
            }

            XElement alignersElem = root.Element(Cog + "WordAligners");

            Debug.Assert(alignersElem != null);
            foreach (XElement alignerElem in alignersElem.Elements(Cog + "WordAligner"))
            {
                LoadComponent(spanFactory, segmentPool, project, alignerElem, project.WordAligners);
            }

            XElement cognateIdentifiersElem = root.Element(Cog + "CognateIdentifiers");

            Debug.Assert(cognateIdentifiersElem != null);
            foreach (XElement cognateIdentifierElem in cognateIdentifiersElem.Elements(Cog + "CognateIdentifier"))
            {
                LoadComponent(spanFactory, segmentPool, project, cognateIdentifierElem, project.CognateIdentifiers);
            }

            var      meanings     = new Dictionary <string, Meaning>();
            XElement meaningsElem = root.Element(Cog + "Meanings");

            Debug.Assert(meaningsElem != null);
            foreach (XElement meaningElem in meaningsElem.Elements(Cog + "Meaning"))
            {
                var meaning = new Meaning((string)meaningElem.Attribute("gloss"), (string)meaningElem.Attribute("category"));
                meanings[(string)meaningElem.Attribute("id")] = meaning;
                project.Meanings.Add(meaning);
            }

            XElement varietiesElem = root.Element(Cog + "Varieties");

            Debug.Assert(varietiesElem != null);
            foreach (XElement varietyElem in varietiesElem.Elements(Cog + "Variety"))
            {
                var      variety   = new Variety((string)varietyElem.Attribute("name"));
                XElement wordsElem = varietyElem.Element(Cog + "Words");
                if (wordsElem != null)
                {
                    foreach (XElement wordElem in wordsElem.Elements(Cog + "Word"))
                    {
                        Meaning meaning;
                        if (meanings.TryGetValue((string)wordElem.Attribute("meaning"), out meaning))
                        {
                            var strRep    = ((string)wordElem).Trim();
                            var stemIndex = (int?)wordElem.Attribute("stemIndex") ?? 0;
                            var stemLen   = (int?)wordElem.Attribute("stemLength") ?? strRep.Length - stemIndex;
                            variety.Words.Add(new Word(strRep, stemIndex, stemLen, meaning));
                        }
                    }
                }
                XElement affixesElem = varietyElem.Element(Cog + "Affixes");
                if (affixesElem != null)
                {
                    foreach (XElement affixElem in affixesElem.Elements(Cog + "Affix"))
                    {
                        var type = AffixType.Prefix;
                        switch ((string)affixElem.Attribute("type"))
                        {
                        case "prefix":
                            type = AffixType.Prefix;
                            break;

                        case "suffix":
                            type = AffixType.Suffix;
                            break;
                        }

                        var affixStr = ((string)affixElem).Trim();
                        variety.Affixes.Add(new Affix(affixStr, type, (string)affixElem.Attribute("category")));
                    }
                }
                XElement regionsElem = varietyElem.Element(Cog + "Regions");
                if (regionsElem != null)
                {
                    foreach (XElement regionElem in regionsElem.Elements(Cog + "Region"))
                    {
                        var region = new GeographicRegion {
                            Description = (string)regionElem.Element(Cog + "Description")
                        };
                        foreach (XElement coordinateElem in regionElem.Elements(Cog + "Coordinates").Elements(Cog + "Coordinate"))
                        {
                            var latitude  = (double)coordinateElem.Element(Cog + "Latitude");
                            var longitude = (double)coordinateElem.Element(Cog + "Longitude");
                            region.Coordinates.Add(new GeographicCoordinate(latitude, longitude));
                        }
                        variety.Regions.Add(region);
                    }
                }
                project.Varieties.Add(variety);
            }

            XElement projectProcessorsElem = root.Element(Cog + "ProjectProcessors");

            Debug.Assert(projectProcessorsElem != null);
            foreach (XElement projectProcessorElem in projectProcessorsElem.Elements(Cog + "ProjectProcessor"))
            {
                LoadComponent(spanFactory, segmentPool, project, projectProcessorElem, project.ProjectProcessors);
            }

            XElement varietyProcessorsElem = root.Element(Cog + "VarietyProcessors");

            Debug.Assert(varietyProcessorsElem != null);
            foreach (XElement varietyProcessorElem in varietyProcessorsElem.Elements(Cog + "VarietyProcessor"))
            {
                LoadComponent(spanFactory, segmentPool, project, varietyProcessorElem, project.VarietyProcessors);
            }

            XElement varietyPairProcessorsElem = root.Element(Cog + "VarietyPairProcessors");

            Debug.Assert(varietyPairProcessorsElem != null);
            foreach (XElement varietyPairProcessorElem in varietyPairProcessorsElem.Elements(Cog + "VarietyPairProcessor"))
            {
                LoadComponent(spanFactory, segmentPool, project, varietyPairProcessorElem, project.VarietyPairProcessors);
            }

            return(project);
        }
Exemplo n.º 18
0
        private void LoadLanguage(XElement langElem)
        {
            _language = new Language { Name = (string) langElem.Element("Name") };

            IEnumerable<FeatureSymbol> posSymbols = langElem.Elements("PartsOfSpeech").Elements("PartOfSpeech")
                .Select(e => new FeatureSymbol((string) e.Attribute("id"), (string) e.Element("Name")));
            _posFeature = _language.SyntacticFeatureSystem.AddPartsOfSpeech(posSymbols);

            XElement phonFeatSysElem = langElem.Elements("PhonologicalFeatureSystem").SingleOrDefault(IsActive);
            if (phonFeatSysElem != null)
                LoadPhonologicalFeatureSystem(phonFeatSysElem);
            _language.PhonologicalFeatureSystem.Freeze();

            XElement headFeatsElem = langElem.Element("HeadFeatures");
            if (headFeatsElem != null)
            {
                _headFeature = _language.SyntacticFeatureSystem.AddHeadFeature();
                LoadSyntacticFeatureSystem(headFeatsElem, SyntacticFeatureType.Head);
            }
            XElement footFeatsElem = langElem.Element("FootFeatures");
            if (footFeatsElem != null)
            {
                _footFeature = _language.SyntacticFeatureSystem.AddFootFeature();
                LoadSyntacticFeatureSystem(footFeatsElem, SyntacticFeatureType.Foot);
            }
            _language.SyntacticFeatureSystem.Freeze();

            foreach (XElement mfElem in langElem.Elements("MorphologicalPhonologicalRuleFeatures").Elements("MorphologicalPhonologicalRuleFeature").Where(IsActive))
            {
                var mprFeature = new MprFeature {Name = (string) mfElem};
                _language.MprFeatures.Add(mprFeature);
                _mprFeatures[(string) mfElem.Attribute("id")] = mprFeature;
            }

            foreach (XElement mprFeatGroupElem in langElem.Elements("MorphologicalPhonologicalRuleFeatures").Elements("MorphologicalPhonologicalRuleFeatureGroup").Where(IsActive))
                LoadMprFeatGroup(mprFeatGroupElem);

            foreach (XElement stemNameElem in langElem.Elements("StemNames").Elements("StemName"))
                LoadStemName(stemNameElem);

            foreach (XElement charDefTableElem in langElem.Elements("CharacterDefinitionTable").Where(IsActive))
                LoadCharacterDefinitionTable(charDefTableElem);

            foreach (XElement natClassElem in langElem.Elements("NaturalClasses").Elements().Where(IsActive))
                LoadNaturalClass(natClassElem);

            foreach (XElement familyElem in langElem.Elements("Families").Elements("Family").Where(IsActive))
            {
                var family = new LexFamily {Name = (string) familyElem};
                _language.Families.Add(family);
                _families[(string) familyElem.Attribute("id")] = family;
            }

            foreach (XElement pruleElem in langElem.Elements("PhonologicalRuleDefinitions").Elements().Where(IsActive))
                LoadPhonologicalRule(pruleElem);

            foreach (XElement stratumElem in langElem.Elements("Strata").Elements("Stratum").Where(IsActive))
                LoadStratum(stratumElem);

            foreach (XElement coOccurElem in langElem.Elements("MorphemeCoOccurrenceRules").Elements("MorphemeCoOccurrenceRule").Where(IsActive))
                LoadMorphemeCoOccurrenceRule(coOccurElem);

            foreach (XElement coOccurElem in langElem.Elements("AllomorphCoOccurrenceRules").Elements("AllomorphCoOccurrenceRule").Where(IsActive))
                LoadAllomorphCoOccurrenceRule(coOccurElem);
        }
Exemplo n.º 19
0
        public void Migrate(SegmentPool segmentPool, CogProject project)
        {
            if (project.FeatureSystem.ContainsFeature("airstream"))
            {
                return;
            }

            var pulmonic  = new FeatureSymbol("pulmonic");
            var ejective  = new FeatureSymbol("ejective");
            var implosive = new FeatureSymbol("implosive");
            var click     = new FeatureSymbol("click");
            var airstream = new SymbolicFeature("airstream",
                                                pulmonic,
                                                ejective,
                                                implosive,
                                                click)
            {
                Description = "Airstream"
            };

            project.FeatureSystem.Add(airstream);

            AddValue(project.Segmenter.Modifiers, "ʼ", ejective);

            AddValue(project.Segmenter.Consonants, "ɓ", implosive);
            AddValue(project.Segmenter.Consonants, "ɗ", implosive);
            AddValue(project.Segmenter.Consonants, "ʄ", implosive);
            AddValue(project.Segmenter.Consonants, "ɠ", implosive);
            AddValue(project.Segmenter.Consonants, "ʛ", implosive);

            FeatureSymbol affricate;

            if (project.FeatureSystem.TryGetSymbol("affricate", out affricate))
            {
                project.Segmenter.Consonants.AddSymbolBasedOn("ʘ", "p", affricate, click);
                project.Segmenter.Consonants.AddSymbolBasedOn("ǀ", "θ", affricate, click);
                project.Segmenter.Consonants.AddSymbolBasedOn("ǁ", "ɬ", affricate, click);
            }
            project.Segmenter.Consonants.AddSymbolBasedOn("ǃ", "t", click);
            project.Segmenter.Consonants.AddSymbolBasedOn("ǂ", "c", click);

            foreach (Symbol symbol in project.Segmenter.Vowels.ToArray())
            {
                AddValue(project.Segmenter.Vowels, symbol, pulmonic);
            }

            foreach (Symbol symbol in project.Segmenter.Consonants.Where(s => !s.FeatureStruct.ContainsFeature("airstream")).ToArray())
            {
                AddValue(project.Segmenter.Consonants, symbol, pulmonic);
            }

            foreach (KeyValuePair <string, IWordAligner> aligner in project.WordAligners.Where(kvp => kvp.Value is Aline).ToArray())
            {
                var aline = (Aline)aligner.Value;
                Dictionary <SymbolicFeature, int> featWeights = aline.FeatureWeights.ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
                featWeights[airstream] = 5;
                Dictionary <FeatureSymbol, int> valueMetrics = aline.ValueMetrics.ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
                valueMetrics[pulmonic]            = 100;
                valueMetrics[ejective]            = 66;
                valueMetrics[implosive]           = 33;
                valueMetrics[click]               = 0;
                project.WordAligners[aligner.Key] = new Aline(segmentPool, aline.RelevantVowelFeatures, aline.RelevantConsonantFeatures.Concat(airstream),
                                                              featWeights, valueMetrics, aline.Settings);
            }
        }
Exemplo n.º 20
0
        static CogFeatureSystem()
        {
            AnchorType = new FeatureSymbol(Guid.NewGuid().ToString())
            {
                Description = "anchor"
            };
            VowelType = new FeatureSymbol(Guid.NewGuid().ToString())
            {
                Description = "vowel"
            };
            ConsonantType = new FeatureSymbol(Guid.NewGuid().ToString())
            {
                Description = "consonant"
            };
            ToneLetterType = new FeatureSymbol(Guid.NewGuid().ToString())
            {
                Description = "toneLetter"
            };
            BoundaryType = new FeatureSymbol(Guid.NewGuid().ToString())
            {
                Description = "boundary"
            };
            SyllableType = new FeatureSymbol(Guid.NewGuid().ToString())
            {
                Description = "syllable"
            };
            StemType = new FeatureSymbol(Guid.NewGuid().ToString())
            {
                Description = "stem"
            };
            PrefixType = new FeatureSymbol(Guid.NewGuid().ToString())
            {
                Description = "prefix"
            };
            SuffixType = new FeatureSymbol(Guid.NewGuid().ToString())
            {
                Description = "suffix"
            };

            Type = new SymbolicFeature(Guid.NewGuid().ToString(), AnchorType, VowelType, ConsonantType, ToneLetterType, BoundaryType, SyllableType, StemType, PrefixType, SuffixType)
            {
                Description = "Type"
            };

            Complex = new FeatureSymbol(Guid.NewGuid().ToString())
            {
                Description = "complex"
            };
            Simple = new FeatureSymbol(Guid.NewGuid().ToString())
            {
                Description = "simple"
            };

            SegmentType = new SymbolicFeature(Guid.NewGuid().ToString(), Complex, Simple)
            {
                Description = "SegmentType"
            };

            OriginalStrRep = new StringFeature(Guid.NewGuid().ToString())
            {
                Description = "OriginalStrRep"
            };
            StrRep = new StringFeature(Guid.NewGuid().ToString())
            {
                Description = "StrRep"
            };

            First = new ComplexFeature(Guid.NewGuid().ToString())
            {
                Description = "First"
            };

            Onset = new FeatureSymbol(Guid.NewGuid().ToString())
            {
                Description = "onset"
            };
            Nucleus = new FeatureSymbol(Guid.NewGuid().ToString())
            {
                Description = "nucleus"
            };
            Coda = new FeatureSymbol(Guid.NewGuid().ToString())
            {
                Description = "coda"
            };

            SyllablePosition = new SymbolicFeature(Guid.NewGuid().ToString(), Onset, Nucleus, Coda)
            {
                Description = "SyllablePosition"
            };

            Instance = new CogFeatureSystem();
        }
Exemplo n.º 21
0
        private Feature LoadFeature(XElement featElem)
        {
            var id = (string) featElem.Attribute("id");
            var name = (string) featElem.Element("Name");
            switch (featElem.Name.LocalName)
            {
                case "SymbolicFeature":
                    IEnumerable<FeatureSymbol> symbols = featElem.Elements("Symbols").Elements("Symbol").Select(e => new FeatureSymbol((string) e.Attribute("id"), (string) e));
                    var feature = new SymbolicFeature(id, symbols) { Description = name };
                    var defValId = (string) featElem.Attribute("defaultSymbol");
                    if (!string.IsNullOrEmpty(defValId))
                        feature.DefaultSymbolID = defValId;
                    return feature;

                case "ComplexFeature":
                    return new ComplexFeature(id) {Description = name};
            }

            return null;
        }