Exemplo n.º 1
0
        public void Copy()
        {
            StringTransducer copy = StringTransducer.Copy();

            StringInferenceTestUtilities.TestTransducerValue(copy, "important", "important", 1.0);
            StringInferenceTestUtilities.TestTransducerValue(copy, "important", "i", 0.0);
            StringInferenceTestUtilities.TestTransducerValue(copy, "important", "imp", 0.0);
            StringInferenceTestUtilities.TestTransducerValue(copy, "important", "t", 0.0);
            StringInferenceTestUtilities.TestTransducerValue(copy, "important", "mpo", 0.0);
            StringInferenceTestUtilities.TestTransducerValue(copy, string.Empty, string.Empty, 1.0);
            StringInferenceTestUtilities.TestTransducerValue(copy, "important", string.Empty, 0.0);
            StringInferenceTestUtilities.TestTransducerValue(copy, string.Empty, "important", 0.0);

            //// Test that projection on Copy() doesn't change the automaton

            StringAutomaton automaton = StringAutomaton.ConstantOn(2.0, "a", "ab", "ac");

            automaton = automaton.Sum(StringAutomaton.ConstantOn(1.0, "a"));
            automaton = automaton.Sum(StringAutomaton.Constant(2.0));
            automaton = automaton.Product(StringAutomaton.Constant(3.0));

            StringAutomaton automatonClone = copy.ProjectSource(automaton);

            Assert.Equal(automaton, automatonClone);
        }
Exemplo n.º 2
0
        public void CopyElement()
        {
            StringTransducer copy = StringTransducer.CopyElement(DiscreteChar.OneOf('a', 'b'));

            StringInferenceTestUtilities.TestTransducerValue(copy, "a", "a", 1.0);
            StringInferenceTestUtilities.TestTransducerValue(copy, "b", "b", 1.0);
            StringInferenceTestUtilities.TestTransducerValue(copy, "a", "b", 0.0);
            StringInferenceTestUtilities.TestTransducerValue(copy, "b", "a", 0.0);
            StringInferenceTestUtilities.TestTransducerValue(copy, string.Empty, string.Empty, 0.0);
            StringInferenceTestUtilities.TestTransducerValue(copy, "bb", "bb", 0.0);
            StringInferenceTestUtilities.TestTransducerValue(copy, "bab", "bab", 0.0);
            StringInferenceTestUtilities.TestTransducerValue(copy, "bab", "ba", 0.0);

            //// Tests that projection on CopyElement(elements) shrinks the support

            StringAutomaton automaton = StringAutomaton.ConstantOn(2.0, "a", "ab", "ac");

            automaton = automaton.Sum(StringAutomaton.ConstantOn(1.0, "a"));
            automaton = automaton.Sum(StringAutomaton.Constant(2.0));
            automaton = automaton.Product(StringAutomaton.Constant(3.0));

            for (int i = 0; i < 2; ++i)
            {
                StringInferenceTestUtilities.TestValue(automaton, 15, "a");
                StringInferenceTestUtilities.TestValue(automaton, 6.0, "b");
                StringInferenceTestUtilities.TestValue(automaton, i == 0 ? 6.0 : 0.0, string.Empty);
                StringInferenceTestUtilities.TestValue(automaton, i == 0 ? 12.0 : 0.0, "ac", "ab");

                automaton = copy.ProjectSource(automaton);
            }
        }
Exemplo n.º 3
0
        public void ProduceSequence()
        {
            StringTransducer produce = StringTransducer.Produce("abc");

            StringInferenceTestUtilities.TestTransducerValue(produce, string.Empty, "abc", 1.0);
            StringInferenceTestUtilities.TestTransducerValue(produce, string.Empty, "ab", 0.0);
            StringInferenceTestUtilities.TestTransducerValue(produce, string.Empty, "abcd", 0.0);
            StringInferenceTestUtilities.TestTransducerValue(produce, string.Empty, string.Empty, 0.0);
            StringInferenceTestUtilities.TestTransducerValue(produce, "abc", string.Empty, 0.0);
        }
Exemplo n.º 4
0
        public void ConsumeSequence()
        {
            StringTransducer consume = StringTransducer.Consume("abc");

            StringInferenceTestUtilities.TestTransducerValue(consume, "abc", string.Empty, 1.0);
            StringInferenceTestUtilities.TestTransducerValue(consume, "ab", string.Empty, 0.0);
            StringInferenceTestUtilities.TestTransducerValue(consume, "abcd", string.Empty, 0.0);
            StringInferenceTestUtilities.TestTransducerValue(consume, string.Empty, string.Empty, 0.0);
            StringInferenceTestUtilities.TestTransducerValue(consume, string.Empty, "abc", 0.0);
        }
