예제 #1
0
        private IList <ColumnDefinition> PickLikelyColumns(JsonDocument[] sampleDocuments, string context, IList <PriorityColumn> priorityColumns)
        {
            if (priorityColumns == null || priorityColumns.Count == 0)
            {
                priorityColumns = DefaultPriorityColumns;
            }

            // only consider nested properties if any of the priority columns refers to a nested property
            var includeNestedProperties = priorityColumns.Any(c => c.PropertyNamePattern.Contains("\\."));

            var columns = DocumentHelpers.GetPropertiesFromDocuments(sampleDocuments, includeNestedProperties)
                          .GroupBy(p => p)
                          .Select(g => new { Property = g.Key, Occurence = g.Count() / (double)sampleDocuments.Length })
                          .Select(p => new { p.Property, Importance = p.Occurence + ImportanceBoost(p.Property, context, priorityColumns) })
                          .OrderByDescending(p => p.Importance)
                          .ThenBy(p => p.Property)
                          .Select(p => new ColumnDefinition
            {
                Binding      = p.Property,
                Header       = p.Property,
                DefaultWidth = GetDefaultColumnWidth(p.Property, priorityColumns)
            })
                          .Take(6)
                          .ToList();

            return(columns);
        }
예제 #2
0
        private IList <string> CreateSuggestedBindingsFromDocuments(JsonDocument[] jsonDocuments)
        {
            var bindings = DocumentHelpers.GetPropertiesFromDocuments(jsonDocuments, true).Distinct()
                           .Concat(DocumentHelpers.GetMetadataFromDocuments(jsonDocuments, true).Distinct().Select(b => "$Meta:" + b))
                           .Concat(new[] { "$JsonDocument:Etag", "$JsonDocument:LastModified", "$Temp:Score" })
                           .ToArray();

            return(bindings);
        }