示例#1
0
        private static double CalculatePLdcgIntent(ResultMetadata result)
        {
            if (result.IsPopularityIntent == 1)
            {
                double score = 0;
                if (result.IntentJudgment == 1)
                {
                    score = 0.722328375279349;
                }
                else if (result.IntentJudgment == 2)
                {
                    score = 0.231394025352752;
                }

                if (score > 0)
                {
                    score += 0.1967974035372131 * result.metric["popularscore"];
                    score += 0.0178954605522934 * result.metric["reviewscore"];
                    score += 0.0629787606311446 * result.metric["urlscore"];
                }

                return(score);
            }

            else
            {
                return(CalculateL3dcgIntent(result));
            }
        }
        public static Dictionary <string, List <ResultMetadata> > ReadResultMetadata(string fileName)
        {
            var resultSet = new Dictionary <string, List <ResultMetadata> >();

            var lines  = File.ReadAllLines(fileName);
            var schema = lines[0].Split('\t');

            for (int i = 1; i < lines.Length; i++)
            {
                var result     = new ResultMetadata(lines[i], schema);
                var entityGuid = result.EntityGuid;

                if (!resultSet.ContainsKey(entityGuid))
                {
                    resultSet.Add(entityGuid, new List <ResultMetadata> {
                        result
                    });
                }
                else
                {
                    resultSet[entityGuid].Add(result);
                }
            }

            foreach (var resultList in resultSet.Values)
            {
                var newList = resultList.OrderBy(s => s.Position).ToList();
                resultList.Clear();
                resultList.AddRange(newList);
            }

            return(resultSet);
        }
示例#3
0
        private static double CalDistanceMatchScore(ResultMetadata result, QueryMetadata query)
        {
            double outterCircle = result.ManualOuterRadius;

            if (!string.IsNullOrWhiteSpace(result.FinalTargetLocationOption) && result.FinalTargetLocationOption == "UserLocation")
            {
                outterCircle = Math.Max(outterCircle, 45);
            }

            double distance = CalDistance(result, query);

            if (distance <= result.ManualInnerRadius)
            {
                return(1);
            }

            if (distance > outterCircle)
            {
                return(0);
            }

            distance -= result.ManualInnerRadius;
            double range = outterCircle - result.ManualInnerRadius;  // range > 0 ALWAYS due to above logic

            return(1 - Math.Sqrt(distance / range));
        }
示例#4
0
        private static double CalDistance(ResultMetadata result, QueryMetadata query)
        {
            double lat1  = query.FinalLat;
            double long1 = query.FinalLong;
            double lat2  = result.Lat;
            double long2 = result.Long;

            return(HaversineDistanceCalculator.GetHaversineDistanceInMiles(lat1, long1, lat2, long2));
        }
示例#5
0
        private static double CalIntentMatchScore(ResultMetadata result)
        {
            if (result.IntentJudgment == 1)
            {
                return(0.822328375279349);
            }
            else if (result.IntentJudgment == 2)
            {
                return(0.311394025352752);
            }

            return(0);
        }
示例#6
0
        private static double CalculateL3dcgIntent(ResultMetadata result)
        {
            double score = result.metric["matchscore"];

            if (score > 0)
            {
                score += 0.0567974035372131 * result.metric["popularscore"];
                score += 0.0478954605522934 * result.metric["reviewscore"];
                score += 0.0729787606311446 * result.metric["urlscore"];
            }

            return(score);
        }
