Nasty.AST.Sentence (Nasty v0.3.0)

View Source

Sentence node representing a complete grammatical unit.

A sentence consists of one or more clauses that form a complete thought. Sentences are classified by their function (declarative, interrogative, etc.) and structure (simple, compound, complex, compound-complex).

Summary

Types

Sentence function classification.

Sentence structure classification.

t()

Functions

Returns all clauses in the sentence.

Checks if sentence is a command.

Checks if sentence is complete (not a fragment).

Infers sentence structure from clauses.

Checks if sentence is a question.

Types

sentence_function()

@type sentence_function() ::
  :declarative | :interrogative | :imperative | :exclamative

Sentence function classification.

  • :declarative - Makes a statement ("The cat sat.")
  • :interrogative - Asks a question ("Did the cat sit?")
  • :imperative - Gives a command ("Sit!")
  • :exclamative - Expresses strong emotion ("What a cat!")

sentence_structure()

@type sentence_structure() ::
  :simple | :compound | :complex | :compound_complex | :fragment

Sentence structure classification.

  • :simple - One independent clause
  • :compound - Multiple independent clauses
  • :complex - One independent + dependent clause(s)
  • :compound_complex - Multiple independent + dependent clause(s)
  • :fragment - Incomplete sentence (missing subject or predicate)

t()

@type t() :: %Nasty.AST.Sentence{
  additional_clauses: [Nasty.AST.Clause.t()],
  function: sentence_function(),
  language: Nasty.AST.Node.language(),
  main_clause: Nasty.AST.Clause.t(),
  span: Nasty.AST.Node.span(),
  structure: sentence_structure()
}

Functions

all_clauses(sentence)

@spec all_clauses(t()) :: [Nasty.AST.Clause.t()]

Returns all clauses in the sentence.

Examples

iex> sentence = %Nasty.AST.Sentence{main_clause: main, additional_clauses: [sub1, sub2], ...}
iex> Nasty.AST.Sentence.all_clauses(sentence)
[main, sub1, sub2]

command?(arg1)

@spec command?(t()) :: boolean()

Checks if sentence is a command.

Examples

iex> sentence = %Nasty.AST.Sentence{function: :imperative, ...}
iex> Nasty.AST.Sentence.command?(sentence)
true

complete?(arg1)

@spec complete?(t()) :: boolean()

Checks if sentence is complete (not a fragment).

Examples

iex> sentence = %Nasty.AST.Sentence{structure: :simple, ...}
iex> Nasty.AST.Sentence.complete?(sentence)
true

infer_structure(main_clause, additional_clauses)

@spec infer_structure(Nasty.AST.Clause.t(), [Nasty.AST.Clause.t()]) ::
  sentence_structure()

Infers sentence structure from clauses.

Examples

iex> main = %Nasty.AST.Clause{type: :independent, ...}
iex> Nasty.AST.Sentence.infer_structure(main, [])
:simple

iex> main = %Nasty.AST.Clause{type: :independent, ...}
iex> sub = %Nasty.AST.Clause{type: :subordinate, ...}
iex> Nasty.AST.Sentence.infer_structure(main, [sub])
:complex

new(function, structure, main_clause, language, span, opts \\ [])

Creates a new sentence.

Examples

iex> span = Nasty.AST.Node.make_span({1, 0}, 0, {1, 15}, 15)
iex> clause = %Nasty.AST.Clause{type: :independent, predicate: vp, language: :en, span: span}
iex> sentence = Nasty.AST.Sentence.new(:declarative, :simple, clause, :en, span)
iex> sentence.function
:declarative
iex> sentence.structure
:simple

question?(arg1)

@spec question?(t()) :: boolean()

Checks if sentence is a question.

Examples

iex> sentence = %Nasty.AST.Sentence{function: :interrogative, ...}
iex> Nasty.AST.Sentence.question?(sentence)
true