Beispiel #1
0
                public override Explanation Explain(int doc)
                {
                    ComplexExplanation result         = new ComplexExplanation();
                    Explanation        nonPayloadExpl = base.Explain(doc);

                    result.AddDetail(nonPayloadExpl);
                    //QUESTION: Is there a wau to avoid this skipTo call?  We need to know whether to load the payload or not

                    Explanation payloadBoost = new Explanation();

                    result.AddDetail(payloadBoost);

                    /*
                     * if (skipTo(doc) == true) {
                     * processPayload();
                     * }*/

                    float avgPayloadScore = (payloadsSeen > 0 ? (payloadScore / payloadsSeen) : 1);

                    payloadBoost.SetValue(avgPayloadScore);
                    //GSI: I suppose we could toString the payload, but I don't think that would be a good idea
                    payloadBoost.SetDescription("scorePayload(...)");
                    result.SetValue(nonPayloadExpl.GetValue() * avgPayloadScore);
                    result.SetDescription("btq, product of:");
                    result.SetMatch(nonPayloadExpl.GetValue() == 0 ? false : true); // LUCENE-1303
                    return(result);
                }
Beispiel #2
0
        public override Explanation Explain(int doc)
        {
            Explanation tfExplanation = new Explanation();

            int expDoc = Advance(doc);

            float phraseFreq = (expDoc == doc)?freq:0.0f;

            tfExplanation.SetValue(GetSimilarity().Tf(phraseFreq));
            tfExplanation.SetDescription("tf(phraseFreq=" + phraseFreq + ")");

            return(tfExplanation);
        }
            public override Explanation Explain(int doc)
            {
                Explanation result         = new Explanation();
                Explanation nonPayloadExpl = base.Explain(doc);

                result.AddDetail(nonPayloadExpl);
                Explanation payloadBoost = new Explanation();

                result.AddDetail(payloadBoost);
                float avgPayloadScore = (payloadsSeen > 0?(payloadScore / payloadsSeen):1);

                payloadBoost.SetValue(avgPayloadScore);
                payloadBoost.SetDescription("scorePayload(...)");
                result.SetValue(nonPayloadExpl.GetValue() * avgPayloadScore);
                result.SetDescription("bnq, product of:");
                return(result);
            }
Beispiel #4
0
        public double Score(Rectangle indexRect, Explanation exp)
        {
            double score;

            if (indexRect == null)
            {
                score = nullValue;
            }
            else
            {
                score = distCalc.Distance(queryPoint, indexRect.GetCenter());
            }
            if (exp != null)
            {
                exp.SetValue((float)score);
                exp.SetDescription(GetType().Name);
                exp.AddDetail(new Explanation(-1f, "" + queryPoint));
                exp.AddDetail(new Explanation(-1f, "" + indexRect));
            }
            return(score);
        }
