Example #1
0
        List<List<WeightedGroupItem>> InitializePermutations(List<WeightedValue> groups)
        {
            PSDebug.Log ("Initialize permutations: {0}", groups.ToDebugString ());
            var templates = new List<List<WeightedGroupItem>> ();
            var numPerms = 1;
            var digits = new int[groups.Count];
            for (int i = 0; i < groups.Count; i++) {
                var item = groups [i];
                var supplements = _supplements (item);
                supplements.ForEach (spm => spm.Weight *= item.Weight);
                numPerms *= digits [i] = supplements.Count;

                templates.Add (supplements);
            }

            var idx = new GenericNumber (digits);
            var perms = new List<List<WeightedGroupItem>> (numPerms);
            for (var i = 0; i < numPerms; ++i) {
                var row = new List<WeightedGroupItem> ();
                perms.Add (row);

                for (var digit = 0; digit < idx.Value.Length; ++digit) {
                    row.Add (templates [digit] [idx.Value [digit]]);
                }

                idx.Incr ();
            }

            return perms;
        }
Example #2
0
        public float TestMatch(List<WeightedGroupItem> groups)
        {
            var result = 0.0f;
            var recipeComponents = new List<WeightedValue> (Groups);
            PSDebug.Log("TestMatch: {1} vs {0}", recipeComponents.ToDebugString(), groups.ToDebugString());
            foreach (var testItem in groups) {
                WeightedValue softMatch = null;
                foreach (var wv in recipeComponents) {
                    var match = wv.Match (testItem);
                    if (match == 2) {
                        recipeComponents.Remove (wv);
                        result += testItem.Weight * wv.Weight;
                        PSDebug.Log("Adding hard match: {0}, result = {1}, item weight = {2}, recipe weight = {3}",
                            testItem.Name, result, testItem.Weight, wv.Weight);
                        softMatch = null;
                        break;
                    } else if (match == 1) {
                        softMatch = wv;
                    }
                }

                if (softMatch != null) {
                    recipeComponents.Remove (softMatch);
                    result += testItem.Weight * softMatch.Weight;
                }
            }

            return recipeComponents.IsEmpty() ? result : 0;
        }
Example #3
0
        private Item[] DoGetNamespacesNamed(string name)
        {
            Profile.Start("AutoComplete::DoGetNamespacesNamed");
            var items = new List<Item>(m_database.GetNamespaces(name));

            string[] names = m_parses.FindNamespaces(name);
            #if DEBUG
            Log.WriteLine(TraceLevel.Verbose, "AutoComplete", "db namespaces: {0}", items.ToDebugString());
            Log.WriteLine(TraceLevel.Verbose, "AutoComplete", "parsed namespaces: {0}", names.ToDebugString());
            #endif

            foreach (string n in names)
            {
                var item = new NameItem(n, name + '.' + n, name + " types");
                items.AddIfMissing(item);
            }

            Profile.Stop("AutoComplete::DoGetNamespacesNamed");
            return items.ToArray();
        }