Exemplo n.º 1
0
        public void Compose()
        {
            var featSys = new FeatureSystem
            {
                new StringFeature("value")
            };

            var fst1 = new Fst <AnnotatedStringData, int>(_operations);

            fst1.StartState = fst1.CreateState();
            State <AnnotatedStringData, int> s1 = fst1.StartState.Arcs.Add(FeatureStruct.New(featSys).Feature("value").EqualTo("a").Value, FeatureStruct.New(featSys).Feature("value").EqualTo("x").Value, fst1.CreateAcceptingState());

            s1.Arcs.Add(FeatureStruct.New(featSys).Feature("value").EqualTo("b").Value, FeatureStruct.New(featSys).Feature("value").EqualTo("y").Value, s1);

            var fst2 = new Fst <AnnotatedStringData, int>(_operations);

            fst2.StartState = fst2.CreateAcceptingState();
            fst2.StartState.Arcs.Add(FeatureStruct.New(featSys).Feature("value").EqualTo("x").Value, null, fst2.StartState);
            fst2.StartState.Arcs.Add(FeatureStruct.New(featSys).Feature("value").EqualTo("y").Value, FeatureStruct.New(featSys).Feature("value").EqualTo("z").Value, fst2.StartState);

            Fst <AnnotatedStringData, int> composedFsa = fst1.Compose(fst2);
            var writer = new StringWriter();

            composedFsa.ToGraphViz(writer);
            Assert.That(writer.ToString().Replace("\r\n", "\n"), Is.EqualTo(@"digraph G {
  0 [shape=""diamond"", color=""green""];
  0 -> 1 [label=""[value:\""a\""],1:ε""];
  1 [shape=""circle"", color=""red"", peripheries=""2""];
  1 -> 1 [label=""[value:\""b\""],1:([value:\""z\""],∪)""];
}
".Replace("\r\n", "\n")));
        }
Exemplo n.º 2
0
        public void Compose()
        {
            var featSys = new FeatureSystem
                {
                    new StringFeature("value")
                };

            var fst1 = new Fst<AnnotatedStringData, int>(_operations);
            fst1.StartState = fst1.CreateState();
            State<AnnotatedStringData, int> s1 = fst1.StartState.Arcs.Add(FeatureStruct.New(featSys).Feature("value").EqualTo("a").Value, FeatureStruct.New(featSys).Feature("value").EqualTo("x").Value, fst1.CreateAcceptingState());
            s1.Arcs.Add(FeatureStruct.New(featSys).Feature("value").EqualTo("b").Value, FeatureStruct.New(featSys).Feature("value").EqualTo("y").Value, s1);

            var fst2 = new Fst<AnnotatedStringData, int>(_operations);
            fst2.StartState = fst2.CreateAcceptingState();
            fst2.StartState.Arcs.Add(FeatureStruct.New(featSys).Feature("value").EqualTo("x").Value, null, fst2.StartState);
            fst2.StartState.Arcs.Add(FeatureStruct.New(featSys).Feature("value").EqualTo("y").Value, FeatureStruct.New(featSys).Feature("value").EqualTo("z").Value, fst2.StartState);

            Fst<AnnotatedStringData, int> composedFsa = fst1.Compose(fst2);
            var writer = new StringWriter();
            composedFsa.ToGraphViz(writer);
            Assert.That(writer.ToString().Replace("\r\n", "\n"), Is.EqualTo(@"digraph G {
              0 [shape=""diamond"", color=""green""];
              0 -> 1 [label=""[value:\""a\""],1:ε""];
              1 [shape=""circle"", color=""red"", peripheries=""2""];
              1 -> 1 [label=""[value:\""b\""],1:([value:\""z\""],∪)""];
            }
            ".Replace("\r\n", "\n")));
        }
Exemplo n.º 3
0
        public void Compose()
        {
            var featSys = new FeatureSystem
            {
                new StringFeature("value")
            };

            var fst1 = new Fst <StringData, int>(_operations);

            fst1.StartState = fst1.CreateState();
            State <StringData, int> s1 = fst1.StartState.Arcs.Add(FeatureStruct.New(featSys).Feature("value").EqualTo("a").Value, FeatureStruct.New(featSys).Feature("value").EqualTo("x").Value, fst1.CreateAcceptingState());

            s1.Arcs.Add(FeatureStruct.New(featSys).Feature("value").EqualTo("b").Value, FeatureStruct.New(featSys).Feature("value").EqualTo("y").Value, s1);

            var fst2 = new Fst <StringData, int>(_operations);

            fst2.StartState = fst2.CreateAcceptingState();
            fst2.StartState.Arcs.Add(FeatureStruct.New(featSys).Feature("value").EqualTo("x").Value, null, fst2.StartState);
            fst2.StartState.Arcs.Add(FeatureStruct.New(featSys).Feature("value").EqualTo("y").Value, FeatureStruct.New(featSys).Feature("value").EqualTo("z").Value, fst2.StartState);

            Fst <StringData, int> composedFsa = fst1.Compose(fst2);
            var writer = new System.IO.StreamWriter(string.Format("c:\\ltor-composed-nfst.dot"));

            composedFsa.ToGraphViz(writer);
            writer.Close();
        }