示例#1
0
        public void Test(BlackBoxTest integrationTest)
        {
            var latinParser = new Latin.WordParser();
            var word        = latinParser.Parse(integrationTest.Latin);

            var analyzers = new IAnalyzer[]
            {
                new MemoizeAnalyzer("classical_latin"),
                new Latin.SyllableAnalyzer(),
                new Latin.AccentAnalyzer(),
            };

            foreach (var analyzer in analyzers)
            {
                analyzer.Analyze(word);
            }

            var rules     = French2.Rules();
            var sequencer = new LinearRuleSequencer(rules, new Dictionary <string, IAnalyzer>()
            {
                { "syllable", new Latin.SyllableAnalyzer() },
            });

            var derived = sequencer.Derive(ExecutionContext, word).Select(d => d.Derived).ToArray();

            var expected = integrationTest.Outputs;

            Assert.Equal(expected.Length, derived.Length);

            for (int i = 0; i < expected.Length; i++)
            {
                TestBlackBoxSample(expected, derived, i);
            }
        }
示例#2
0
        public void Test(WhiteBoxTest whiteBoxTest)
        {
            var latinParser = new Latin.WordParser();
            var word        = latinParser.Parse(whiteBoxTest.Latin);

            var analyzers = new IAnalyzer[]
            {
                new MemoizeAnalyzer("classical_latin"),
                new Latin.SyllableAnalyzer(),
                new Latin.AccentAnalyzer(),
            };

            foreach (var analyzer in analyzers)
            {
                analyzer.Analyze(word);
            }

            var rules     = French2.Rules();
            var sequencer = new LinearRuleSequencer(rules, new Dictionary <string, IAnalyzer>()
            {
                { "syllable", new Latin.SyllableAnalyzer() },
            });

            var derivations = sequencer.Derive(ExecutionContext, word);
            var sequences   = derivations.Select(d => ToSteps(d)).ToArray();

            var seqs          = sequences.ToList();
            var possibleSteps = new List <WhiteBoxStep>();

            for (int i = 1; i < whiteBoxTest.Steps.Length; i++)
            {
                var expected = whiteBoxTest.Steps[i];
                var newSeqs  = new List <WhiteBoxStep[]>();

                for (int j = 0; j < seqs.Count; j++)
                {
                    var seq = seqs[j];

                    if (i >= seq.Length)
                    {
                        continue;
                    }
                    else if (expected.Equals(seq[i]))
                    {
                        newSeqs.Add(seq);
                    }
                    else
                    {
                        possibleSteps.Add(seq[i]);
                    }
                }

                Assert.True(newSeqs.Count > 0,
                            $"Could not find any derivation matching [{expected.Phonemes}] at step [{i}] : {string.Join(", ", possibleSteps.Select(s => "[" + s.Phonemes + "]"))}");

                seqs = newSeqs;
                possibleSteps.Clear();
            }
        }
示例#3
0
文件: Program.cs 项目: gropax/phonos
        static void DeriveWord(string latinWord)
        {
            latinWord = latinWord.Replace(':', '\u0304');

            var latinParser = new Latin.WordParser();
            var word        = latinParser.Parse(latinWord);

            var analyzers = new IAnalyzer[]
            {
                new MemoizeAnalyzer("classical_latin"),
                new Latin.SyllableAnalyzer(),
                new Latin.AccentAnalyzer(),
            };

            foreach (var analyzer in analyzers)
            {
                analyzer.Analyze(word);
            }

            var rules     = French2.Rules();
            var sequencer = new LinearRuleSequencer(rules, new Dictionary <string, IAnalyzer>()
            {
                { "syllable", new Latin.SyllableAnalyzer() },
            });

            var context = new ExecutionContext(new Dictionary <string, IAnalyzer>()
            {
                { "syllable", new Latin.SyllableAnalyzer() },
            });

            var derivations = sequencer.Derive(context, word);
            var sequences   = derivations.Select(d => ToSteps(d)).ToArray();

            foreach (var derivation in derivations)
            {
                string output = derivation.Derived.DebuggerDisplay;

                Console.WriteLine($"\nOutput: {output}\n");
                Console.WriteLine($"Steps:");
                Console.WriteLine($"\t{word.PrettyPhonemes}");
                foreach (var step in ToSteps(derivation))
                {
                    Console.WriteLine($"\t{step.DebuggerDisplay}");
                }
            }
        }