private void GenerateDictionaty(SourceGeneratorContext context, INamedTypeSymbol type)
        {
            var structure = new JsonDictionary(type);
            var code      = DictionaryGenerator.Generate(structure);

            context.AddSource($"{type.Name}.Generated.cs", SourceText.From(code, Encoding.UTF8));
        }
Exemplo n.º 2
0
 private void InitializeDictionary()
 {
     if (this.bgDictionary == null || this.bgDictionary.Count == 0)
     {
         var bgDictionaryFilePath = Directory.GetCurrentDirectory() + BG_DICTIONARY_PATH;
         this.bgDictionary = DictionaryGenerator.LoadDictionary(bgDictionaryFilePath, "bg", 0, 1);
     }
 }
Exemplo n.º 3
0
        public void TestYDictionary()
        {
            var data = ShopRiteSalesData.GenerateYMetricsData();

            var typeWrapper = new Pivot.Accessories.Mapping.TypeWrapper <ShopRiteSales, AggregationFunctions>();
            var generator   = new DictionaryGenerator <ShopRiteSales, AggregationFunctions>(typeWrapper);

            var dirY = generator.GenerateYDictionary(data);

            Assert.AreEqual(51, dirY.Count); // expecting exact amount for combinations
        }
Exemplo n.º 4
0
        public void TestXYDictionarySmallSet_CheckOrder()
        {
            var data = SmallDatasets.GenerateFullFlatData();

            var typeWrapper = new Pivot.Accessories.Mapping.TypeWrapper <TwoByTwo, AggregationFunctions>();
            var generator   = new DictionaryGenerator <TwoByTwo, AggregationFunctions>(typeWrapper);

            // checking X
            var dirX = generator.GenerateXDictionary(data);

            Assert.AreEqual(6, dirX.Count); // expecting exact amount for combinations
        }
        public GTFSOrderedEntityCollection(IEnumerable <T> objects)
        {
            Backing = new Dictionary <string, AVLTreeDictionary <int, T> >();
            var backingGen = new DictionaryGenerator <string, AVLTreeDictionary <int, T> >(Backing,
                                                                                           new FuncGenerator <string, AVLTreeDictionary <int, T> >(x => new AVLTreeDictionary <int, T>()));

            Unparsed = new List <GTFSUnparsedEntity>();

            foreach (T item in objects)
            {
                backingGen[item.ID].Add(item.Index, item);
            }
        }
        public GTFSOrderedEntityCollection(IGTFSDataSource source, string tableName, GTFSEntityFactory <T> factory)
        {
            Backing = new Dictionary <string, AVLTreeDictionary <int, T> >();
            var backingGen = new DictionaryGenerator <string, AVLTreeDictionary <int, T> >(Backing,
                                                                                           new FuncGenerator <string, AVLTreeDictionary <int, T> >(x => new AVLTreeDictionary <int, T>()));

            Unparsed = new List <GTFSUnparsedEntity>();

            foreach (T item in source.GetObjects(tableName, factory, Unparsed))
            {
                backingGen[item.ID].Add(item.Index, item);
            }
        }
Exemplo n.º 7
0
        private void SetBudgetRealizationLabel()
        {
            Dictionary <int, string> mon = new Dictionary <int, string>();

            mon = DictionaryGenerator.GetMonths();
            foreach (KeyValuePair <int, string> kvp in mon)
            {
                if (kvp.Key == Month)
                {
                    string temp = "Realizacja budżetu na " + kvp.Value.ToLower() + ":";
                    BudgetRealizationLabel.Content = temp;
                }
            }
        }
        private void GetMonths(int month)
        {
            Dictionary <int, string> mon = new Dictionary <int, string>();

            mon = DictionaryGenerator.GetMonths();
            foreach (KeyValuePair <int, string> kvp in mon)
            {
                MonthComboBox.Items.Add(kvp.Value);
                if (kvp.Key == month)
                {
                    MonthComboBox.SelectedItem = kvp.Value;
                }
            }
        }
        private void MonthComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            string text = (sender as ComboBox).SelectedItem as string;
            Dictionary <int, string> mon = new Dictionary <int, string>();

            mon = DictionaryGenerator.GetMonths();
            foreach (KeyValuePair <int, string> kvp in mon)
            {
                if (kvp.Value == text)
                {
                    Month = kvp.Key;
                    break;
                }
            }
            MonthPlanExist();
        }
