Nasty.AST.Relation (Nasty v0.3.0)
View SourceRepresents a semantic relation between two entities.
Relations capture structured information like employment ("works_at"), organization structure ("founded"), location ("located_in"), etc.
Examples
%Relation{
type: :works_at,
subject: %Entity{text: "John Smith", type: :person},
object: %Entity{text: "Google", type: :org},
confidence: 0.9,
evidence: "John Smith works at Google",
span: {{1, 1}, {1, 30}},
language: :en
}
Summary
Functions
Filters relations by minimum confidence threshold.
Filters relations by type.
Returns the inverse of a relation type.
Inverts a relation (swaps subject and object, inverts type).
Creates a new relation.
Gets the text representation of object.
Sorts relations by confidence (descending).
Gets the text representation of subject.
Converts a relation to a human-readable string.
Types
@type relation_type() :: :works_at | :employed_by | :founded | :acquired_by | :subsidiary_of | :located_in | :based_in | :headquarters_in | :born_in | :educated_at | :member_of | :ceo_of | :part_of | :occurred_on | :founded_in | atom()
@type t() :: %Nasty.AST.Relation{ confidence: float(), evidence: String.t() | nil, language: Nasty.AST.Node.language(), metadata: map(), object: Nasty.AST.Semantic.Entity.t() | String.t(), span: Nasty.AST.Node.span() | nil, subject: Nasty.AST.Semantic.Entity.t() | String.t(), type: relation_type() }
Functions
Filters relations by minimum confidence threshold.
Examples
iex> Relation.filter_by_confidence(relations, 0.7)
[%Relation{confidence: 0.9}, %Relation{confidence: 0.8}]
@spec filter_by_type([t()], relation_type()) :: [t()]
Filters relations by type.
Examples
iex> Relation.filter_by_type(relations, :works_at)
[%Relation{type: :works_at}, ...]
@spec inverse_type(relation_type()) :: relation_type()
Returns the inverse of a relation type.
Examples
iex> Relation.inverse_type(:works_at)
:employed_by
iex> Relation.inverse_type(:founded)
:founded_by
Inverts a relation (swaps subject and object, inverts type).
Examples
iex> relation = Relation.new(:works_at, john, google, :en)
iex> Relation.invert(relation)
%Relation{type: :employed_by, subject: google, object: john}
@spec new( relation_type(), Nasty.AST.Semantic.Entity.t() | String.t(), Nasty.AST.Semantic.Entity.t() | String.t(), Nasty.AST.Node.language(), keyword() ) :: t()
Creates a new relation.
Examples
iex> Relation.new(:works_at, subject, object, :en)
%Relation{type: :works_at, subject: subject, object: object, language: :en}
iex> Relation.new(:works_at, subject, object, :en, confidence: 0.8)
%Relation{type: :works_at, confidence: 0.8, ...}
Gets the text representation of object.
Sorts relations by confidence (descending).
Examples
iex> relations = [%Relation{confidence: 0.5}, %Relation{confidence: 0.9}]
iex> Relation.sort_by_confidence(relations)
[%Relation{confidence: 0.9}, %Relation{confidence: 0.5}]
Gets the text representation of subject.
Converts a relation to a human-readable string.
Examples
iex> Relation.to_string(relation)
"John Smith works_at Google (confidence: 0.9)"