Nasty.AST.Sentence (Nasty v0.3.0)
View SourceSentence 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
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.
Creates a new sentence.
Checks if sentence is a question.
Types
@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!")
@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)
@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
@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]
Checks if sentence is a command.
Examples
iex> sentence = %Nasty.AST.Sentence{function: :imperative, ...}
iex> Nasty.AST.Sentence.command?(sentence)
true
Checks if sentence is complete (not a fragment).
Examples
iex> sentence = %Nasty.AST.Sentence{structure: :simple, ...}
iex> Nasty.AST.Sentence.complete?(sentence)
true
@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
@spec new( sentence_function(), sentence_structure(), Nasty.AST.Clause.t(), Nasty.AST.Node.language(), Nasty.AST.Node.span(), keyword() ) :: t()
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
Checks if sentence is a question.
Examples
iex> sentence = %Nasty.AST.Sentence{function: :interrogative, ...}
iex> Nasty.AST.Sentence.question?(sentence)
true