Dependency graphs #
This file defines the dependency structure of a sentence: the vertices are
the sentence positions Fin n with their linear order, and the arcs are a
partial labeling of ordered position pairs by UD v2 dependency relations.
A distinguished root position replaces CoNLL-U's artificial root token.
Well-formedness (Graph.IsTree) is defined in Dominance.lean, beside
the dominance relation it is stated through.
Main definitions #
Graph nis a dependency graph onnwords: a token at every position, an optional UD relation on every ordered pair of positions (head to dependent), and a root position.Graph.toDigraphandGraph.toSimpleGraphare the directed and undirected views of a graph as mathlib's graph carriers.Graph.enhanceadds arcs to a graph, as in UD's enhanced representation;HasUnrepresentedArgsays that an enhanced graph gives a position an argument relation its basic graph lacks.
Implementation notes #
Positions are 0-indexed; CoNLL-U is 1-indexed with 0 as an artificial
root, so wire-format conversion shifts indices.
label returns at most one relation per ordered pair, faithful to
dependency trees and basic UD. If an enhanced-UD fixture ever needs
parallel arcs on one pair, the field generalizes to a list. Feature-level
constraints (agreement) are Syntax/Agreement/'s domain, not the
carrier's.
References #
[Mel88] — Dependency syntax: theory and practice, source of the arcs-among-ordered-words presentation [KN06] — Mildly non-projective dependency structures, source of the root convention [Kuh13] — Mildly non-projective dependency grammar [dMN19] — Dependency grammar, on UD's enhanced representation
Dependency graphs #
A dependency graph on n words: the sentence's tokens as a labeling of
the positions Fin n, the arcs as a partial labeling of ordered position
pairs (head → dependent) by UD relations, and a distinguished root
position.
- words : Fin n → Morphology.Word
The token at each position.
- label : Fin n → Fin n → Option UD.DepRel
The UD relation from head
vto dependentw, if there is an arc. - root : Fin n
The root position.
Instances For
Equations
- g.instDecidableRelFinAdj x✝¹ x✝ = DependencyGrammar.Graph.instDecidableRelFinAdj._aux_1 g x✝¹ x✝
Equations
Views onto mathlib's graph carriers #
The graph as a mathlib Digraph on positions.
Instances For
The graph's undirected view: mathlib's orientation-forgetting
Digraph.toSimpleGraphInclusive applied to toDigraph. Planarity and
catena connectivity are stated through it.
Equations
- g.toSimpleGraph = g.toDigraph.toSimpleGraphInclusive
Instances For
Equations
- g.instDecidableRelFinAdjToSimpleGraph v w = decidable_of_iff (v ≠ w ∧ g.Linked v w) ⋯
Off the diagonal the two undirected views agree; they can differ only on
self-arcs, which toSimpleGraph drops and Linked keeps.
Heads and dependents #
The head positions of w.
Instances For
The dependent positions of v.
Instances For
Constructors #
The partial label function induced by a CoNLL-U-style arc list of (head, dependent, relation) triples. First match wins.
Equations
- DependencyGrammar.Graph.arcsLabel arcs v w = Option.map (fun (x : Fin n × Fin n × UD.DepRel) => x.2.2) (List.find? (fun (a : Fin n × Fin n × UD.DepRel) => a.1 == v && a.2.1 == w) arcs)
Instances For
An arc list labels a pair exactly when some triple mentions it; which
relation wins on duplicates is arcsLabel's business, not whether.
Build a graph from CoNLL-U-style data: the token list (whose length
fixes n), the root position, and the arcs as
(head, dependent, relation) triples. Later arcs for the same pair are
ignored.
Equations
- DependencyGrammar.Graph.ofArcs words root arcs = { words := words.get, label := DependencyGrammar.Graph.arcsLabel arcs, root := root }
Instances For
Add arcs to a graph (existing labels win), as in UD's enhanced representation: semantic relations the single-headed tree cannot encode — shared dependents in coordination, controlled subjects, relative-clause gaps — become explicit arcs.
Equations
Instances For
Position w has an argument relation in the enhanced graph that the
basic graph fails to encode.
Equations
- DependencyGrammar.HasUnrepresentedArg basic enhanced w = ∃ (v : Fin n), enhanced.Adj v w ∧ ¬basic.Adj v w