Skip to main content

GraphExtractor

Trait GraphExtractor 

Source
pub trait GraphExtractor: Send + Sync {
    type NodeData: Clone + Send + Sync;
    type EdgeData: Clone + Send + Sync;

    // Required methods
    fn extract_node(
        &self,
        base_path: &Path,
        file_path: &Path,
        frontmatter: &Value,
        content: &str,
    ) -> Result<Self::NodeData>;
    fn extract_edges(
        &self,
        frontmatter: &Value,
        content: &str,
    ) -> Result<Option<Self::EdgeData>>;
    fn to_graph_node(&self, node_data: &Self::NodeData) -> Node;
    fn to_graph_edges(
        &self,
        from_id: &str,
        edge_data: &Self::EdgeData,
    ) -> Vec<Edge>;

    // Provided methods
    fn content_glob(&self) -> &str { ... }
    fn name(&self) -> &str { ... }
}
Expand description

Trait for extracting graph data from domain-specific content.

Each knowledge domain (music theory, math, etc.) implements this trait to define how its markdown files with frontmatter are transformed into graph nodes and edges.

§Associated Types

  • NodeData: Domain-specific node information (e.g., ConceptCard)
  • EdgeData: Domain-specific relationship information (e.g., RelatedConcepts)

§Lifecycle

For each content file, GraphBuilder calls:

  1. extract_node() - Parse frontmatter + content into NodeData
  2. extract_edges() - Parse relationship data into EdgeData
  3. to_graph_node() - Convert NodeData to generic Node
  4. to_graph_edges() - Convert EdgeData to generic Vec<Edge>

Required Associated Types§

Source

type NodeData: Clone + Send + Sync

Domain-specific node data extracted from content.

Source

type EdgeData: Clone + Send + Sync

Domain-specific edge/relationship data extracted from content.

Required Methods§

Source

fn extract_node( &self, base_path: &Path, file_path: &Path, frontmatter: &Value, content: &str, ) -> Result<Self::NodeData>

Extract node data from a content file.

§Arguments
  • base_path - Root directory for content
  • file_path - Full path to the file being processed
  • frontmatter - Parsed YAML frontmatter as generic Value
  • content - Markdown body (after frontmatter)
Source

fn extract_edges( &self, frontmatter: &Value, content: &str, ) -> Result<Option<Self::EdgeData>>

Extract relationship/edge data from content.

Returns Ok(None) if no relationships found (valid for leaf nodes).

Source

fn to_graph_node(&self, node_data: &Self::NodeData) -> Node

Convert domain node data to a generic graph Node.

Source

fn to_graph_edges(&self, from_id: &str, edge_data: &Self::EdgeData) -> Vec<Edge>

Convert domain edge data to generic graph Edges.

Provided Methods§

Source

fn content_glob(&self) -> &str

Returns the content glob pattern for this domain.

Used by GraphBuilder to discover content files. Default: "**/*.md" (all markdown files recursively).

Source

fn name(&self) -> &str

Returns the name of this extractor for logging/debugging.

Implementors§