//public Boolean ComputeFeatureScores(WeightDictionary featureScores, SpaceModel space, ILogBuilder log, folderNode folder = null)
        //{



        //    return doAll;

        //}


        /// <summary>
        /// Selects the top <see cref="limit"/> terms, ranked by <see cref="function"/>
        /// </summary>
        /// <param name="space">The space.</param>
        /// <returns></returns>
        public List <KeyValuePair <string, double> > SelectFeatures(SpaceModel space, ILogBuilder log, folderNode folder = null, WeightDictionary featureScores = null)
        {
            Dictionary <String, Double> rank = new Dictionary <string, double>();
            Boolean doAll = false;

            if (limit == -1)
            {
                doAll = true;
            }

            if (featureScores == null)
            {
                featureScores = new WeightDictionary();
            }

            var tokens = space.terms_known_label.GetTokens();

            if (precompiledSelection != null && precompiledSelection.Count > 0)
            {
                log.log("Using precompiled selection filter from [" + outputFilename + "]");
                featureScores.Merge(precompiledSelection);
            }
            else
            {
                WeightModel.PrepareTheModel(space, log);

                featureScores = WeightModel.GetElementFactors(tokens, space);
            }


            if (tokens.Count() <= limit)
            {
                doAll = true;
            }

            if (doAll)
            {
                List <KeyValuePair <string, double> > outAll = new List <KeyValuePair <string, double> >();

                foreach (String tkn in tokens)
                {
                    outAll.Add(new KeyValuePair <string, double>(tkn, 1));
                }
                return(outAll);
            }

            //function.PrepareTheModel(space, log);



            if (!outputFilename.isNullOrEmpty())
            {
                if (folder != null)
                {
                    String p_m = folder.pathFor(outputFilename, imbSCI.Data.enums.getWritableFileMode.none, "", false);
                    featureScores.Save(folder, log, outputFilename);
                    //precompiledSelection = WeightDictionary.LoadFile(p_m, logger);
                }
            }


            foreach (WeightDictionaryEntry en in featureScores.index.Values)
            {
                //   rank.Add(en.name, en.weight);
                Double v = 0;

                if (featureScores.nDimensions > 1)
                {
                    v = en.CompressNumericVector(nVectorValueSelectionOperation);
                }
                else
                {
                    v = en.weight;
                }


                Boolean ok = true;

                if (RemoveZero)
                {
                    if (v == 0)
                    {
                        ok = false;
                    }
                }


                if (ok)
                {
                    rank.Add(en.name, v);
                }
            }

            var rankSorted = rank.OrderByDescending(x => x.Value).ToList();
            List <KeyValuePair <string, double> > top = rankSorted.Take(Math.Min(limit, rankSorted.Count)).ToList();

            return(top);
        }