Metastatic. NL. AST
(Metastatic v0.33.0)
View Source
M2: Meta-Model for Natural Language Abstract Syntax (NL-MetaAST).
Provides a universal, language-neutral abstract representation for natural language text, sentences, clauses, phrases, and tokens.
Meta-Modeling Hierarchy
- M3: Elixir type system (
@type,@spec) - M2: NL-MetaAST (this module) - defines what natural language AST nodes can be
- M1: Language-specific concrete syntax trees (Tree-sitter English CST, Universal Dependencies, etc.)
- M0: Concrete text utterances and written documents
Uniform 3-Tuple Representation
All NL-MetaAST nodes are uniform 3-element tuples:
{type_atom, keyword_meta, children_or_value}Where:
type_atom- Node kind (e.g.,:document,:sentence,:clause,:phrase,:token)keyword_meta- Keyword list containing metadata (POS, lemma, voice, aspect, line, col, etc.)children_or_value- Either a string/nil (for leaf nodes) or a list of child nodes
Stratification
- M2.1 Core: Universal linguistic units present in all human languages:
:document,:section,:paragraph,:sentence,:clause,:phrase,:token,:punctuation,:coordination,:subordination. - M2.2 Extended: Typological variations and semantic enrichment: Tense, Aspect, Mood, Voice (TAM), grammatical gender/number/case, hedging/weasel tags, semantic frames, and coreference indices.
- M2.3 Native: Language-specific escape hatches via
:native_nl_feature.
Summary
Types
Grammatical aspect
Clause classification
Hedging / weasel classification
An NL-MetaAST node 3-tuple
Phrase syntactic types
Universal POS (Part-of-Speech) tags
Sentence modality / kind
Grammatical tense
Grammatical voice
Functions
Returns the children list or leaf value of an NL node.
Constructs a :clause node.
Extracts all :clause nodes from the tree.
Determines whether an arbitrary term conforms to the NL-MetaAST specification.
Returns whether a node type belongs to the Core (M2.1) layer.
Constructs a :document node.
Returns whether a node type belongs to the Extended (M2.2) layer.
Gets a metadata value by key, returning default if absent.
Extracts all distinct lemmas from the tokens.
Returns the metadata keyword list of an NL node.
Returns whether a node type belongs to the Native (M2.3) layer.
Constructs a :paragraph node.
Path from a matching NL node up to the root, or nil.
Constructs a :phrase composite node.
Extracts all :phrase nodes from the tree.
Post-walk traversal over an NL-MetaAST.
Pre-walk traversal over an NL-MetaAST.
Lazy depth-first pre-order enumerable over an NL-MetaAST.
Lazy pre-order enumerable that threads an accumulator.
Constructs a :punctuation leaf node.
Sets or updates a metadata key.
Constructs a :section node.
Constructs a :sentence node.
Extracts all :sentence nodes from the tree.
Returns the list of all supported NL-MetaAST node types.
Reconstructs readable text from the leaf tokens and punctuation.
Constructs a :token leaf node.
Extracts all :token nodes from the tree.
Traverses an NL-MetaAST depth-first with pre-visit and post-visit functions.
Returns the type atom of an NL node.
Merges a keyword list of metadata updates into the node.
Updates a metadata value with a function.
Extracts all string words from word-like tokens (excluding punctuation).
Types
@type aspect() :: :simple | :progressive | :perfect | :perfect_progressive
Grammatical aspect
@type clause_type() ::
:main | :subordinate | :relative | :conditional | :coordinate | :adverbial
Clause classification
@type hedging() :: :none | :weasel | :tentative | :certain
Hedging / weasel classification
An NL-MetaAST node 3-tuple
@type phrase_type() ::
:noun_phrase
| :verb_phrase
| :prep_phrase
| :adj_phrase
| :adverb_phrase
| :conjunction_phrase
| :interjection_phrase
Phrase syntactic types
@type pos_tag() ::
:noun
| :proper_noun
| :verb
| :adjective
| :adverb
| :pronoun
| :determiner
| :preposition
| :postposition
| :conjunction
| :auxiliary
| :numeral
| :particle
| :symbol
| :punctuation
| :interjection
| :other
Universal POS (Part-of-Speech) tags
@type sentence_kind() :: :declarative | :interrogative | :imperative | :exclamative
Sentence modality / kind
@type tense() :: :present | :past | :future
Grammatical tense
@type voice() :: :active | :passive | :middle
Grammatical voice
Functions
Returns the children list or leaf value of an NL node.
Constructs a :clause node.
Extracts all :clause nodes from the tree.
Determines whether an arbitrary term conforms to the NL-MetaAST specification.
Returns whether a node type belongs to the Core (M2.1) layer.
Constructs a :document node.
Returns whether a node type belongs to the Extended (M2.2) layer.
Gets a metadata value by key, returning default if absent.
Extracts all distinct lemmas from the tokens.
Returns the metadata keyword list of an NL node.
Returns whether a node type belongs to the Native (M2.3) layer.
Constructs a :paragraph node.
@spec path(nl_node(), (nl_node() -> as_boolean(term()))) :: [nl_node()] | nil
Path from a matching NL node up to the root, or nil.
@spec phrase(phrase_type(), [nl_node()], keyword()) :: nl_node()
Constructs a :phrase composite node.
Extracts all :phrase nodes from the tree.
Post-walk traversal over an NL-MetaAST.
Pre-walk traversal over an NL-MetaAST.
@spec prewalker(nl_node()) :: Enumerable.t()
Lazy depth-first pre-order enumerable over an NL-MetaAST.
@spec prewalker(nl_node(), acc, (nl_node(), acc -> {term(), acc})) :: Enumerable.t() when acc: term()
Lazy pre-order enumerable that threads an accumulator.
Constructs a :punctuation leaf node.
Sets or updates a metadata key.
Constructs a :section node.
Constructs a :sentence node.
Extracts all :sentence nodes from the tree.
@spec supported_types() :: [atom()]
Returns the list of all supported NL-MetaAST node types.
Reconstructs readable text from the leaf tokens and punctuation.
Constructs a :token leaf node.
Extracts all :token nodes from the tree.
@spec traverse(nl_node(), acc, (nl_node(), acc -> {nl_node(), acc}), (nl_node(), acc -> {nl_node(), acc})) :: {nl_node(), acc} when acc: term()
Traverses an NL-MetaAST depth-first with pre-visit and post-visit functions.
Delegates to Metastatic.MetaAST.traverse/4, which also visits metadata
values that contain nodes (e.g. a :coreference target).
Returns the type atom of an NL node.
Merges a keyword list of metadata updates into the node.
Updates a metadata value with a function.
Extracts all string words from word-like tokens (excluding punctuation).