Nasty.AST.Event (Nasty v0.3.0)
View SourceRepresents an event extracted from text.
Events capture actions, occurrences, or states with their participants, temporal information, and location.
Examples
%Event{
trigger: %Token{text: "acquired", lemma: "acquire"},
type: :business_acquisition,
participants: %{
agent: %Entity{text: "Google", type: :org},
patient: %Entity{text: "YouTube", type: :org},
value: "1.65 billion"
},
time: "October 2006",
confidence: 0.85,
language: :en
}
Summary
Functions
Adds a participant to an event.
Filters events by minimum confidence threshold.
Filters events that have a specific participant role.
Filters events by type.
Gets a participant by role.
Creates a new event.
Sorts events by confidence (descending).
Converts an event to a human-readable string.
Gets the text representation of the trigger.
Types
@type event_type() :: :business_acquisition | :business_merger | :product_launch | :employment_start | :employment_end | :company_founding | :meeting | :announcement | :election | :birth | :death | :movement | :transaction | :communication | atom()
@type participant_role() :: :agent | :patient | :theme | :recipient | :beneficiary | :instrument | atom()
@type t() :: %Nasty.AST.Event{ confidence: float(), language: Nasty.AST.Node.language(), location: Nasty.AST.Semantic.Entity.t() | String.t() | nil, metadata: map(), participants: %{ required(participant_role()) => Nasty.AST.Semantic.Entity.t() | String.t() }, span: Nasty.AST.Node.span() | nil, time: String.t() | nil, trigger: Nasty.AST.Token.t() | String.t(), type: event_type() }
Functions
@spec add_participant( t(), participant_role(), Nasty.AST.Semantic.Entity.t() | String.t() ) :: t()
Adds a participant to an event.
Examples
iex> event = Event.new(:business_acquisition, trigger, :en)
iex> Event.add_participant(event, :agent, buyer_entity)
%Event{participants: %{agent: buyer_entity}}
Filters events by minimum confidence threshold.
Examples
iex> Event.filter_by_confidence(events, 0.7)
[%Event{confidence: 0.9}, %Event{confidence: 0.8}]
@spec filter_by_participant([t()], participant_role()) :: [t()]
Filters events that have a specific participant role.
Examples
iex> Event.filter_by_participant(events, :agent)
[%Event{participants: %{agent: ...}}, ...]
@spec filter_by_type([t()], event_type()) :: [t()]
Filters events by type.
Examples
iex> Event.filter_by_type(events, :business_acquisition)
[%Event{type: :business_acquisition}, ...]
@spec get_participant(t(), participant_role()) :: Nasty.AST.Semantic.Entity.t() | String.t() | nil
Gets a participant by role.
Examples
iex> Event.get_participant(event, :agent)
%Entity{text: "Google", type: :org}
iex> Event.get_participant(event, :missing_role)
nil
@spec new( event_type(), Nasty.AST.Token.t() | String.t(), Nasty.AST.Node.language(), keyword() ) :: t()
Creates a new event.
Examples
iex> Event.new(:business_acquisition, trigger, :en)
%Event{type: :business_acquisition, trigger: trigger, language: :en}
iex> Event.new(:business_acquisition, trigger, :en,
...> participants: %{agent: buyer, patient: target},
...> confidence: 0.8
...> )
%Event{type: :business_acquisition, participants: %{agent: ..., patient: ...}, ...}
Sorts events by confidence (descending).
Examples
iex> events = [%Event{confidence: 0.5}, %Event{confidence: 0.9}]
iex> Event.sort_by_confidence(events)
[%Event{confidence: 0.9}, %Event{confidence: 0.5}]
Converts an event to a human-readable string.
Examples
iex> Event.to_string(event)
"business_acquisition: Google acquired YouTube (confidence: 0.85)"
Gets the text representation of the trigger.