Nasty.Language.English.SemanticRoleLabeler (Nasty v0.3.0)

View Source

Semantic Role Labeling (SRL) for English.

Thin wrapper around generic SRL modules with English-specific configuration. Extracts predicate-argument structure from sentences by mapping syntactic dependencies to semantic roles (Agent, Patient, Theme, etc.).

Examples

iex> alias Nasty.Language.English.{Tokenizer, POSTagger, SentenceParser}
iex> {:ok, tokens} = Tokenizer.tokenize("John gave Mary a book.")
iex> {:ok, tagged} = POSTagger.tag_pos(tokens)
iex> {:ok, analyzed} = Morphology.analyze(tagged)
iex> {:ok, sentences} = SentenceParser.parse_sentences(analyzed)
iex> sentence = List.first(sentences)
iex> {:ok, frames} = SemanticRoleLabeler.label(sentence)
iex> frame = List.first(frames)
iex> frame.predicate.text
"gave"
iex> Enum.map(frame.roles, & &1.type)
[:agent, :patient, :recipient]

Summary

Functions

Labels semantic roles for all predicates in a sentence.

Labels semantic roles for a single clause.

Functions

label(sentence, opts \\ [])

@spec label(
  Nasty.AST.Sentence.t(),
  keyword()
) :: {:ok, [Nasty.AST.Semantic.Frame.t()]} | {:error, term()}

Labels semantic roles for all predicates in a sentence.

Returns a list of semantic frames, one per predicate (main verb).

Examples

iex> {:ok, frames} = SemanticRoleLabeler.label(sentence)
iex> is_list(frames)
true

label_clause(clause)

@spec label_clause(Nasty.AST.Clause.t()) :: [Nasty.AST.Semantic.Frame.t()]

Labels semantic roles for a single clause.

Delegates to generic labeler with English configuration.