示例#7
0
        static void Main(string[] args)
        {
            if (string.Compare(args[0], "metric", true) == 0)
            {
                var querySet  = QueryMetadata.ReadQueryMetadata(args[1]);
                var resultSet = ResultMetadata.ReadResultMetadata(args[2]);

                // remove result set which entity id is not in query set
                resultSet = ResultMetadata.TrimResultSet(resultSet, querySet);

                var metricList = new List <string>();
                for (int i = 6; i < args.Length; i++)
                {
                    var metricName  = args[i].ToLower();
                    var metricValue = MetricCalculator.CalculateMetric(metricName, querySet, resultSet);
                    metricList.Add(metricName);
                    Console.WriteLine("{0}: {1}", metricName, Math.Round(metricValue, 4));
                }

                MetricLogger.GenerateAnalysisReport(args[3], querySet, resultSet, metricList);
                MetricLogger.OutputQueryMetadata(args[4], querySet, metricList);
                MetricLogger.OutputEntityMetadata(args[5], querySet, resultSet, metricList);
                MetricLogger.GenerateQuerySetAnalysis(args[1], querySet);
                MetricLogger.GenerateEntitySetAnalysis(resultSet);
            }
            else if (args[0].StartsWith("removejunk"))
            {
                var querySet  = QueryMetadata.ReadQueryMetadata(args[1]);
                var resultSet = ResultMetadata.ReadResultMetadata(args[2]);
                JunkFilter.DemoteJunk(args[0], querySet, resultSet);
                MetricLogger.OutputEntityMetadata(args[3], querySet, resultSet, new List <string>());
            }
            else if (string.Compare(args[0], "trim", true) == 0)
            {
                var querySet  = QueryMetadata.ReadQueryMetadata(args[1]);
                var resultSet = ResultMetadata.ReadResultMetadata(args[2]);
                JunkFilter.TrimResult(resultSet);
                MetricLogger.OutputEntityMetadata(args[3], querySet, resultSet, new List <string>());
            }
            else if (string.Compare(args[0], "statjunk", true) == 0)
            {
                var querySet  = QueryMetadata.ReadQueryMetadata(args[1]);
                var resultSet = ResultMetadata.ReadResultMetadata(args[2]);
                MetricLogger.StatisticJunk(args[3], querySet, resultSet);
            }
            else if (string.Compare(args[0], "createsbs", true) == 0)
            {
                var querySet   = QueryMetadata.ReadQueryMetadata(args[1]);
                var resultSet1 = ResultMetadata.ReadResultMetadata(args[2]);
                var resultSet2 = ResultMetadata.ReadResultMetadata(args[3]);
                Dictionary <string, List <ResultMetadata> > refSet = null;
                if (args.Length > 5)
                {
                    refSet = ResultMetadata.ReadResultMetadata(args[4]);
                }

                var folderPrefix = args.Last();

                List <string> htmlList = new List <string>();
                htmlList.Add("SideBySideHtml");
                foreach (var query in querySet)
                {
                    if (resultSet1.ContainsKey(query.EntityGuid) && resultSet2.ContainsKey(query.EntityGuid))
                    {
                        string key1 = string.Concat(resultSet1[query.EntityGuid].Select(s => s.EngineEntityId));
                        string key2 = string.Concat(resultSet2[query.EntityGuid].Select(s => s.EngineEntityId));
                        if (key1 != key2)
                        {
                            var    html  = SBSHtml.GetSideBySideHtml(query.Text, "LEFT", "RIGHT", "REFERENCE", resultSet1[query.EntityGuid], resultSet2[query.EntityGuid], refSet == null || !refSet.ContainsKey(query.EntityGuid) ? null : refSet[query.EntityGuid]);
                            string fname = folderPrefix + query.EntityGuid + ".html";
                            File.WriteAllText(fname, html);
                            htmlList.Add(html);
                        }
                    }
                }

                Console.WriteLine("queryCount:{0}, set1Count:{1}, set2Count:{2}, diffCount:{3}",
                                  querySet.Count, resultSet1.Count, resultSet2.Count, htmlList.Count - 1);
                File.WriteAllLines(folderPrefix + "0000.uhrsupload.tsv", htmlList);
            }
        }
示例#8
0
        private static double CalLineDistanceInnerRatio(ResultMetadata result, QueryMetadata queryMetadata)
        {
            double distance = CalDistance(result, queryMetadata);

            return(distance / Math.Max(1, result.ManualInnerRadius));
        }
