pub struct Relation {
pub head: Entity,
pub tail: Entity,
pub relation_type: String,
pub trigger_span: Option<(usize, usize)>,
pub confidence: f64,
}Expand description
A relation between two entities, forming a knowledge graph triple.
In the GLiNER bi-encoder paradigm, relations are detected just like entities: the relation trigger text (“CEO of”, “located in”) is matched against relation type labels in the same latent space.
§Structure
Triple: (Head, Relation, Tail)
"Marie Curie worked at the Sorbonne"
^^^^^^^^^^^ ~~~~~~~~~ ^^^^^^^^
Head Rel Tail
(Person) (Employment) (Organization)§TPLinker/Joint Extraction
For joint extraction, relations are extracted in a single pass with entities.
The trigger_span captures the text that indicates the relation.
Fields§
§head: EntityThe source entity (head of the triple)
tail: EntityThe target entity (tail of the triple)
relation_type: StringRelation type label (e.g., “EMPLOYMENT”, “LOCATED_IN”, “FOUNDED_BY”)
trigger_span: Option<(usize, usize)>Optional trigger span: the text that indicates this relation For “CEO of”, this would be the span covering “CEO of”
confidence: f64Confidence score for this relation (0.0-1.0)
Implementations§
Source§impl Relation
impl Relation
Sourcepub fn new(
head: Entity,
tail: Entity,
relation_type: impl Into<String>,
confidence: f64,
) -> Relation
pub fn new( head: Entity, tail: Entity, relation_type: impl Into<String>, confidence: f64, ) -> Relation
Create a new relation between two entities.
Sourcepub fn with_trigger(
head: Entity,
tail: Entity,
relation_type: impl Into<String>,
trigger_start: usize,
trigger_end: usize,
confidence: f64,
) -> Relation
pub fn with_trigger( head: Entity, tail: Entity, relation_type: impl Into<String>, trigger_start: usize, trigger_end: usize, confidence: f64, ) -> Relation
Create a relation with an explicit trigger span.
Sourcepub fn as_triple(&self) -> String
pub fn as_triple(&self) -> String
Convert to a triple string representation (for debugging/display).
Sourcepub fn span_distance(&self) -> usize
pub fn span_distance(&self) -> usize
Check if the head and tail entities are adjacent (within n tokens). Useful for filtering spurious long-distance relations.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Relation
impl<'de> Deserialize<'de> for Relation
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<Relation, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<Relation, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl Serialize for Relation
impl Serialize for Relation
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 Relation
impl RefUnwindSafe for Relation
impl Send for Relation
impl Sync for Relation
impl Unpin for Relation
impl UnsafeUnpin for Relation
impl UnwindSafe for Relation
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