Beispiel #1
0
        public IEnumerable <FactBaseQueryResult> EnumerateResults(FactsPartsDictionary FactsOfParts, int ix, IList <int> data, FactBaseQuery currentquery, bool skipinitialfiltering = false)
        {
            var items = data;

            //CurrentLength = GetDictFilterCount();
            if (ix == 0)
            {
                currentquery = new FactBaseQuery();
                currentquery.DictFilterIndexes = this.DictFilterIndexes;
                if (DictFilterIndexes.Count > 0 && !skipinitialfiltering)
                {
                    items = FactsOfParts.SearchFactsIndexByKey(DictFilterIndexes.ToArray(), data);
                }
                foreach (var negativeindex in NegativeDictFilterIndexes)
                {
                    if (FactsOfParts.ContainsKey(negativeindex))
                    {
                        items = Utilities.Objects.SortedExcept(items, FactsOfParts[negativeindex]);
                    }
                }
            }

            if (Pools.Count == 0)
            {
                var result = new FactBaseQueryResult();
                result.Items = items;
                result.Query = currentquery;
                yield return(result);

                yield break;
            }

            if (ix == Pools.Count)
            {
                var result = new FactBaseQueryResult();
                result.Items = data;
                result.Query = currentquery;
                yield return(result);
            }
            else
            {
                foreach (var qry in Pools[ix].ChildQueries)
                {
                    var subresult = qry.ToIntervalList(FactsOfParts, items);
                    var subquery  = new FactBaseQuery();
                    FactBaseQuery.BaseMerge(currentquery, subquery);
                    FactBaseQuery.BaseMerge(qry, subquery);
                    foreach (var x in EnumerateResults(FactsOfParts, ix + 1, subresult, subquery))
                    {
                        yield return(x);
                    }
                }
            }
        }
Beispiel #2
0
        public void AddChildQuery(FactBaseQuery qry)
        {
            if (qry != this)
            {
                qry.Parent = this;

                if (!ChildQueries.Contains(qry))
                {
                    ChildQueries.Add(qry);
                }
            }
        }
Beispiel #3
0
        public FactBaseQuery Copy()
        {
            var result = new FactBaseQuery();

            result.DictFilterIndexes         = this.DictFilterIndexes.ToArray().ToList();
            result.NegativeDictFilterIndexes = this.NegativeDictFilterIndexes.ToArray().ToList();
            foreach (var childquery in ChildQueries)
            {
                result.AddChildQuery(childquery.Copy());
            }
            return(result);
        }
Beispiel #4
0
 public static void MergeQueries(FactBaseQuery target, FactBaseQuery source)
 {
     target.DictFilterIndexes         = target.DictFilterIndexes.Concat(source.DictFilterIndexes).Distinct().ToList();
     target.NegativeDictFilterIndexes = target.NegativeDictFilterIndexes.Concat(source.NegativeDictFilterIndexes).Distinct().ToList();
     foreach (var sourcechild in source.ChildQueries)
     {
         var sourcechildcs = sourcechild.GetCompareString();
         var targetchild   = target.ChildQueries.FirstOrDefault(i => i.GetCompareString() == sourcechildcs);
         if (targetchild == null)
         {
             target.ChildQueries.Add(sourcechild);
         }
     }
 }
Beispiel #5
0
        public static void Merge(FactBaseQuery source, FactBaseQuery target)
        {
            target.TrueFilters  = target.TrueFilters + source.TrueFilters;
            target.FalseFilters = target.FalseFilters + source.FalseFilters;
            target.DictFilters  = target.DictFilters + source.DictFilters;
            target.DictFilterIndexes.AddRange(source.DictFilterIndexes);
            target.NegativeDictFilterIndexes.AddRange(source.NegativeDictFilterIndexes);
            target.ChildQueries = source.ChildQueries;
            var originalfilter = target.Filter;

            target.Filter = null;
            target.Cover  = source.Cover;
            target.Filter = (s) => originalfilter(s) && source.Filter(s);
        }
Beispiel #6
0
        public static FactBaseQuery GetCommonQuery(params FactBaseQuery[] queries)
        {
            if (queries.Length == 0)
            {
                return(null);
            }

            var result = queries[0];

            for (int i = 1; i < queries.Length; i++)
            {
                result = FactBaseQuery.GetCommon(result, queries[i]);
            }

            return(result);
        }
Beispiel #7
0
        public static void RemoveQuery(FactBaseQuery from, FactBaseQuery item)
        {
            from.DictFilterIndexes         = from.DictFilterIndexes.Except(item.DictFilterIndexes).ToList();
            from.NegativeDictFilterIndexes = from.NegativeDictFilterIndexes.Except(item.NegativeDictFilterIndexes).ToList();
            var childqueries = from.ChildQueries.ToArray().ToList();

            foreach (var childquery in childqueries)
            {
                var itemcs = childquery.GetCompareString();

                var bchildquery = item.ChildQueries.FirstOrDefault(i => i.GetCompareString() == itemcs);
                if (bchildquery != null)
                {
                    from.ChildQueries.Remove(childquery);
                }
            }
        }
