Esempio n. 1
0
        private static List <Dependency> ProjectMarkCyclesAndBackProject(Dependency[] deps, GlobalContext globalContext)
        {
            var backProjectedDeps = new List <Dependency>();

            globalContext.RenameCurrentGraph("INPUT");
            globalContext.CurrentGraph.AddDependencies(deps);

            var pi = new ProjectItems();

            pi.Configure(globalContext,
                         $"{{ {ProjectItems.ProjectionsOption} $GENERIC_2---%SIMPLE !(**) }}".Replace(" ", Environment.NewLine),
                         false);
            var projectedDeps = new List <Dependency>();

            pi.Transform(globalContext, deps, "", projectedDeps, s => null);

            var mc = new MarkCycleDeps();

            mc.Transform(globalContext, projectedDeps,
                         $"{{ {MarkCycleDeps.ConsiderSelfCyclesOption} {MarkCycleDeps.AddIndexedMarkerOption} C }}".Replace(" ", Environment.NewLine), new List <Dependency>(), s => null);

            pi.Transform(globalContext, projectedDeps,
                         $"{{ {ProjectItems.BackProjectionGraphOption} INPUT }}".Replace(" ", Environment.NewLine),
                         backProjectedDeps, s => globalContext.CurrentGraph.VisibleDependencies);

            return(backProjectedDeps);
        }
Esempio n. 2
0
        public void TestToTooFewFields()
        {
            var          pi           = new ProjectItems((p, i) => new ProjectItems.SelfOptimizingPrefixTrieProjector(p, i, 2, "prefixTrie"));
            var          gc           = new GlobalContext();
            const string THREE_FIELDS = "THREE_FIELDS";

            pi.Configure(gc, $@"{{ -pl
    $ {THREE_FIELDS}(F1:F2:F3) ---% {THREE_FIELDS}

    ! a:b:c ---% ::
    ! a:b   ---% : // this threw an exception before a fix
    ! a    ---%
}}", forceReload: false);

            ItemType     threeFields = ItemType.Find(THREE_FIELDS);
            WorkingGraph graph       = gc.CurrentGraph;
            Item         abc         = graph.CreateItem(threeFields, "a:b:c");
            Item         ab          = graph.CreateItem(threeFields, "a:b:-");
            Item         a           = graph.CreateItem(threeFields, "a:-:-");

            var result = new List <Dependency>();

            pi.Transform(gc, new[] {
                graph.CreateDependency(abc, abc, null, "abc", 1),
                graph.CreateDependency(ab, ab, null, "ab", 1),
                graph.CreateDependency(a, a, null, "a", 1),
            }, "", result, s => null);

            Assert.AreEqual(0, result.Count);
        }
Esempio n. 3
0
        private static void SmallTestForPrefixOptimizedProjector(Func <Projection[], bool, ProjectItems.IProjector> createProjector)
        {
            var          pi    = new ProjectItems(createProjector);
            var          gc    = new GlobalContext();
            WorkingGraph graph = gc.CurrentGraph;

            pi.Configure(gc, @"{ -pl
    $ (Ignore:Name) ---% SIMPLE

    ! :a* ---% A
    > :ab ---% AB
    ! :b* ---% B
    ! :c* ---% C
    ! :** ---% 
}", forceReload: false);

            ItemType generic2 = ItemType.Generic(2, ignoreCase: false);
            Item     a        = graph.CreateItem(generic2, "x:a");
            Item     ab       = graph.CreateItem(generic2, "x:ab");
            Item     ac       = graph.CreateItem(generic2, "x:ac");
            Item     ca       = graph.CreateItem(generic2, "x:ca");
            Item     cb       = graph.CreateItem(generic2, "x:cb");
            Item     s        = graph.CreateItem(generic2, "m:s");
            Item     t        = graph.CreateItem(generic2, "m:t");

            var result = new List <Dependency>();

            pi.Transform(gc, new ProjectItems.ConfigureOptions(), new ProjectItems.TransformOptions(), new[] {
                graph.CreateDependency(a, a, null, "a_a", 1),     // the first surviving dependency
                graph.CreateDependency(a, s, null, "a_s", 1),     // vanishes, because s is not mapped
                graph.CreateDependency(ab, s, null, "ab_s", 1),   // same
                graph.CreateDependency(ca, s, null, "ca_s", 1),   // etc.
                graph.CreateDependency(cb, cb, null, "cb_cb", 1), // the second surviving dependency
                graph.CreateDependency(cb, t, null, "cb_t", 1),   // vanishes, because t is not mapped
                graph.CreateDependency(a, t, null, "a_t", 1),
                graph.CreateDependency(ac, t, null, "ac_t", 1),
                graph.CreateDependency(a, s, null, "a_s", 1),

                // Counts:
                // !a  5
                // >ab 0
                // !ac 1
                // !b  0
                // !ca 1
                // !cb 3
                // !s  4
                // !t  3
            }, result);

            Assert.AreEqual(2, result.Count);
            Assert.AreEqual("A", result[0].UsingItem.Values[0]);
            Assert.AreEqual("A", result[0].UsedItem.Values[0]);
            Assert.AreEqual("C", result[1].UsingItem.Values[0]);
            Assert.AreEqual("C", result[1].UsedItem.Values[0]);
        }
Esempio n. 4
0
        public void TestSmallSelfOptimizingPrefixTrieProjector2()
        {
            // This test found a problem in TrieNode.SetProjectors.
            var pi = new ProjectItems((p, i) => new ProjectItems.SelfOptimizingPrefixTrieProjector(p, i, 2, "prefixTrie"));
            var gc = new GlobalContext();

            pi.Configure(gc, @"{ -pl
    $ (:Name) ---% SIMPLE

    ! :abc ---% ADetail
    ! :a*  ---% A
    ! :t   ---% T
    ! :**  ---% 
}", forceReload: false);

            ItemType     generic2 = ItemType.Generic(2, ignoreCase: false);
            WorkingGraph graph    = gc.CurrentGraph;
            Item         a        = graph.CreateItem(generic2, "x:a");
            Item         ab       = graph.CreateItem(generic2, "x:ab");
            Item         abc      = graph.CreateItem(generic2, "x:abc");
            Item         abcd     = graph.CreateItem(generic2, "x:abcd");
            Item         t        = graph.CreateItem(generic2, "m:t");

            var result = new List <Dependency>();

            pi.Transform(gc, new[] {
                graph.CreateDependency(a, t, null, "a_t", 1),       // A_T
                graph.CreateDependency(ab, t, null, "ab_t", 1),     // A_ T
                graph.CreateDependency(abc, t, null, "abc_t", 1),   // ADetail _T
                graph.CreateDependency(abcd, t, null, "abcd_t", 1), // A _ T
            }, "", result, s => null);

            Assert.AreEqual(2, result.Count);
            Assert.AreEqual("A", result[0].UsingItem.Values[0]);
            Assert.AreEqual(3, result[0].Ct);
            Assert.AreEqual("ADetail", result[1].UsingItem.Values[0]);
            Assert.AreEqual(1, result[1].Ct);
        }