#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct Triple {
pub head: String,
pub relation: String,
pub tail: String,
}
impl Triple {
pub fn new(
head: impl Into<String>,
relation: impl Into<String>,
tail: impl Into<String>,
) -> Self {
Self {
head: head.into(),
relation: relation.into(),
tail: tail.into(),
}
}
}
impl From<Triple> for crate::Triple {
fn from(t: Triple) -> Self {
crate::Triple::new(t.head, t.relation, t.tail)
}
}
impl From<crate::Triple> for Triple {
fn from(t: crate::Triple) -> Self {
Self::new(
t.subject().as_str(),
t.predicate().as_str(),
t.object().as_str(),
)
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct TripleIds {
pub head: usize,
pub relation: usize,
pub tail: usize,
}
impl TripleIds {
pub fn new(head: usize, relation: usize, tail: usize) -> Self {
Self {
head,
relation,
tail,
}
}
pub fn as_tuple(&self) -> (usize, usize, usize) {
(self.head, self.relation, self.tail)
}
}