Exemplo n.º 5
0
        public void ProduceElement()
        {
            StringTransducer produce = StringTransducer.ProduceElement('x');

            StringInferenceTestUtilities.TestTransducerValue(produce, string.Empty, "x", 1.0);
            StringInferenceTestUtilities.TestTransducerValue(produce, string.Empty, "xx", 0.0);
            StringInferenceTestUtilities.TestTransducerValue(produce, string.Empty, string.Empty, 0.0);
            StringInferenceTestUtilities.TestTransducerValue(produce, "x", string.Empty, 0.0);
            StringInferenceTestUtilities.TestTransducerValue(produce, "xx", string.Empty, 0.0);
        }
Exemplo n.º 6
0
        public void ConsumeElement()
        {
            StringTransducer consume = StringTransducer.ConsumeElement('x');

            StringInferenceTestUtilities.TestTransducerValue(consume, "x", string.Empty, 1.0);
            StringInferenceTestUtilities.TestTransducerValue(consume, "xx", string.Empty, 0.0);
            StringInferenceTestUtilities.TestTransducerValue(consume, string.Empty, string.Empty, 0.0);
            StringInferenceTestUtilities.TestTransducerValue(consume, string.Empty, "x", 0.0);
            StringInferenceTestUtilities.TestTransducerValue(consume, string.Empty, "xx", 0.0);
        }
Exemplo n.º 7
0
        public void Repeat2()
        {
            StringAutomaton  automaton = StringAutomaton.ConstantOn(2.0, "a", string.Empty);
            StringTransducer repeat    = StringTransducer.Repeat(StringTransducer.Copy(automaton), 1, 2);

            StringInferenceTestUtilities.TestTransducerValue(repeat, "a", "a", 10.0);
            StringInferenceTestUtilities.TestTransducerValue(repeat, "aa", "aa", 4.0);
            StringInferenceTestUtilities.TestTransducerValue(repeat, string.Empty, string.Empty, 6.0);
            StringInferenceTestUtilities.TestTransducerValue(repeat, "aaa", "aaa", 0.0);
            StringInferenceTestUtilities.TestTransducerValue(repeat, "aa", "a", 0.0);
            StringInferenceTestUtilities.TestTransducerValue(repeat, string.Empty, "a", 0.0);
        }
Exemplo n.º 8
0
        public void Repeat1()
        {
            StringAutomaton  automaton = StringAutomaton.ConstantOn(2.0, "a");
            StringTransducer repeat    = StringTransducer.Repeat(StringTransducer.Consume(automaton), 1, 3);

            StringInferenceTestUtilities.TestTransducerValue(repeat, "a", string.Empty, 2.0);
            StringInferenceTestUtilities.TestTransducerValue(repeat, "aa", string.Empty, 4.0);
            StringInferenceTestUtilities.TestTransducerValue(repeat, "aaa", string.Empty, 8.0);
            StringInferenceTestUtilities.TestTransducerValue(repeat, "aaaa", string.Empty, 0.0);
            StringInferenceTestUtilities.TestTransducerValue(repeat, string.Empty, string.Empty, 0.0);
            StringInferenceTestUtilities.TestTransducerValue(repeat, string.Empty, "aaa", 0.0);
        }
Exemplo n.º 9
0
        public void ReplaceSequence()
        {
            StringTransducer replace = StringTransducer.Replace("hello", "worlds");

            StringInferenceTestUtilities.TestTransducerValue(replace, "hello", "worlds", 1.0);
            StringInferenceTestUtilities.TestTransducerValue(replace, "worlds", "hello", 0.0);
            StringInferenceTestUtilities.TestTransducerValue(replace, "worlds", "worlds", 0.0);
            StringInferenceTestUtilities.TestTransducerValue(replace, "hello", "hello", 0.0);
            StringInferenceTestUtilities.TestTransducerValue(replace, "hello", string.Empty, 0.0);
            StringInferenceTestUtilities.TestTransducerValue(replace, string.Empty, "worlds", 0.0);
            StringInferenceTestUtilities.TestTransducerValue(replace, string.Empty, string.Empty, 0.0);
        }
