Nasty.AST.Paragraph (Nasty v0.3.0)

View Source

Paragraph node representing a sequence of related sentences.

A paragraph is a unit of text containing one or more sentences that deal with a single topic or idea. Paragraphs provide discourse structure and cohesion markers.

Summary

Functions

Returns the first sentence of the paragraph.

Returns the last sentence of the paragraph.

Counts the number of sentences in the paragraph.

Types

t()

@type t() :: %Nasty.AST.Paragraph{
  language: Nasty.AST.Node.language(),
  sentences: [Nasty.AST.Sentence.t()],
  span: Nasty.AST.Node.span(),
  topic_sentence: Nasty.AST.Sentence.t() | nil
}

Functions

first_sentence(paragraph)

@spec first_sentence(t()) :: Nasty.AST.Sentence.t() | nil

Returns the first sentence of the paragraph.

Often the topic sentence in English writing.

Examples

iex> paragraph = %Nasty.AST.Paragraph{sentences: [s1, s2, s3], ...}
iex> Nasty.AST.Paragraph.first_sentence(paragraph)
s1

last_sentence(paragraph)

@spec last_sentence(t()) :: Nasty.AST.Sentence.t() | nil

Returns the last sentence of the paragraph.

Examples

iex> paragraph = %Nasty.AST.Paragraph{sentences: [s1, s2, s3], ...}
iex> Nasty.AST.Paragraph.last_sentence(paragraph)
s3

new(sentences, language, span, opts \\ [])

Creates a new paragraph.

Examples

iex> span = Nasty.AST.Node.make_span({1, 0}, 0, {5, 0}, 100)
iex> sentences = [s1, s2, s3]
iex> paragraph = Nasty.AST.Paragraph.new(sentences, :en, span)
iex> length(paragraph.sentences)
3

sentence_count(paragraph)

@spec sentence_count(t()) :: non_neg_integer()

Counts the number of sentences in the paragraph.

Examples

iex> paragraph = %Nasty.AST.Paragraph{sentences: [s1, s2, s3], ...}
iex> Nasty.AST.Paragraph.sentence_count(paragraph)
3