Beispiel #5
0
        public override Explanation Explain(IndexReader reader, int doc)
        {
            ComplexExplanation result = new ComplexExplanation();

            result.SetDescription("weight(" + GetQuery() + " in " + doc + "), product of:");
            System.String field = ((SpanQuery)GetQuery()).GetField();

            Explanation idfExpl = new Explanation(idf, "idf(" + field + ": " + idfExp.Explain() + ")");

            // explain query weight
            Explanation queryExpl = new Explanation();

            queryExpl.SetDescription("queryWeight(" + GetQuery() + "), product of:");

            Explanation boostExpl = new Explanation(GetQuery().GetBoost(), "boost");

            if (GetQuery().GetBoost() != 1.0f)
            {
                queryExpl.AddDetail(boostExpl);
            }
            queryExpl.AddDetail(idfExpl);

            Explanation queryNormExpl = new Explanation(queryNorm, "queryNorm");

            queryExpl.AddDetail(queryNormExpl);

            queryExpl.SetValue(boostExpl.GetValue() * idfExpl.GetValue() * queryNormExpl.GetValue());

            result.AddDetail(queryExpl);

            // explain field weight
            ComplexExplanation fieldExpl = new ComplexExplanation();

            fieldExpl.SetDescription("fieldWeight(" + field + ":" + query.ToString(field) + " in " + doc + "), product of:");

            Explanation tfExpl = Scorer(reader, true, false).Explain(doc);

            fieldExpl.AddDetail(tfExpl);
            fieldExpl.AddDetail(idfExpl);

            Explanation fieldNormExpl = new Explanation();

            byte[] fieldNorms = reader.Norms(field);
            float  fieldNorm  = fieldNorms != null?Similarity.DecodeNorm(fieldNorms[doc]) : 1.0f;

            fieldNormExpl.SetValue(fieldNorm);
            fieldNormExpl.SetDescription("fieldNorm(field=" + field + ", doc=" + doc + ")");
            fieldExpl.AddDetail(fieldNormExpl);

            fieldExpl.SetMatch(tfExpl.IsMatch());
            fieldExpl.SetValue(tfExpl.GetValue() * idfExpl.GetValue() * fieldNormExpl.GetValue());

            result.AddDetail(fieldExpl);
            System.Boolean?tempAux = fieldExpl.GetMatch();
            result.SetMatch(tempAux);

            // combine them
            result.SetValue(queryExpl.GetValue() * fieldExpl.GetValue());

            if (queryExpl.GetValue() == 1.0f)
            {
                return(fieldExpl);
            }

            return(result);
        }
        public virtual Explanation Explain(IndexReader reader, int doc)
        {
            ComplexExplanation result = new ComplexExplanation();

            result.SetDescription("weight(" + GetQuery() + " in " + doc + "), product of:");
            System.String field = ((SpanQuery)GetQuery()).GetField();

            System.Text.StringBuilder      docFreqs = new System.Text.StringBuilder();
            System.Collections.IEnumerator i        = terms.GetEnumerator();
            while (i.MoveNext())
            {
                System.Collections.DictionaryEntry tmp = (System.Collections.DictionaryEntry)i.Current;
                Term term = (Term)tmp.Key;
                docFreqs.Append(term.Text());
                docFreqs.Append("=");
                docFreqs.Append(reader.DocFreq(term));

                if (i.MoveNext())
                {
                    docFreqs.Append(" ");
                }
            }

            Explanation idfExpl = new Explanation(idf, "idf(" + field + ": " + docFreqs + ")");

            // explain query weight
            Explanation queryExpl = new Explanation();

            queryExpl.SetDescription("queryWeight(" + GetQuery() + "), product of:");

            Explanation boostExpl = new Explanation(GetQuery().GetBoost(), "boost");

            if (GetQuery().GetBoost() != 1.0f)
            {
                queryExpl.AddDetail(boostExpl);
            }
            queryExpl.AddDetail(idfExpl);

            Explanation queryNormExpl = new Explanation(queryNorm, "queryNorm");

            queryExpl.AddDetail(queryNormExpl);

            queryExpl.SetValue(boostExpl.GetValue() * idfExpl.GetValue() * queryNormExpl.GetValue());

            result.AddDetail(queryExpl);

            // explain field weight
            ComplexExplanation fieldExpl = new ComplexExplanation();

            fieldExpl.SetDescription("fieldWeight(" + field + ":" + query.ToString(field) + " in " + doc + "), product of:");

            Explanation tfExpl = Scorer(reader).Explain(doc);

            fieldExpl.AddDetail(tfExpl);
            fieldExpl.AddDetail(idfExpl);

            Explanation fieldNormExpl = new Explanation();

            byte[] fieldNorms = reader.Norms(field);
            float  fieldNorm  = fieldNorms != null?Similarity.DecodeNorm(fieldNorms[doc]) : 0.0f;

            fieldNormExpl.SetValue(fieldNorm);
            fieldNormExpl.SetDescription("fieldNorm(field=" + field + ", doc=" + doc + ")");
            fieldExpl.AddDetail(fieldNormExpl);

            fieldExpl.SetMatch(tfExpl.IsMatch());
            fieldExpl.SetValue(tfExpl.GetValue() * idfExpl.GetValue() * fieldNormExpl.GetValue());

            result.AddDetail(fieldExpl);
            System.Boolean tempAux = fieldExpl.GetMatch();
            result.SetMatch(tempAux);

            // combine them
            result.SetValue(queryExpl.GetValue() * fieldExpl.GetValue());

            if (queryExpl.GetValue() == 1.0f)
            {
                return(fieldExpl);
            }

            return(result);
        }
