Nasty.AST.Document (Nasty v0.3.0)
View SourceDocument node representing the root of the AST.
A document is the top-level structure containing one or more paragraphs. It represents an entire text unit (article, email, book chapter, etc.) with metadata about the source and language.
Summary
Functions
Returns all sentences in the document (flattened).
Returns the first paragraph of the document.
Creates a new document.
Counts total number of paragraphs.
Counts total number of sentences across all paragraphs.
Types
Document metadata.
Optional information about the document:
title- Document titleauthor- Author name(s)date- Creation/modification datesource- Original source (URL, file path, etc.)- Custom fields as needed
@type t() :: %Nasty.AST.Document{ coref_chains: [Nasty.AST.Semantic.CorefChain.t()] | nil, language: Nasty.AST.Node.language(), metadata: metadata(), paragraphs: [Nasty.AST.Paragraph.t()], semantic_frames: [Nasty.AST.Semantic.Frame.t()] | nil, span: Nasty.AST.Node.span() }
Functions
@spec all_sentences(t()) :: [Nasty.AST.Sentence.t()]
Returns all sentences in the document (flattened).
Examples
iex> doc = %Nasty.AST.Document{paragraphs: [p1, p2], ...}
iex> sentences = Nasty.AST.Document.all_sentences(doc)
iex> is_list(sentences)
true
@spec first_paragraph(t()) :: Nasty.AST.Paragraph.t() | nil
Returns the first paragraph of the document.
Examples
iex> doc = %Nasty.AST.Document{paragraphs: [p1, p2], ...}
iex> Nasty.AST.Document.first_paragraph(doc)
p1
@spec new( [Nasty.AST.Paragraph.t()], Nasty.AST.Node.language(), Nasty.AST.Node.span(), keyword() ) :: t()
Creates a new document.
Examples
iex> span = Nasty.AST.Node.make_span({1, 0}, 0, {100, 0}, 5000)
iex> paragraphs = [p1, p2, p3]
iex> doc = Nasty.AST.Document.new(paragraphs, :en, span)
iex> length(doc.paragraphs)
3
iex> doc = Nasty.AST.Document.new(paragraphs, :en, span,
...> metadata: %{title: "My Essay", author: "Jane Doe"})
iex> doc.metadata.title
"My Essay"
@spec paragraph_count(t()) :: non_neg_integer()
Counts total number of paragraphs.
Examples
iex> doc = %Nasty.AST.Document{paragraphs: [p1, p2, p3], ...}
iex> Nasty.AST.Document.paragraph_count(doc)
3
@spec sentence_count(t()) :: non_neg_integer()
Counts total number of sentences across all paragraphs.
Examples
iex> doc = %Nasty.AST.Document{paragraphs: [p1, p2, p3], ...}
iex> Nasty.AST.Document.sentence_count(doc)
10