Exemplo n.º 10
0
        public void ReplaceElements()
        {
            StringTransducer replace = StringTransducer.Replace(DiscreteChar.Lower(), DiscreteChar.Digit());

            StringInferenceTestUtilities.TestTransducerValue(replace, "hello", "123", 1.0);
            StringInferenceTestUtilities.TestTransducerValue(replace, "w", "1337", 1.0);
            StringInferenceTestUtilities.TestTransducerValue(replace, "w", string.Empty, 1.0);
            StringInferenceTestUtilities.TestTransducerValue(replace, string.Empty, "17", 1.0);
            StringInferenceTestUtilities.TestTransducerValue(replace, string.Empty, string.Empty, 1.0);
            StringInferenceTestUtilities.TestTransducerValue(replace, "123", "worlds", 0.0);
            StringInferenceTestUtilities.TestTransducerValue(replace, "123", "123", 0.0);
            StringInferenceTestUtilities.TestTransducerValue(replace, "1", string.Empty, 0.0);
        }
Exemplo n.º 11
0
        public void Optional()
        {
            StringAutomaton  automaton    = StringAutomaton.Constant(1.0, DiscreteChar.Lower());
            StringTransducer copy         = StringTransducer.Copy(automaton);
            StringTransducer copyOptional = StringTransducer.Optional(copy);

            StringInferenceTestUtilities.TestTransducerValue(copy, "abc", "abc", 1.0);
            StringInferenceTestUtilities.TestTransducerValue(copyOptional, "abc", "abc", 1.0);
            StringInferenceTestUtilities.TestTransducerValue(copy, string.Empty, string.Empty, 1.0);
            StringInferenceTestUtilities.TestTransducerValue(copyOptional, string.Empty, string.Empty, 2.0);
            StringInferenceTestUtilities.TestTransducerValue(copy, "abc", "ab", 0.0);
            StringInferenceTestUtilities.TestTransducerValue(copyOptional, "abc", "ab", 0.0);
            StringInferenceTestUtilities.TestTransducerValue(copy, "abc", string.Empty, 0.0);
            StringInferenceTestUtilities.TestTransducerValue(copyOptional, "abc", string.Empty, 0.0);
        }
Exemplo n.º 12
0
        public void Repeat3()
        {
            StringAutomaton  automaton = StringAutomaton.ConstantOn(2.0, "a", "aa");
            StringTransducer repeat    = StringTransducer.Repeat(StringTransducer.Replace(automaton, automaton), minTimes: 0);

            StringInferenceTestUtilities.TestTransducerValue(repeat, string.Empty, string.Empty, 1.0); // TODO: it's not clear from the definition that this should hold
            StringInferenceTestUtilities.TestTransducerValue(repeat, "a", "a", 4.0);
            StringInferenceTestUtilities.TestTransducerValue(repeat, "a", "aa", 4.0);
            StringInferenceTestUtilities.TestTransducerValue(repeat, "aa", "aa", 20.0);
            StringInferenceTestUtilities.TestTransducerValue(repeat, "aaa", "aa", 32.0);
            StringInferenceTestUtilities.TestTransducerValue(repeat, "aa", "aaa", 32.0);
            StringInferenceTestUtilities.TestTransducerValue(repeat, "a", "aaa", 0.0);
            StringInferenceTestUtilities.TestTransducerValue(repeat, string.Empty, "a", 0.0);
            StringInferenceTestUtilities.TestTransducerValue(repeat, "b", "b", 0.0);
        }
Exemplo n.º 13
0
        public void ProduceAutomaton()
        {
            StringAutomaton automaton = StringAutomaton.Constant(2.0, ImmutableDiscreteChar.Lower());

            automaton = automaton.Sum(StringAutomaton.ConstantOnElement(3.0, 'a'));
            StringTransducer produce = StringTransducer.Produce(automaton);

            StringInferenceTestUtilities.TestTransducerValue(produce, string.Empty, "aaa", 2.0);
            StringInferenceTestUtilities.TestTransducerValue(produce, string.Empty, "bb", 2.0);
            StringInferenceTestUtilities.TestTransducerValue(produce, string.Empty, "a", 5.0);
            StringInferenceTestUtilities.TestTransducerValue(produce, string.Empty, string.Empty, 2.0);
            StringInferenceTestUtilities.TestTransducerValue(produce, "aaa", "bb", 0.0);
            StringInferenceTestUtilities.TestTransducerValue(produce, "bb", "bb", 0.0);
            StringInferenceTestUtilities.TestTransducerValue(produce, "bb", string.Empty, 0.0);
            StringInferenceTestUtilities.TestTransducerValue(produce, "a", string.Empty, 0.0);
        }
