/// <summary> /// Triggers the action if the score falls between the min and max thresholds /// </summary> /// <param name="score">The score to test</param> /// <param name="crawl">The crawl the scroe is for</param> public void Trigger(double score, PageCrawl crawl) { if (score > min && score < max) { action.Invoke(score, crawl); } }
/// <summary> /// Triggers the action of the rule if the score is greater than or equal to the threshold /// </summary> /// <param name="score">The score to test against the threshold</param> public void Trigger(double score, PageCrawl crawl) { if (score >= threshold) { action.Invoke(score, crawl); } }
/// <summary> /// Score a page using the average of all scores /// Trigger rules with the score and crawl /// </summary> /// <param name="crawl">The crawl to score</param> public void Score(PageCrawl crawl, string comparison) { double score = 0; foreach (IStringComparisonScorer scorePipe in scorers) { score += scorePipe.Score(crawl.Content, comparison); } score = score / (double)scorers.Count; Console.WriteLine(crawl.Page + " scored " + score); foreach (IScoreThresholdRule rule in thresholdActions) { rule.Trigger(score, crawl); } }
/// <summary> /// Handle a new candidate /// Keeps a reference to the crawl and score, if the page is already present in the store then update score to the maximum of both /// </summary> /// <param name="score">The score of the candidate</param> /// <param name="candiate">The candidate</param> public void HandleCandidate(double score, PageCrawl candiate) { // Update existing IEnumerable <CandidateScore> matchingCandidates = candidates.Where(x => x.Candidate.Page.ToString() == candiate.Page.ToString()); if (matchingCandidates.Count() > 0) { CandidateScore existing = matchingCandidates.First(); existing.Score = Math.Max(existing.Score, score); Console.WriteLine("Existing candidate: " + candiate.Page + " - score updated to " + existing.Score); return; } // Add new Console.WriteLine("New candidate: " + candiate.Page + " - " + score); candidates.Add(new CandidateScore(score, candiate)); }
public CandidateScore(double score, PageCrawl candidate) { this.score = score; this.candidate = candidate; }
public Page(Uri uri, Page linkedFrom) { this.uri = uri; this.linkedFrom = linkedFrom; this.crawl = crawl; }