pub struct AdjacencyGraph {
pub entity_to_idx: HashMap<String, usize>,
pub idx_to_entity: Vec<String>,
pub adjacency: Vec<Vec<usize>>,
pub edge_features: Vec<Vec<f64>>,
}Expand description
Adjacency graph built from RDF triples.
Each unique subject or object string is mapped to a dense integer index.
The adjacency list adjacency[i] stores the indices of all nodes reachable
from node i by following any predicate. Edge features encode a simple
hash of the predicate string, normalised to [0, 1].
Fields§
§entity_to_idx: HashMap<String, usize>Map from entity string to its integer index
idx_to_entity: Vec<String>Inverse: index → entity string
adjacency: Vec<Vec<usize>>adjacency[i] = list of neighbour indices for node i
edge_features: Vec<Vec<f64>>edge_features[i] = list of scalar features for each edge leaving node i
(one-to-one correspondence with adjacency[i])
Implementations§
Source§impl AdjacencyGraph
impl AdjacencyGraph
Sourcepub fn from_triples(triples: &[(String, String, String)]) -> Self
pub fn from_triples(triples: &[(String, String, String)]) -> Self
Build an AdjacencyGraph from a slice of (subject, predicate, object) triples.
Duplicate entities are deduplicated; duplicate edges are preserved (they represent multiple predicates between the same entity pair).
Sourcepub fn neighbors(&self, idx: usize) -> &[usize]
pub fn neighbors(&self, idx: usize) -> &[usize]
Return the neighbour indices of node idx.
Returns an empty slice for out-of-range indices.
Sourcepub fn entity_count(&self) -> usize
pub fn entity_count(&self) -> usize
Return the total number of unique entities (nodes) in the graph.
Sourcepub fn entity_name(&self, idx: usize) -> Option<&str>
pub fn entity_name(&self, idx: usize) -> Option<&str>
Look up the string label for a given node index.
Returns None if the index is out of range.
Sourcepub fn entity_index(&self, name: &str) -> Option<usize>
pub fn entity_index(&self, name: &str) -> Option<usize>
Look up the integer index for a given entity string.
Returns None if the entity is not in the graph.
Trait Implementations§
Source§impl Clone for AdjacencyGraph
impl Clone for AdjacencyGraph
Source§fn clone(&self) -> AdjacencyGraph
fn clone(&self) -> AdjacencyGraph
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for AdjacencyGraph
impl RefUnwindSafe for AdjacencyGraph
impl Send for AdjacencyGraph
impl Sync for AdjacencyGraph
impl Unpin for AdjacencyGraph
impl UnsafeUnpin for AdjacencyGraph
impl UnwindSafe for AdjacencyGraph
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> ErasedDestructor for Twhere
T: 'static,
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