Exemplo n.º 10
0
        public void TestXYDictionary()
        {
            var data = ShopRiteSalesData.GenerateFullFlatData();

            var typeWrapper = new Pivot.Accessories.Mapping.TypeWrapper <ShopRiteSales, AggregationFunctions>();
            var generator   = new DictionaryGenerator <ShopRiteSales, AggregationFunctions>(typeWrapper);

            // checking X
            var dirX = generator.GenerateXDictionary(data);

            Assert.AreEqual(82, dirX.Count); // expecting exact amount for combinations

            var dirY = generator.GenerateYDictionary(data);

            Assert.AreEqual(411, dirY.Count); // expecting exact amount for combinations
        }
Exemplo n.º 11
0
        public void TestGenerateXLevelTree()
        {
            var data        = SmallDatasets.GenerateFullFlatData();
            var typeWrapper = new Pivot.Accessories.Mapping.TypeWrapper <TwoByTwo, AggregationFunctions>();
            var generator   = new DictionaryGenerator <TwoByTwo, AggregationFunctions>(typeWrapper);
            SortedDictionary <FieldList, int> dirX = generator.GenerateXDictionary(data);

            int level = 0;
            IEnumerable <AggregationTreeNode> q0 = GenerateAggregationTreeXAnyLevel(dirX, level);
            var lst = q0.ToList();

            Assert.AreEqual(4, lst.Count);

            level = 1;
            IEnumerable <AggregationTreeNode> q1 = GenerateAggregationTreeXAnyLevel(dirX, level);

            lst = q1.ToList();
            Assert.AreEqual(2, lst.Count);
        }