示例#9
0
        private static double CalLineDistanceInnerScore(ResultMetadata result, QueryMetadata queryMetadata)
        {
            double distance = CalDistance(result, queryMetadata);

            return(Math.Max(distance - result.ManualInnerRadius, 0));
        }
示例#10
0
 private static double CalLineDistanceScore(ResultMetadata result, QueryMetadata queryMetadata)
 {
     return(CalDistance(result, queryMetadata));
 }
示例#11
0
        private static void CalculateResultLevelMetric(string metricName, QueryMetadata queryMetadata, ResultMetadata result)
        {
            if (result.metric.ContainsKey(metricName))
            {
                return;
            }

            double metricScore = 0;

            if (metricName == "matchscore")
            {
                metricScore = CalIntentMatchScore(result);
            }

            else if (metricName == "popularscore")
            {
                metricScore = result.Popularity / 100000.0;
            }

            else if (metricName == "distancescore")
            {
                metricScore = CalDistanceMatchScore(result, queryMetadata);
            }

            else if (metricName == "linedistance")
            {
                metricScore = CalLineDistanceScore(result, queryMetadata);
            }

            else if (metricName == "linedistance2")
            {
                metricScore = CalLineDistanceScore(result, queryMetadata);
                if (queryMetadata.ManualInnerRadius > 20)
                {
                    metricScore = -1;;
                }
            }

            else if (metricName == "linedistance3")
            {
                metricScore = CalLineDistanceScore(result, queryMetadata);
                if (metricScore > 100)
                {
                    metricScore = -1;;
                }
            }

            else if (metricName == "linedistanceinner")
            {
                metricScore = CalLineDistanceInnerScore(result, queryMetadata);
            }

            else if (metricName == "distanceinnerratio")
            {
                metricScore = CalLineDistanceInnerRatio(result, queryMetadata);
            }

            else if (metricName == "urlscore")
            {
                metricScore = string.IsNullOrWhiteSpace(result.Url) ? 0 : 1;
            }

            else if (metricName == "reviewscore")
            {
                metricScore = (result.ReviewCount > 3 || result.Rating > 0) ? 1 : 0;
            }

            else if (metricName == "nojunkscore")
            {
                metricScore = (result.ReviewCount > 3 || result.Rating > 0 || !string.IsNullOrWhiteSpace(result.Url)) ? 1 : 0;
            }

            else if (metricName == "l3dcgrelevance")
            {
                CalculateResultLevelMetric("matchscore", queryMetadata, result);
                CalculateResultLevelMetric("popularscore", queryMetadata, result);
                CalculateResultLevelMetric("urlscore", queryMetadata, result);
                CalculateResultLevelMetric("reviewscore", queryMetadata, result);
                metricScore = CalculateL3dcgIntent(result);
            }

            else if (metricName == "pldcgrelevance")
            {
                CalculateResultLevelMetric("l3dcgrelevance", queryMetadata, result);
                metricScore = CalculatePLdcgIntent(result);
            }

            else if (metricName.StartsWith("l3dcg"))
            {
                CalculateResultLevelMetric("l3dcgrelevance", queryMetadata, result);
                CalculateResultLevelMetric("distancescore", queryMetadata, result);

                metricScore = result.metric["l3dcgrelevance"] * result.metric["distancescore"] * 100;
                metricName  = "l3dcg";
            }

            else if (metricName.StartsWith("pldcg"))
            {
                CalculateResultLevelMetric("pldcgrelevance", queryMetadata, result);
                CalculateResultLevelMetric("distancescore", queryMetadata, result);

                metricScore = result.metric["pldcgrelevance"] * result.metric["distancescore"] * 100;
                metricName  = "pldcg";
            }

            if (!result.metric.ContainsKey(metricName))
            {
                result.metric.Add(metricName, metricScore);
            }
        }