Nasty.Operations.QA.QuestionClassifier (Nasty v0.3.0)
View SourceGeneric 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.
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
@type answer_type() ::
:person
| :location
| :time
| :thing
| :reason
| :manner
| :quantity
| :boolean
Expected answer type for the question.
@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 questionsstop_words- Words to exclude from keywordscontent_pos_tags- POS tags for content wordsexpects_entity_type?- Function to check if answer type expects entity type
@type question_type() ::
:who | :what | :when | :where | :why | :how | :which | :yes_no
Question type based on interrogative word.
@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
@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.
Returns a human-readable description of the question analysis.
@spec expects_entity_type?(t(), atom(), language_config()) :: boolean()
Checks if a question expects a specific entity type.