Beispiel #8
0
        public static FactBaseQuery GetCommon(FactBaseQuery a, FactBaseQuery b)
        {
            var common_dfs  = a.DictFilterIndexes.Intersect(b.DictFilterIndexes).ToList();
            var common_ndfs = a.NegativeDictFilterIndexes.Intersect(b.NegativeDictFilterIndexes).ToList();
            var qry         = new FactBaseQuery();

            qry.DictFilterIndexes         = common_dfs;
            qry.NegativeDictFilterIndexes = common_ndfs;
            foreach (var achildquery in a.ChildQueries)
            {
                var acs         = achildquery.GetCompareString();
                var bchildquery = b.ChildQueries.FirstOrDefault(i => i.GetCompareString() == acs);
                if (bchildquery != null)
                {
                    qry.ChildQueries.Add(achildquery.Copy());
                }
            }
            return(qry);
        }
Beispiel #9
0
 //public IEnumerable<IList<int>> EnumerateIntervals(Taxonomy taxonomy, int ix, IList<int> data)
 //{
 //    if (ix == Items.Count) { yield return data; }
 //    foreach (var qry in Items[ix])
 //    {
 //        var subresult = qry.ToIntervalList(taxonomy, data);
 //        EnumerateIntervals(taxonomy, ix + 1, subresult);
 //    }
 //}
 public void Remove(FactBaseQuery childquery)
 {
     this.ChildQueries.Remove(childquery);
     childquery.ClearParent();
 }
Beispiel #10
0
 internal void ClearParent()
 {
     this.Parent = null;
 }
Beispiel #11
0
        public static FactBaseQuery GetQuery(string filterstring, Dictionary <string, int> factparts)
        {
            var factstrings = filterstring.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
            //TODO
            IList <int> idlist = new List <int>();
            var         keys   = new List <int>();
            var         qry    = new FactBaseQuery();

            foreach (var fs in factstrings)
            {
                var ors = fs.Split(new string[] { "|" }, StringSplitOptions.RemoveEmptyEntries);
                if (ors.Length == 1)
                {
                    var oritem     = ors.FirstOrDefault();
                    var isnegative = false;
                    if (oritem.StartsWith("!"))
                    {
                        isnegative = true;
                        oritem     = oritem.Substring(1);
                    }
                    oritem = oritem.Trim();
                    if (factparts.ContainsKey(oritem))
                    {
                        qry.AddIndex(factparts[oritem], isnegative);
                    }
                    else
                    {
                        var partkeys = factparts.Keys.Where(i => i.IndexOf(oritem, StringComparison.InvariantCultureIgnoreCase) > -1).ToList();
                        if (partkeys.Count > 0)
                        {
                            if (isnegative)
                            {
                                foreach (var partkey in partkeys)
                                {
                                    var partqry = new FactBaseQuery();
                                    qry.AddIndex(factparts[partkey], isnegative);
                                }
                            }
                            else
                            {
                                var qrypool = new FactPoolQuery();
                                foreach (var partkey in partkeys)
                                {
                                    var partqry = new FactBaseQuery();
                                    partqry.AddIndex(factparts[partkey], isnegative);
                                    qrypool.AddChildQuery(partqry);
                                }
                                qry.AddChildQuery(qrypool);
                            }
                        }
                        else
                        {
                            qry.DictFilterIndexes.Add(-1);
                        }
                    }
                }
                else
                {
                    var qrypool    = new FactPoolQuery();
                    var isnegative = false;

                    for (int i = 0; i < ors.Length; i++)
                    {
                        var oritem = ors[i];
                        if (oritem.StartsWith("!"))
                        {
                            isnegative = true;
                            oritem     = oritem.Substring(1);
                        }
                        oritem = oritem.Trim();
                        FactBaseQuery subquery = null;
                        if (factparts.ContainsKey(oritem))
                        {
                            subquery = new FactBaseQuery();
                            subquery.AddIndex(factparts[oritem], isnegative);
                        }
                        else
                        {
                            var partkeys = factparts.Keys.Where(k => k.IndexOf(oritem, StringComparison.InvariantCultureIgnoreCase) > -1).ToList();
                            if (partkeys.Count > 0 && !String.IsNullOrEmpty(oritem))
                            {
                                if (isnegative)
                                {
                                    subquery = new FactBaseQuery();

                                    foreach (var partkey in partkeys)
                                    {
                                        var partqry = new FactBaseQuery();
                                        subquery.AddIndex(factparts[partkey], isnegative);
                                    }
                                }
                                else
                                {
                                    subquery = new FactPoolQuery();
                                    foreach (var partkey in partkeys)
                                    {
                                        var partqry = new FactBaseQuery();
                                        partqry.AddIndex(factparts[partkey], isnegative);
                                        subquery.AddChildQuery(partqry);
                                    }
                                }
                            }
                            else
                            {
                                qry.DictFilterIndexes.Add(-1);
                            }
                        }
                        qrypool.AddChildQuery(subquery);
                    }
                    qry.AddChildQuery(qrypool);
                }
            }
            if (!qry.HasFilters())
            {
                return(null);
            }
            else
            {
                return(qry);
            }
        }
Beispiel #12
0
 public static void BaseMerge(FactBaseQuery source, FactBaseQuery target)
 {
     target.DictFilterIndexes.AddRange(source.DictFilterIndexes.Except(target.DictFilterIndexes));
     target.NegativeDictFilterIndexes.AddRange(source.NegativeDictFilterIndexes.Except(target.NegativeDictFilterIndexes));
 }