use super::super::types::*;
use super::graph::KnowledgeGraph;
impl KnowledgeGraph {
pub fn get_component(&self, name: &str) -> Option<&StackComponent> {
self.components.get(name)
}
pub fn components(&self) -> impl Iterator<Item = &StackComponent> {
self.components.values()
}
pub fn component_names(&self) -> impl Iterator<Item = &String> {
self.components.keys()
}
pub fn components_in_layer(&self, layer: StackLayer) -> Vec<&StackComponent> {
self.components
.values()
.filter(|c| c.layer == layer)
.collect()
}
pub fn find_by_capability(&self, capability: &str) -> Vec<&StackComponent> {
self.capability_index
.get(capability)
.map(|names| {
names
.iter()
.filter_map(|n| self.components.get(n))
.collect()
})
.unwrap_or_default()
}
pub fn find_by_domain(&self, domain: ProblemDomain) -> Vec<&StackComponent> {
self.domain_capabilities
.get(&domain)
.map(|caps| {
caps.iter()
.flat_map(|cap| self.find_by_capability(cap))
.collect::<Vec<_>>()
})
.unwrap_or_default()
}
pub fn integrations_from(&self, component: &str) -> Vec<&IntegrationPattern> {
self.integrations
.iter()
.filter(|p| p.from == component)
.collect()
}
pub fn integrations_to(&self, component: &str) -> Vec<&IntegrationPattern> {
self.integrations
.iter()
.filter(|p| p.to == component)
.collect()
}
pub fn get_integration(&self, from: &str, to: &str) -> Option<&IntegrationPattern> {
self.integrations
.iter()
.find(|p| p.from == from && p.to == to)
}
pub fn all_capabilities(&self) -> impl Iterator<Item = &String> {
self.capability_index.keys()
}
pub fn component_count(&self) -> usize {
self.components.len()
}
pub fn capability_count(&self) -> usize {
self.capability_index.len()
}
pub fn integration_count(&self) -> usize {
self.integrations.len()
}
}