Esempio n. 1
0
        /// <summary>
        /// Queries table for specified terms and return aggregated score. The score source is specified by <see cref="termTableColumns.tf_idf"/> (only numeric columns are supported).
        /// </summary>
        /// <param name="queryTerms">Terms to test against the table, terms found are used in calculation.</param>
        /// <param name="scoreToUse">What numeric property of matched term to use for aggregation.</param>
        /// <param name="aggregation">The aggregation type</param>
        /// <returns>Any score information from the query terms is ignored.</returns>
        public static double GetScoreForMatch(this IWeightTable table, IEnumerable <string> queryTerms, termTableColumns scoreToUse = termTableColumns.tf_idf, dataPointAggregationType aggregation = dataPointAggregationType.sum)
        {
            List <IWeightTableTerm> output = new List <IWeightTableTerm>();

            output = table.GetMatches(queryTerms);
            return(output.GetScoreAggregate(table, scoreToUse, aggregation));
        }
Esempio n. 2
0
        public static double GetScoreAggregate(this IEnumerable <IWeightTableTerm> terms, IWeightTable table, termTableColumns scoreToUse = termTableColumns.tf_idf, dataPointAggregationType aggregation = dataPointAggregationType.sum)
        {
            List <double> output = new List <double>();

            foreach (IWeightTableTerm term in terms)
            {
                switch (scoreToUse)
                {
                case termTableColumns.cw:
                    output.Add(table.GetWeight(term));
                    break;

                case termTableColumns.df:
                    output.Add(table.GetBDFreq(term));
                    break;

                case termTableColumns.freqAbs:
                    output.Add(table.GetAFreq(term));
                    break;

                case termTableColumns.freqNorm:
                    output.Add(table.GetNFreq(term));
                    break;

                case termTableColumns.idf:
                    output.Add(table.GetIDF(term));
                    break;

                case termTableColumns.ncw:
                    output.Add(table.GetNWeight(term));
                    break;

                case termTableColumns.none:
                    break;

                case termTableColumns.words:
                case termTableColumns.normalizedSemanticDistance:
                case termTableColumns.semanticDistance:
                case termTableColumns.termLemma:
                case termTableColumns.termName:
                    throw new NotImplementedException();
                    break;

                case termTableColumns.tf_idf:
                    output.Add(table.GetTF_IDF(term));
                    break;
                }
            }

            switch (aggregation)
            {
            case dataPointAggregationType.avg:
                return(output.Average());

                break;

            case dataPointAggregationType.count:
                return(output.Count());

                break;

            case dataPointAggregationType.max:
                return(output.Max());

                break;

            case dataPointAggregationType.min:
                return(output.Min());

                break;

            case dataPointAggregationType.range:
                return(output.Max() - output.Min());

                break;

            case dataPointAggregationType.sum:
                return(output.Sum());

                break;

            default:
                throw new dataException("Operation not supported [" + aggregation.toString() + "]", null, table, "Aggregation operation not supported");
                return(0);

                break;
            }

            return(0);
        }