Пример #1
0
        protected void TestSample(IRule rule, RuleContextTest ruleTest, RuleTestSample sample)
        {
            var word = sample.Input;
            var initialDerivation = WordDerivation.Origin(word);
            var derivation        = rule.Derive(ExecutionContext, initialDerivation);
            var derived           = derivation.Select(d => d.Derived).ToArray();

            int expectedNb = sample.Outputs.Length;

            Assert.True(expectedNb == derived.Length,
                        $"Expect [{string.Join("", word.Phonemes)}] to have [{expectedNb}] derivations ({string.Join(", ", sample.Outputs.Select(o => "[" + string.Join("", o.Word.Phonemes) + "]"))}) but only have [{derived.Length}].");

            for (int i = 0; i < sample.Outputs.Length; i++)
            {
                TestSampleOutput(sample.Outputs, derived, i);
            }
        }
Пример #2
0
        public void TestApplyWithScope()
        {
            var c = new PhonemeQuery(new[] { "b", "l" });
            var v = new PhonemeQuery(new[] { "a", "e" });

            var rule = new Rule(
                id: "test",
                group: "test",
                timeSpan: new Interval(0, 1),
                queries: new[] {
                new ContextualQuery(v, lookBehind: c, lookAhead: c, scope: "syllable"),
            },
                operation: new[] {
                new Operation(
                    name: "Test",
                    phonological: ps => new[] { "o" },
                    graphical: new[] {
                    new GraphicalMap((b, m, a) => m),
                })
            });

            var word = new Word(
                Phonemes("b", "e", "l", "l", "a", "b", "e", "l"),
                GraphicalForms(Alignment.Parse("B E L L A B E L")),
                Fields(Field("syllable", Alignment.Parse("long:3 short:2 long:3"))));

            var context            = new ExecutionContext();
            var originalDerivation = WordDerivation.Origin(word);
            var derivation         = rule.DeriveImplementation(context, originalDerivation);
            var newWords           = derivation.Select(d => d.Derived).ToArray();

            var expected = new[]
            {
                new Word(
                    Phonemes("b", "o", "l", "l", "a", "b", "o", "l"),
                    GraphicalForms(Alignment.Parse("B E L L A B E L")),
                    Fields(Field("syllable", Alignment.Parse("long:3 short:2 long:3")))),
            };

            WordAssert.Equal(expected, newWords);
        }
Пример #3
0
        public void TestApply()
        {
            var l = new PhonemeQuery(new[] { "l" });

            var rule = new Rule(
                id: "test",
                group: "test",
                timeSpan: new Interval(0, 1),
                queries: new[] {
                new ContextualQuery(new SequenceQuery(new[] { l, l })),
            },
                operation: new[] {
                new Operation(
                    name: "Test",
                    phonological: ps => new[] { "l" },
                    graphical: new[] {
                    new GraphicalMap((b, m, a) => m),
                })
            });

            var word = new Word(
                Phonemes("b", "e", "l", "l", "a"),
                GraphicalForms(Alignment.Parse("B E L L A")),
                Fields(Field("type", Alignment.Parse("C V C C V"))));

            var context            = new ExecutionContext();
            var originalDerivation = WordDerivation.Origin(word);
            var derivation         = rule.DeriveImplementation(context, originalDerivation);
            var newWords           = derivation.Select(d => d.Derived).ToArray();

            var expected = new[]
            {
                new Word(
                    Phonemes("b", "e", "l", "a"),
                    GraphicalForms(Alignment.Parse("B E LL:2 A")),
                    Fields(Field("type", Alignment.Parse("C V C V"))))
            };

            WordAssert.Equal(expected, newWords);
        }