Exemplo n.º 12
0
        private List <string> LookupItemInDictionary(Dictionary <string, int> dictionary, string input, int editDistanceMax)
        {
            List <string>    candidates     = new List <string>();
            HashSet <string> deletesHashset = new HashSet <string>();

            List <SuggestedItem> suggestions        = new List <SuggestedItem>();
            HashSet <string>     suggestionsHashset = new HashSet <string>();

            int initialEditDistanceMax = editDistanceMax;

            int candidatePointer = 0;

            candidates.Add(input);
            while (candidatePointer < candidates.Count)
            {
                string candidate  = candidates[candidatePointer++];
                int    lengthDiff = Math.Min(input.Length, prefixLength) - candidate.Length;

                if ((verbose < 2) && (suggestions.Count > 0) && (lengthDiff > suggestions[0].distance))
                {
                    return(this.GetSortedList(suggestions));
                }

                int value;
                if (dictionary.TryGetValue(candidate, out value))
                {
                    var inputItem = new InputItem();
                    if (value >= 0)
                    {
                        inputItem.suggestions.Add((Int32)value);
                    }
                    else
                    {
                        inputItem = DictionaryGenerator.GetItemsList()[-value - 1];
                    }

                    if (inputItem.appearances > 0)
                    {
                        int distance = input.Length - candidate.Length;

                        if ((distance <= editDistanceMax) &&
                            ((verbose == 2) || (suggestions.Count == 0) || (distance <= suggestions[0].distance)) &&
                            (suggestionsHashset.Add(candidate)))
                        {
                            if ((verbose < 2) && (suggestions.Count > 0) && (suggestions[0].distance > distance))
                            {
                                suggestions.Clear();
                            }

                            var suggestedItem = new SuggestedItem()
                            {
                                word     = candidate,
                                count    = inputItem.appearances,
                                distance = distance
                            };
                            suggestions.Add(suggestedItem);

                            if ((verbose < 2) && (distance == 0))
                            {
                                return(this.GetSortedList(suggestions));
                            }
                        }
                    }

                    foreach (int suggestionInt in inputItem.suggestions)
                    {
                        string suggestion = DictionaryGenerator.GetUniqueWordList()[suggestionInt];

                        int distance = 0;
                        if (suggestion != input)
                        {
                            int min = 0;
                            if (Math.Abs(suggestion.Length - input.Length) > initialEditDistanceMax)
                            {
                                continue;
                            }
                            else if (candidate.Length == 0)
                            {
                                if (!suggestionsHashset.Add(suggestion))
                                {
                                    continue;
                                }

                                distance = Math.Max(input.Length, suggestion.Length);
                            }
                            else
                            if ((prefixLength - editDistanceMax == candidate.Length) && (((min = Math.Min(input.Length, suggestion.Length) - prefixLength) > 1) && (input.Substring(input.Length + 1 - min) != suggestion.Substring(suggestion.Length + 1 - min))) || ((min > 0) && (input[input.Length - min] != suggestion[suggestion.Length - min]) && ((input[input.Length - min - 1] != suggestion[suggestion.Length - min]) || (input[input.Length - min] != suggestion[suggestion.Length - min - 1]))))
                            {
                                continue;
                            }
                            else
                            if ((suggestion.Length == candidate.Length) && (input.Length <= prefixLength))
                            {
                                if (!suggestionsHashset.Add(suggestion))
                                {
                                    continue;
                                }

                                distance = input.Length - candidate.Length;
                            }
                            else if ((input.Length == candidate.Length) && (suggestion.Length <= prefixLength))
                            {
                                if (!suggestionsHashset.Add(suggestion))
                                {
                                    continue;
                                }

                                distance = suggestion.Length - candidate.Length;
                            }
                            else if (suggestionsHashset.Add(suggestion))
                            {
                                distance = EditDistance.DamerauLevenshteinDistance(input, suggestion, initialEditDistanceMax);
                                if (distance < 0)
                                {
                                    distance = editDistanceMax + 1;
                                }
                            }
                            else
                            {
                                continue;
                            }
                        }
                        else if (!suggestionsHashset.Add(suggestion))
                        {
                            continue;
                        }

                        if ((verbose < 2) && (suggestions.Count > 0) && (distance > suggestions[0].distance))
                        {
                            continue;
                        }

                        if (distance <= editDistanceMax)
                        {
                            int value2;
                            if (dictionary.TryGetValue(suggestion, out value2))
                            {
                                var suggestedItem = new SuggestedItem()
                                {
                                    word     = suggestion,
                                    count    = DictionaryGenerator.GetItemsList()[-value2 - 1].appearances,
                                    distance = distance
                                };

                                if (verbose < 2)
                                {
                                    initialEditDistanceMax = distance;
                                }

                                if ((verbose < 2) && (suggestions.Count > 0) && (suggestions[0].distance > distance))
                                {
                                    suggestions.Clear();
                                }

                                suggestions.Add(suggestedItem);
                            }
                        }
                    }
                }

                if (lengthDiff < editDistanceMax)
                {
                    if (candidate.Length > prefixLength)
                    {
                        candidate = candidate.Substring(0, prefixLength);
                    }

                    for (int i = 0; i < candidate.Length; i++)
                    {
                        string delete = candidate.Remove(i, 1);

                        if (deletesHashset.Add(delete))
                        {
                            candidates.Add(delete);
                        }
                    }
                }
            }

            return(this.GetSortedList(suggestions));
        }
Exemplo n.º 13
0
        public Dictionary <string, JsonPath.Node> Dictionary(string key = null, string lang = null, string path = null, DictionaryGenerator data = null, Dictionary <string, DictionaryGenerator> i18n = null)
        {
            var    text = GetData(key, lang);
            string err  = "";

            if (!string.IsNullOrEmpty(text))
            {
                try {
                    var node = JsonPath.Node.FromJson(text);
                    if (string.IsNullOrEmpty(path))
                    {
                        return(node);
                    }
                    var child = ChildByPath(node, path);
                    if (child != null)
                    {
                        return(child.Dictionary);
                    }
                } catch (Exception ex) {
                    err = ex.Message;
                }
            }

            if (data != null)
            {
                return(data());
            }

            if (i18n != null)
            {
                if (i18n.TryGetValue(_lang, out var i18nData))
                {
                    return(i18nData());
                }
            }

            return(new JsonPath.Dictionary()
            {
                ["error"] = FormatError(key, lang, path, err)
            });
        }
Exemplo n.º 14
0
 public PivotGenerator(TypeWrapper <T, TAggregator> t)
 {
     _typeWrapper         = t;
     _dictionaryGenerator = new DictionaryGenerator <T, TAggregator>(t);
 }