public void ReplaceElements() { StringTransducer replace = StringTransducer.Replace(ImmutableDiscreteChar.Lower(), ImmutableDiscreteChar.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); }
public void Repeat2() { StringAutomaton automaton = StringAutomaton.Constant(1.0, ImmutableDiscreteChar.Lower()); StringInferenceTestUtilities.TestValue(automaton, 1.0, string.Empty, "ab", "abcab"); automaton = StringAutomaton.Repeat(automaton); // Can't use StringInferenceTestUtilities.TestValue here since the value is not infinite in log-domain // due to approximate closure computations for epsilon-loops Assert.True(automaton.GetValue(string.Empty) > 1000); Assert.True(automaton.GetValue("ab") > 1000); Assert.True(automaton.GetValue("abcab") > 1000); }
public void Optional() { StringAutomaton automaton = StringAutomaton.Constant(1.0, ImmutableDiscreteChar.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); }
public void ConsumeAutomaton() { StringAutomaton automaton = StringAutomaton.Constant(2.0, ImmutableDiscreteChar.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); }
public void Sum() { StringTransducer replace = StringTransducer.Sum( StringTransducer.Replace(ImmutableDiscreteChar.Lower(), ImmutableDiscreteChar.Digit()), StringTransducer.Replace(ImmutableDiscreteChar.Lower(), ImmutableDiscreteChar.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); }
public void CopyAutomaton() { StringAutomaton automaton = StringAutomaton.ConstantOn(1.0, "prefix1", "prefix2") .Append(StringAutomaton.Constant(1.0, ImmutableDiscreteChar.Lower())) .Append(StringAutomaton.Constant(1.0, ImmutableDiscreteChar.Upper())) .Append("!"); 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") .Append(StringAutomaton.ConstantOn(3.0, "lll", "mmm")) .Append(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") .Append(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); }
public void ReplaceAutomaton() { StringAutomaton automaton1 = StringAutomaton.Constant(2.0, ImmutableDiscreteChar.Lower()); automaton1 = automaton1.Sum(StringAutomaton.ConstantOnElement(3.0, 'a')); StringAutomaton automaton2 = StringAutomaton.Constant(0.5, ImmutableDiscreteChar.Digit()); automaton2 = automaton2.Sum(StringAutomaton.Constant(2.5, ImmutableDiscreteChar.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); }