Esempio n. 1
0
        public void Test()
        {
            var v = new PhonemeQuery(new[] { "a", "e", "i", "o", "u" });
            var q = new WithQuery(v, "field", new[] { "val1", "val2" });

            var word = new Word(
                phonemes: new[] { "r", "a", "t", "a", "b", "l", "e", "r", "a" },
                graphicalForms: null,
                fields: new Dictionary <string, Alignment <string> >()
            {
                { "field", new Alignment <string>(new []
                    {
                        new Interval <string>(1, 1, "val1"),
                        new Interval <string>(2, 1, "val1"),
                        new Interval <string>(3, 1, "val3"),
                        new Interval <string>(4, 1, "val3"),
                        new Interval <string>(6, 1, "val2"),
                        new Interval <string>(8, 1, "val1"),
                    }) },
            });

            QueryAssert.NoMatch(q, word, 0);
            QueryAssert.IsMatch(q, word, 1, new[] { "a" });
            QueryAssert.NoMatch(q, word, 2);
            QueryAssert.NoMatch(q, word, 3);
            QueryAssert.NoMatch(q, word, 4);
            QueryAssert.NoMatch(q, word, 5);
            QueryAssert.IsMatch(q, word, 6, new[] { "e" });
            QueryAssert.NoMatch(q, word, 7);
            QueryAssert.IsMatch(q, word, 8, new[] { "a" });
            QueryAssert.NoMatch(q, word, 9);

            Assert.Throws <ArgumentOutOfRangeException>(() => q.Match(word, -1));
            Assert.Throws <ArgumentOutOfRangeException>(() => q.Match(word, 10));
        }
Esempio n. 2
0
        public void TestMatchesWithLookBehindAndLookAhead()
        {
            var v = new PhonemeQuery(new[] { "a", "e", "i", "o", "u" });
            var c = new PhonemeQuery(new[] { "r", "t", "b", "l" });
            var q = new ContextualQuery(c, lookBehind: v, lookAhead: v);

            var word = new Word(Phonemes("r", "a", "t", "a", "b", "l", "e", "r", "a"), null, null);

            var matches  = q.Match(word).Map((string[] px) => string.Join(string.Empty, px)).ToArray();
            var expected = new[]
            {
                new Interval <string>(2, 1, "t"),
                new Interval <string>(7, 1, "r"),
            };

            Assert.Equal(expected, matches);
        }
Esempio n. 3
0
        public void TestMatches()
        {
            var v = new PhonemeQuery(new[] { "a", "e", "i", "o", "u" });
            var c = new PhonemeQuery(new[] { "r", "t", "b", "l" });
            var q = new ContextualQuery(new SequenceQuery(new[] { c, v, c }));

            var word = new Word(Phonemes("r", "a", "t", "a", "b", "l", "e", "r", "a"), null, null);

            var matches  = q.Match(word).Map((string[] px) => string.Join(string.Empty, px)).ToArray();
            var expected = new[]
            {
                new Interval <string>(0, 3, "rat"),
                new Interval <string>(5, 3, "ler"),
            };

            Assert.Equal(expected, matches);
        }
Esempio n. 4
0
        public void TestScope()
        {
            var q = new PhonemeQuery(new[] { "a", "e", "i", "o", "u" });

            var word = new Word(
                phonemes: new[] { "a", "t", "a", "b", "l", "e", "r", "a" },
                graphicalForms: null,
                fields: null);

            var scope = new Interval(2, 4);

            Assert.Throws <ArgumentOutOfRangeException>(() => q.Match(word, 1, scope));
            QueryAssert.IsMatch(q, word, 2, new[] { "a" }, scope);
            QueryAssert.NoMatch(q, word, 3, scope);
            QueryAssert.NoMatch(q, word, 4, scope);
            QueryAssert.IsMatch(q, word, 5, new[] { "e" }, scope);
            QueryAssert.NoMatch(q, word, 6, scope);
            Assert.Throws <ArgumentOutOfRangeException>(() => q.Match(word, 7, scope));
        }
Esempio n. 5
0
        public void TestMatchesWithScope()
        {
            var t = new PhonemeQuery(new[] { "t" });
            var a = new PhonemeQuery(new[] { "a" });
            var q = new ContextualQuery(new SequenceQuery(new[] { t, a, t }),
                                        scope: "syllable");

            var word = new Word(
                Phonemes("t", "a", "t", "a", "t", "t", "a", "a", "t", "a", "t"), null,
                Fields(Field("syllable", Alignment.Parse("short:2 long:3 short:2 short:1 long:3"))));

            var matches  = q.Match(word).Map((string[] px) => string.Join(string.Empty, px)).ToArray();
            var expected = new[]
            {
                new Interval <string>(2, 3, "tat"),
                new Interval <string>(8, 3, "tat"),
            };

            Assert.Equal(expected, matches);
        }
