Skip to main content

GraphDocument

Struct GraphDocument 

Source
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

Source

pub fn new() -> Self

Create an empty graph document.

Source

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 have canonical_id set if coref was run)
  • relations - Extracted relations between entities
  • coref_chains - Optional coreference chains for canonical mention resolution
§Returns

A GraphDocument with deduplicated nodes (by canonical_id) and edges.

Source

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.

Source

pub fn to_cypher(&self) -> String

Export to Neo4j Cypher CREATE statements.

Source

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)
Source

pub fn to_json_ld(&self) -> String

Export to JSON-LD format (for semantic web applications).

Source

pub fn with_metadata( self, key: impl Into<String>, value: impl Into<Value>, ) -> Self

Add metadata to the graph document.

Source

pub fn node_count(&self) -> usize

Get node count.

Source

pub fn edge_count(&self) -> usize

Get edge count.

Source

pub fn is_empty(&self) -> bool

Check if graph is empty.

Source

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

Source

pub fn export(&self, format: GraphExportFormat) -> String

Export to the specified format.

Trait Implementations§

Source§

impl Clone for GraphDocument

Source§

fn clone(&self) -> GraphDocument

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for GraphDocument

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for GraphDocument

Source§

fn default() -> GraphDocument

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for GraphDocument

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for GraphDocument

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,