use super::{CrawlStats, StopCondition, StopReason};
impl StopCondition {
pub(super) fn check_pending_links(&self, stats: &CrawlStats) -> Option<StopReason> {
if stats.pending_links == 0 {
return Some(StopReason::NoPendingLinks);
}
None
}
pub(super) fn check_max_pages(&self, stats: &CrawlStats) -> Option<StopReason> {
if let Some(max) = self.max_pages {
if stats.pages_crawled >= max {
return Some(StopReason::MaxPagesReached {
crawled: stats.pages_crawled,
max,
});
}
}
None
}
pub(super) fn check_confidence(&self, stats: &CrawlStats) -> Option<StopReason> {
if let Some(threshold) = self.min_confidence {
if stats.result.confidence >= threshold {
return Some(StopReason::ConfidenceReached {
confidence: stats.result.confidence,
threshold,
});
}
}
None
}
pub(super) fn check_saturation(&self, stats: &CrawlStats) -> Option<StopReason> {
if let Some(threshold) = self.saturation_threshold {
if stats.result.saturation < threshold {
return Some(StopReason::SaturationReached {
saturation: stats.result.saturation,
threshold,
});
}
}
None
}
pub(super) fn check_coverage(&self, stats: &CrawlStats) -> Option<StopReason> {
if let Some(threshold) = self.min_coverage {
if let Some(coverage) = stats.kg_coverage {
if coverage >= threshold {
return Some(StopReason::CoverageReached {
coverage,
threshold,
});
}
}
}
None
}
}