Nasty.Operations.QA.QuestionClassifier (Nasty v0.3.0)

View Source

Generic question classification for Question Answering systems.

Classifies questions by interrogative word (who, what, when, where, why, how) and determines expected answer type (person, location, time, etc.).

Language-specific patterns (question words, stop words) are provided via configuration.

Summary

Types

Expected answer type for the question.

Language configuration for question classification.

Question type based on interrogative word.

t()

Functions

Classifies a question from its tokens.

Returns a human-readable description of the question analysis.

Checks if a question expects a specific entity type.

Types

answer_type()

@type answer_type() ::
  :person
  | :location
  | :time
  | :thing
  | :reason
  | :manner
  | :quantity
  | :boolean

Expected answer type for the question.

language_config()

@type language_config() :: %{
  question_words: map(),
  auxiliary_verbs: [String.t()],
  stop_words: [String.t()],
  content_pos_tags: [atom()],
  expects_entity_type?: (answer_type(), atom() -> boolean())
}

Language configuration for question classification.

Required fields:

  • question_words - Map of interrogative words to {type, answer_type}
  • auxiliary_verbs - List of auxiliary verbs for yes/no questions
  • stop_words - Words to exclude from keywords
  • content_pos_tags - POS tags for content words
  • expects_entity_type? - Function to check if answer type expects entity type

question_type()

@type question_type() ::
  :who | :what | :when | :where | :why | :how | :which | :yes_no

Question type based on interrogative word.

t()

@type t() :: %Nasty.Operations.QA.QuestionClassifier{
  answer_type: answer_type(),
  aux_verb: Nasty.AST.Token.t() | nil,
  focus: Nasty.AST.Token.t() | nil,
  keywords: [Nasty.AST.Token.t()],
  type: question_type()
}

Functions

classify(tokens, config, opts \\ [])

@spec classify([Nasty.AST.Token.t()], language_config(), keyword()) ::
  {:ok, t()} | {:error, term()}

Classifies a question from its tokens.

Returns {:ok, analysis} with question type, expected answer type, focus word, and keywords.

describe(question_classifier)

@spec describe(t()) :: String.t()

Returns a human-readable description of the question analysis.

expects_entity_type?(question_classifier, entity_type, config)

@spec expects_entity_type?(t(), atom(), language_config()) :: boolean()

Checks if a question expects a specific entity type.