/// <summary> /// Scores the specified entry. /// </summary> /// <param name="entry">The entry.</param> /// <param name="context">The context.</param> /// <param name="log">The log.</param> /// <returns></returns> public override double Score(DocumentSelectResultEntry entry, DocumentSelectResult context, ILogBuilder log) { Double score = 0; WebSiteGraph webSiteGraph = context.domainNameToGraph[entry.DomainID]; // GraphRegistry[entry.DomainID]; freeGraphNodeAndLinks outLinks = webSiteGraph.GetLinks(entry.AssignedID, true, false); freeGraphNodeAndLinks inLinks = webSiteGraph.GetLinks(entry.AssignedID, false, true); if (functionFlags.HasFlag(GraphFactorFunctionEnum.count_outbound)) { score += outLinks.Count; } if (functionFlags.HasFlag(GraphFactorFunctionEnum.count_inbound)) { score += inLinks.Count; } if (score == 0) { return(score); } if (functionFlags.HasFlag(GraphFactorFunctionEnum.divide_by_graphlinks)) { score = score / webSiteGraph.CountLinks(); } if (functionFlags.HasFlag(GraphFactorFunctionEnum.divide_by_graphnodes)) { score = score / webSiteGraph.CountNodes(); } if (functionFlags.HasFlag(GraphFactorFunctionEnum.divide_by_inbound)) { score = score / inLinks.Count; } if (functionFlags.HasFlag(GraphFactorFunctionEnum.divide_by_outbound)) { score = score / outLinks.Count; } if (functionFlags.HasFlag(GraphFactorFunctionEnum.divide_by_linkCount)) { score = score / (inLinks.Count + outLinks.Count); } return(score); }
/// <summary> /// Prepares the specified context. /// </summary> /// <param name="context">The context.</param> /// <param name="log">The log.</param> public override void Prepare(DocumentSelectResult context, ILogBuilder log) { var byDomain = context.GetByDomain(log); foreach (var pair in byDomain) { WebSiteGraph webSiteGraph = context.domainNameToGraph[pair.Key]; var matrix = webSiteGraph.GetIDMatrix(scoreUnit); p_matrix.Add(pair.Key, matrix); switch (algorithm) { case GraphFactorAlgorithm.HITS: HITSRank hits = new HITSRank(); hits.recalculate(matrix, convergence, steps); p_hits.Add(pair.Key, hits); break; case GraphFactorAlgorithm.PageRank: var pageRank = new PageRank(matrix.GetMatrix(), alpha, convergence, steps); double[] dbl = pageRank.ComputePageRank(); List <Int32> pri = new List <Int32>(); foreach (Double db in dbl) { pri.Add(Convert.ToInt32(db * scoreUnit)); } var ranks = new Dictionary <String, Int32>(); ranks = matrix.MapToX(pri); p_rank.Add(pair.Key, ranks); break; } } }