Beispiel #7
0
        public double Score(Rectangle target, Explanation exp)
        {
            if (target == null || queryArea <= 0)
            {
                return(0);
            }
            double targetArea = target.GetArea(null);

            if (targetArea <= 0)
            {
                return(0);
            }
            double score = 0;

            double top    = Math.Min(queryExtent.GetMaxY(), target.GetMaxY());
            double bottom = Math.Max(queryExtent.GetMinY(), target.GetMinY());
            double height = top - bottom;
            double width  = 0;

            // queries that cross the date line
            if (queryExtent.GetCrossesDateLine())
            {
                // documents that cross the date line
                if (target.GetCrossesDateLine())
                {
                    double left  = Math.Max(queryExtent.GetMinX(), target.GetMinX());
                    double right = Math.Min(queryExtent.GetMaxX(), target.GetMaxX());
                    width = right + 360.0 - left;
                }
                else
                {
                    double qryWestLeft  = Math.Max(queryExtent.GetMinX(), target.GetMaxX());
                    double qryWestRight = Math.Min(target.GetMaxX(), 180.0);
                    double qryWestWidth = qryWestRight - qryWestLeft;
                    if (qryWestWidth > 0)
                    {
                        width = qryWestWidth;
                    }
                    else
                    {
                        double qryEastLeft  = Math.Max(target.GetMaxX(), -180.0);
                        double qryEastRight = Math.Min(queryExtent.GetMaxX(), target.GetMaxX());
                        double qryEastWidth = qryEastRight - qryEastLeft;
                        if (qryEastWidth > 0)
                        {
                            width = qryEastWidth;
                        }
                    }
                }
            }
            else
            {             // queries that do not cross the date line
                if (target.GetCrossesDateLine())
                {
                    double tgtWestLeft  = Math.Max(queryExtent.GetMinX(), target.GetMinX());
                    double tgtWestRight = Math.Min(queryExtent.GetMaxX(), 180.0);
                    double tgtWestWidth = tgtWestRight - tgtWestLeft;
                    if (tgtWestWidth > 0)
                    {
                        width = tgtWestWidth;
                    }
                    else
                    {
                        double tgtEastLeft  = Math.Max(queryExtent.GetMinX(), -180.0);
                        double tgtEastRight = Math.Min(queryExtent.GetMaxX(), target.GetMaxX());
                        double tgtEastWidth = tgtEastRight - tgtEastLeft;
                        if (tgtEastWidth > 0)
                        {
                            width = tgtEastWidth;
                        }
                    }
                }
                else
                {
                    double left  = Math.Max(queryExtent.GetMinX(), target.GetMinX());
                    double right = Math.Min(queryExtent.GetMaxX(), target.GetMaxX());
                    width = right - left;
                }
            }


            // calculate the score
            if ((width > 0) && (height > 0))
            {
                double intersectionArea = width * height;
                double queryRatio       = intersectionArea / queryArea;
                double targetRatio      = intersectionArea / targetArea;
                double queryFactor      = Math.Pow(queryRatio, queryPower);
                double targetFactor     = Math.Pow(targetRatio, targetPower);
                score = queryFactor * targetFactor * 10000.0;

                if (exp != null)
                {
                    //        StringBuilder sb = new StringBuilder();
                    //        sb.append("\nscore=").append(score);
                    //        sb.append("\n  query=").append();
                    //        sb.append("\n  target=").append(target.toString());
                    //        sb.append("\n  intersectionArea=").append(intersectionArea);
                    //
                    //        sb.append(" queryArea=").append(queryArea).append(" targetArea=").append(targetArea);
                    //        sb.append("\n  queryRatio=").append(queryRatio).append(" targetRatio=").append(targetRatio);
                    //        sb.append("\n  queryFactor=").append(queryFactor).append(" targetFactor=").append(targetFactor);
                    //        sb.append(" (queryPower=").append(queryPower).append(" targetPower=").append(targetPower).append(")");

                    exp.SetValue((float)score);
                    exp.SetDescription(GetType().Name);

                    Explanation e = null;

                    exp.AddDetail(e = new Explanation((float)intersectionArea, "IntersectionArea"));
                    e.AddDetail(new Explanation((float)width, "width; Query: " + queryExtent));
                    e.AddDetail(new Explanation((float)height, "height; Target: " + target));

                    exp.AddDetail(e = new Explanation((float)queryFactor, "Query"));
                    e.AddDetail(new Explanation((float)queryArea, "area"));
                    e.AddDetail(new Explanation((float)queryRatio, "ratio"));
                    e.AddDetail(new Explanation((float)queryPower, "power"));

                    exp.AddDetail(e = new Explanation((float)targetFactor, "Target"));
                    e.AddDetail(new Explanation((float)targetArea, "area"));
                    e.AddDetail(new Explanation((float)targetRatio, "ratio"));
                    e.AddDetail(new Explanation((float)targetPower, "power"));
                }
            }
            else if (exp != null)
            {
                exp.SetValue(0);
                exp.SetDescription("Shape does not intersect");
            }
            return(score);
        }