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 new() -> GraphDocument
pub fn new() -> GraphDocument
Create an empty graph document.
Sourcepub fn from_extraction(
entities: &[Entity],
relations: &[Relation],
_coref_chains: Option<()>,
) -> GraphDocument
pub fn from_extraction( entities: &[Entity], relations: &[Relation], _coref_chains: Option<()>, ) -> GraphDocument
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,
) -> GraphDocument
pub fn from_entities_cooccurrence( entities: &[Entity], max_distance: usize, ) -> GraphDocument
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>,
) -> GraphDocument
pub fn with_metadata( self, key: impl Into<String>, value: impl Into<Value>, ) -> GraphDocument
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) -> GraphDocument
pub fn from_grounded_document(doc: &GroundedDocument) -> GraphDocument
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 moreSource§impl Debug for GraphDocument
impl Debug for GraphDocument
Source§impl Default for GraphDocument
impl Default for GraphDocument
Source§fn default() -> GraphDocument
fn default() -> GraphDocument
Source§impl<'de> Deserialize<'de> for GraphDocument
impl<'de> Deserialize<'de> for GraphDocument
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<GraphDocument, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<GraphDocument, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl Serialize for GraphDocument
impl Serialize for GraphDocument
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
Auto Trait Implementations§
impl Freeze for GraphDocument
impl RefUnwindSafe for GraphDocument
impl Send for GraphDocument
impl Sync for GraphDocument
impl Unpin for GraphDocument
impl UnsafeUnpin for GraphDocument
impl UnwindSafe for GraphDocument
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more