Exemplo n.º 14
0
        public void ConsumeAutomaton()
        {
            StringAutomaton automaton = StringAutomaton.Constant(2.0, DiscreteChar.Lower());

            automaton = automaton.Sum(StringAutomaton.ConstantOnElement(3.0, 'a'));
            StringTransducer consume = StringTransducer.Consume(automaton);

            StringInferenceTestUtilities.TestTransducerValue(consume, "aaa", string.Empty, 2.0);
            StringInferenceTestUtilities.TestTransducerValue(consume, "bb", string.Empty, 2.0);
            StringInferenceTestUtilities.TestTransducerValue(consume, "a", string.Empty, 5.0);
            StringInferenceTestUtilities.TestTransducerValue(consume, string.Empty, string.Empty, 2.0);
            StringInferenceTestUtilities.TestTransducerValue(consume, "bb", "aaa", 0.0);
            StringInferenceTestUtilities.TestTransducerValue(consume, "bb", "bb", 0.0);
            StringInferenceTestUtilities.TestTransducerValue(consume, string.Empty, "bb", 0.0);
            StringInferenceTestUtilities.TestTransducerValue(consume, string.Empty, "a", 0.0);
        }
Exemplo n.º 15
0
        public void Sum()
        {
            StringTransducer replace = StringTransducer.Sum(
                StringTransducer.Replace(DiscreteChar.Lower(), DiscreteChar.Digit()),
                StringTransducer.Replace(DiscreteChar.Lower(), DiscreteChar.LetterOrDigit()));

            StringInferenceTestUtilities.TestTransducerValue(replace, "hello", "123", 2.0);
            StringInferenceTestUtilities.TestTransducerValue(replace, "w", "1337", 2.0);
            StringInferenceTestUtilities.TestTransducerValue(replace, "w", string.Empty, 2.0);
            StringInferenceTestUtilities.TestTransducerValue(replace, string.Empty, "17", 2.0);
            StringInferenceTestUtilities.TestTransducerValue(replace, string.Empty, string.Empty, 2.0);
            StringInferenceTestUtilities.TestTransducerValue(replace, "hello", "worlds", 1.0);
            StringInferenceTestUtilities.TestTransducerValue(replace, "hello", "WORLDS111", 1.0);
            StringInferenceTestUtilities.TestTransducerValue(replace, "123", "worlds", 0.0);
            StringInferenceTestUtilities.TestTransducerValue(replace, "123", "123", 0.0);
            StringInferenceTestUtilities.TestTransducerValue(replace, "1", string.Empty, 0.0);
        }
Exemplo n.º 16
0
        public void CopyAutomaton()
        {
            StringAutomaton automaton = StringAutomaton.ConstantOn(1.0, "prefix1", "prefix2");

            automaton.AppendInPlace(StringAutomaton.Constant(1.0, DiscreteChar.Lower()));
            automaton.AppendInPlace(StringAutomaton.Constant(1.0, DiscreteChar.Upper()));
            automaton.AppendInPlace("!");

            StringTransducer copy = StringTransducer.Copy(automaton);

            StringInferenceTestUtilities.TestTransducerValue(copy, "prefix1!", "prefix1!", 1.0);
            StringInferenceTestUtilities.TestTransducerValue(copy, "prefix2!", "prefix2!", 1.0);
            StringInferenceTestUtilities.TestTransducerValue(copy, "prefix1lower!", "prefix1lower!", 1.0);
            StringInferenceTestUtilities.TestTransducerValue(copy, "prefix2UPPER!", "prefix2UPPER!", 1.0);
            StringInferenceTestUtilities.TestTransducerValue(copy, "prefix1lowerUPPER!", "prefix1lowerUPPER!", 1.0);
            StringInferenceTestUtilities.TestIfTransducerRejects(copy, "prefix1lower", "prefix2UPPER", "!", "prefix1lowerUPPER");

            StringInferenceTestUtilities.TestTransducerProjection(copy, automaton, "prefix1!", 1.0);
            StringInferenceTestUtilities.TestTransducerProjection(copy, automaton, "prefix2!", 1.0);
            StringInferenceTestUtilities.TestTransducerProjection(copy, automaton, "prefix1lower!", 1.0);
            StringInferenceTestUtilities.TestTransducerProjection(copy, automaton, "prefix2UPPER!", 1.0);
            StringInferenceTestUtilities.TestTransducerProjection(copy, automaton, "prefix1lowerUPPER!", 1.0);

            StringAutomaton subsetAutomaton = StringAutomaton.ConstantOn(2.0, "prefix1");

            subsetAutomaton.AppendInPlace(StringAutomaton.ConstantOn(3.0, "lll", "mmm"));
            subsetAutomaton.AppendInPlace(StringAutomaton.ConstantOn(1.5, "!", "U!"));
            StringInferenceTestUtilities.TestTransducerProjection(copy, subsetAutomaton, "prefix1lll!", 9.0);
            StringInferenceTestUtilities.TestTransducerProjection(copy, subsetAutomaton, "prefix1mmmU!", 9.0);
            StringInferenceTestUtilities.TestTransducerProjection(copy, subsetAutomaton, "prefix1!", 0.0);
            StringInferenceTestUtilities.TestTransducerProjection(copy, subsetAutomaton, "prefix2lower!", 0.0);
            StringInferenceTestUtilities.TestTransducerProjection(copy, subsetAutomaton, "prefix2U!", 0.0);

            StringAutomaton supersetAutomaton = StringAutomaton.ConstantOn(1.5, "pr");

            supersetAutomaton.AppendInPlace(StringAutomaton.Constant(2.0));
            StringInferenceTestUtilities.TestTransducerProjection(copy, supersetAutomaton, "prefix1!", 3.0);
            StringInferenceTestUtilities.TestTransducerProjection(copy, supersetAutomaton, "prefix2!", 3.0);
            StringInferenceTestUtilities.TestTransducerProjection(copy, supersetAutomaton, "prefix1lower!", 3.0);
            StringInferenceTestUtilities.TestTransducerProjection(copy, supersetAutomaton, "prefix2UPPER!", 3.0);
            StringInferenceTestUtilities.TestTransducerProjection(copy, supersetAutomaton, "prefix1lowerUPPER!", 3.0);
            StringInferenceTestUtilities.TestTransducerProjection(copy, supersetAutomaton, "prefix11!", 0.0);
            StringInferenceTestUtilities.TestTransducerProjection(copy, supersetAutomaton, "prefix1lowerUPPERlower!", 0.0);
            StringInferenceTestUtilities.TestTransducerProjection(copy, supersetAutomaton, "prrrrr!", 0.0);
        }
