pub struct KGDataset {
pub triples: Vec<(usize, usize, usize)>,
pub n_entities: usize,
pub n_relations: usize,
pub entity_labels: Vec<String>,
pub relation_labels: Vec<String>,
}Expand description
A collection of (head, relation, tail) triples for a knowledge graph.
Entities and relations are referenced by their integer indices. Use
KGDataset::from_str_triples to build a dataset from string labels
automatically.
Fields§
§triples: Vec<(usize, usize, usize)>All triples as (head_idx, rel_idx, tail_idx)
n_entities: usizeNumber of distinct entities
n_relations: usizeNumber of distinct relation types
entity_labels: Vec<String>Entity index → string label
relation_labels: Vec<String>Relation index → string label
Implementations§
Source§impl KGDataset
impl KGDataset
Sourcepub fn new(
triples: Vec<(usize, usize, usize)>,
n_entities: usize,
n_relations: usize,
) -> Result<Self>
pub fn new( triples: Vec<(usize, usize, usize)>, n_entities: usize, n_relations: usize, ) -> Result<Self>
Build a KGDataset from raw integer triples.
§Arguments
triples– Vec of(head, relation, tail)triples.n_entities– Total number of entities (must exceed all indices).n_relations– Total number of relation types.
Sourcepub fn from_str_triples(triples: &[(&str, &str, &str)]) -> Self
pub fn from_str_triples(triples: &[(&str, &str, &str)]) -> Self
Build a dataset from string-labeled triples.
Entity and relation vocabularies are inferred from the data in the order they are first encountered.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for KGDataset
impl RefUnwindSafe for KGDataset
impl Send for KGDataset
impl Sync for KGDataset
impl Unpin for KGDataset
impl UnsafeUnpin for KGDataset
impl UnwindSafe for KGDataset
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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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>
Converts
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>
Converts
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