pub struct GraphDocument {
pub nodes: Vec<GraphNode>,
pub edges: Vec<GraphEdge>,
pub metadata: HashMap<String, Value>,
}Expand description
A complete graph document ready for export.
Fields§
§nodes: Vec<GraphNode>Nodes (entities)
edges: Vec<GraphEdge>Edges (relations)
metadata: HashMap<String, Value>Document metadata
Implementations§
Source§impl GraphDocument
impl GraphDocument
Sourcepub fn from_extraction(
entities: &[Entity],
relations: &[Relation],
_coref_chains: Option<()>,
) -> Self
pub fn from_extraction( entities: &[Entity], relations: &[Relation], _coref_chains: Option<()>, ) -> Self
Build graph document from NER/IE extraction results.
§Arguments
entities- Extracted entities (should havecanonical_idset if coref was run)relations- Extracted relations between entitiescoref_chains- Optional coreference chains for canonical mention resolution
§Returns
A GraphDocument with deduplicated nodes (by canonical_id) and edges.
Sourcepub fn from_entities_cooccurrence(
entities: &[Entity],
max_distance: usize,
) -> Self
pub fn from_entities_cooccurrence( entities: &[Entity], max_distance: usize, ) -> Self
Build graph from entities only, inferring co-occurrence relations.
Uses a simple heuristic: entities within max_distance characters
are considered related. This is useful when no explicit relation
extraction was performed.
Sourcepub fn to_networkx_json(&self) -> String
pub fn to_networkx_json(&self) -> String
Export to NetworkX-compatible JSON format.
This format can be loaded directly with:
import networkx as nx
import json
with open('graph.json') as f:
data = json.load(f)
G = nx.node_link_graph(data)Sourcepub fn to_json_ld(&self) -> String
pub fn to_json_ld(&self) -> String
Export to JSON-LD format (for semantic web applications).
Sourcepub fn with_metadata(
self,
key: impl Into<String>,
value: impl Into<Value>,
) -> Self
pub fn with_metadata( self, key: impl Into<String>, value: impl Into<Value>, ) -> Self
Add metadata to the graph document.
Sourcepub fn node_count(&self) -> usize
pub fn node_count(&self) -> usize
Get node count.
Sourcepub fn edge_count(&self) -> usize
pub fn edge_count(&self) -> usize
Get edge count.
Sourcepub fn from_grounded_document(doc: &GroundedDocument) -> Self
pub fn from_grounded_document(doc: &GroundedDocument) -> Self
Build graph document from a GroundedDocument.
Converts the Signal → Track → Identity hierarchy to a graph format suitable for RAG applications (Neo4j, NetworkX, etc.).
§Arguments
doc- The GroundedDocument to convert
§Returns
A GraphDocument with nodes from entities and edges inferred from co-occurrence or track relationships.
§Example
use anno_core::grounded::GroundedDocument;
use anno_core::graph::GraphDocument;
let doc = GroundedDocument::new("doc1", "Marie Curie won the Nobel Prize.");
// ... add signals, tracks, identities ...
let graph = GraphDocument::from_grounded_document(&doc);
println!("{}", graph.to_cypher());Source§impl GraphDocument
impl GraphDocument
Sourcepub fn export(&self, format: GraphExportFormat) -> String
pub fn export(&self, format: GraphExportFormat) -> String
Export to the specified format.
Trait Implementations§
Source§impl Clone for GraphDocument
impl Clone for GraphDocument
Source§fn clone(&self) -> GraphDocument
fn clone(&self) -> GraphDocument
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more