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,
) -> Self
pub fn new( head: Entity, tail: Entity, relation_type: impl Into<String>, confidence: f64, ) -> Self
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,
) -> Self
pub fn with_trigger( head: Entity, tail: Entity, relation_type: impl Into<String>, trigger_start: usize, trigger_end: usize, confidence: f64, ) -> Self
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.