Exemplo n.º 17
0
        public void CopySequence1()
        {
            StringTransducer copySequence = StringTransducer.Copy("important");

            StringInferenceTestUtilities.TestTransducerValue(copySequence, "important", "important", 1.0);
            StringInferenceTestUtilities.TestTransducerValue(copySequence, "important", "imp", 0.0);
            StringInferenceTestUtilities.TestTransducerValue(copySequence, "important", "ortant", 0.0);
            StringInferenceTestUtilities.TestTransducerValue(copySequence, "important", string.Empty, 0.0);
            StringInferenceTestUtilities.TestTransducerProjection(copySequence, StringAutomaton.ConstantOn(3.0, "important"), "important", 3.0);
            StringInferenceTestUtilities.TestTransducerProjection(copySequence, StringAutomaton.ConstantOn(1.5, "important", "not important"), "important", 1.5);
            StringInferenceTestUtilities.TestTransducerProjection(copySequence, StringAutomaton.Constant(2.0), "important", 2.0);
            StringInferenceTestUtilities.TestTransducerProjection(
                copySequence,
                StringAutomaton.Constant(2.0).Append(StringAutomaton.ConstantOn(3.0, "nt")),
                "important",
                6.0);
            StringInferenceTestUtilities.TestIfTransducerRejects(copySequence, string.Empty, "nothing is important", "importance", "imp", "ortant", "a");
        }
Exemplo n.º 18
0
        public void ReplaceAutomaton()
        {
            StringAutomaton automaton1 = StringAutomaton.Constant(2.0, DiscreteChar.Lower());

            automaton1 = automaton1.Sum(StringAutomaton.ConstantOnElement(3.0, 'a'));
            StringAutomaton automaton2 = StringAutomaton.Constant(0.5, DiscreteChar.Digit());

            automaton2 = automaton2.Sum(StringAutomaton.Constant(2.5, DiscreteChar.LetterOrDigit()));
            StringTransducer replace = StringTransducer.Replace(automaton1, automaton2);

            StringInferenceTestUtilities.TestTransducerValue(replace, string.Empty, "123", 6.0);
            StringInferenceTestUtilities.TestTransducerValue(replace, "a", "123", 15.0);
            StringInferenceTestUtilities.TestTransducerValue(replace, "ax", "AbC", 5.0);
            StringInferenceTestUtilities.TestTransducerValue(replace, "a", "a", 12.5);
            StringInferenceTestUtilities.TestTransducerValue(replace, string.Empty, string.Empty, 6.0);
            StringInferenceTestUtilities.TestTransducerValue(replace, "123", string.Empty, 0.0);
            StringInferenceTestUtilities.TestTransducerValue(replace, "AbC", "ax", 0.0);
            StringInferenceTestUtilities.TestTransducerValue(replace, "1", "1", 0.0);
        }