Esempio n. 6
0
        public void Test()
        {
            var q = new PhonemeQuery(new[] { "a", "e", "i", "o", "u" });

            var word = new Word(
                phonemes: new[] { "a", "t", "a", "b", "l", "e" },
                graphicalForms: null,
                fields: null);

            QueryAssert.IsMatch(q, word, 0, new[] { "a" });
            QueryAssert.NoMatch(q, word, 1);
            QueryAssert.IsMatch(q, word, 2, new[] { "a" });
            QueryAssert.NoMatch(q, word, 3);
            QueryAssert.NoMatch(q, word, 4);
            QueryAssert.IsMatch(q, word, 5, new[] { "e" });
            QueryAssert.NoMatch(q, word, 6);

            Assert.Throws <ArgumentOutOfRangeException>(() => q.Match(word, -1));
            Assert.Throws <ArgumentOutOfRangeException>(() => q.Match(word, 7));
        }
Esempio n. 7
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);
        }
Esempio n. 8
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);
        }
Esempio n. 9
0
        public void Test()
        {
            var v = new PhonemeQuery(new[] { "a", "e", "i", "o", "u" });
            var c = new PhonemeQuery(new[] { "r", "t", "b", "l" });
            var q = new SequenceQuery(new IQuery[] { c, new MaybeQuery(c), v });

            var word = new Word(
                phonemes: new[] { "a", "t", "a", "b", "l", "e" },
                graphicalForms: null,
                fields: null);

            QueryAssert.NoMatch(q, word, 0);
            QueryAssert.IsMatch(q, word, 1, new[] { "t", "a" });
            QueryAssert.NoMatch(q, word, 2);
            QueryAssert.IsMatch(q, word, 3, new[] { "b", "l", "e" });
            QueryAssert.IsMatch(q, word, 4, new[] { "l", "e" });
            QueryAssert.NoMatch(q, word, 5);
            QueryAssert.NoMatch(q, word, 6);

            Assert.Throws <ArgumentOutOfRangeException>(() => q.Match(word, -1));
            Assert.Throws <ArgumentOutOfRangeException>(() => q.Match(word, 7));
        }
Esempio n. 10
0
        public void TestScope()
        {
            var v = new PhonemeQuery(new[] { "a", "e", "i", "o", "u" });
            var c = new PhonemeQuery(new[] { "r", "s", "c", "b", "l" });
            var q = new SequenceQuery(new IQuery[] { c, new MaybeQuery(c), v });

            var word = new Word(
                phonemes: new[] { "s", "c", "r", "a", "b", "l", "e", "b", "l", "e" },
                graphicalForms: null,
                fields: null);

            var scope = new Interval(2, 6);

            Assert.Throws <ArgumentOutOfRangeException>(() => q.Match(word, 1, scope));
            QueryAssert.IsMatch(q, word, 2, new[] { "r", "a" }, scope);
            QueryAssert.NoMatch(q, word, 3, scope);
            QueryAssert.IsMatch(q, word, 4, new[] { "b", "l", "e" }, scope);
            QueryAssert.IsMatch(q, word, 5, new[] { "l", "e" }, scope);
            QueryAssert.NoMatch(q, word, 6, scope);
            QueryAssert.NoMatch(q, word, 7, scope);
            QueryAssert.NoMatch(q, word, 8, scope);
            Assert.Throws <ArgumentOutOfRangeException>(() => q.Match(word, 9, scope));
        }
Esempio n. 11
0
        public void TestSequenceWithEndAnchor()
        {
            var e = new EndAnchorQuery();
            var v = new PhonemeQuery(new[] { "a", "e", "i", "o", "u" });
            var c = new PhonemeQuery(new[] { "r", "t", "b", "l" });
            var q = new SequenceQuery(new IQuery[] { c, c, v, e });

            var word = new Word(
                phonemes: new[] { "r", "a", "t", "a", "b", "l", "e" },
                graphicalForms: null,
                fields: null);

            QueryAssert.NoMatch(q, word, 0);
            QueryAssert.NoMatch(q, word, 1);
            QueryAssert.NoMatch(q, word, 2);
            QueryAssert.NoMatch(q, word, 3);
            QueryAssert.IsMatch(q, word, 4, new[] { "b", "l", "e" });
            QueryAssert.NoMatch(q, word, 5);
            QueryAssert.NoMatch(q, word, 6);
            QueryAssert.NoMatch(q, word, 7);

            Assert.Throws <ArgumentOutOfRangeException>(() => q.Match(word, -1));
            Assert.Throws <ArgumentOutOfRangeException>(() => q.Match(word, 8));
        }