Documentation

Linglib.Syntax.DependencyGrammar.Basic

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 #

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 #

structure DependencyGrammar.Graph (n : ) :

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 nMorphology.Word

    The token at each position.

  • label : Fin nFin nOption UD.DepRel

    The UD relation from head v to dependent w, if there is an arc.

  • root : Fin n

    The root position.

Instances For
    theorem DependencyGrammar.Graph.ext {n : } {x y : Graph n} (words : x.words = y.words) (label : x.label = y.label) (root : x.root = y.root) :
    x = y
    theorem DependencyGrammar.Graph.ext_iff {n : } {x y : Graph n} :
    x = y x.words = y.words x.label = y.label x.root = y.root
    def DependencyGrammar.Graph.Adj {n : } (g : Graph n) (v w : Fin n) :

    Adjacency: there is an arc from head v to dependent w.

    Equations
    • g.Adj v w = ((g.label v w).isSome = true)
    Instances For
      @[instance_reducible]
      instance DependencyGrammar.Graph.instDecidableRelFinAdj {n : } (g : Graph n) :
      DecidableRel g.Adj
      Equations
      theorem DependencyGrammar.Graph.adj_iff_exists {n : } {g : Graph n} {v w : Fin n} :
      g.Adj v w ∃ (r : UD.DepRel), g.label v w = some r
      def DependencyGrammar.Graph.Linked {n : } (g : Graph n) (a b : Fin n) :

      Positions linked by an arc in either direction — the undirected view of adjacency.

      Equations
      Instances For
        @[instance_reducible]
        instance DependencyGrammar.Graph.instDecidableLinked {n : } (g : Graph n) (a b : Fin n) :
        Decidable (g.Linked a b)
        Equations
        theorem DependencyGrammar.Graph.Linked.symm {n : } {g : Graph n} {a b : Fin n} (h : g.Linked a b) :
        g.Linked b a

        Views onto mathlib's graph carriers #

        def DependencyGrammar.Graph.toDigraph {n : } (g : Graph n) :
        Digraph (Fin n)

        The graph as a mathlib Digraph on positions.

        Equations
        Instances For
          @[simp]
          theorem DependencyGrammar.Graph.toDigraph_adj {n : } (g : Graph n) (v w : Fin n) :
          g.toDigraph.Adj v w g.Adj v w
          def DependencyGrammar.Graph.toSimpleGraph {n : } (g : Graph n) :
          SimpleGraph (Fin n)

          The graph's undirected view: mathlib's orientation-forgetting Digraph.toSimpleGraphInclusive applied to toDigraph. Planarity and catena connectivity are stated through it.

          Equations
          Instances For
            @[simp]
            theorem DependencyGrammar.Graph.toSimpleGraph_adj {n : } (g : Graph n) (v w : Fin n) :
            g.toSimpleGraph.Adj v w v w g.Linked v w
            @[instance_reducible]
            Equations
            theorem DependencyGrammar.Graph.toSimpleGraph_adj_of_ne {n : } {g : Graph n} {v w : Fin n} (h : v w) :
            g.toSimpleGraph.Adj 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 #

            def DependencyGrammar.Graph.parents {n : } (g : Graph n) (w : Fin n) :
            Finset (Fin n)

            The head positions of w.

            Equations
            Instances For
              def DependencyGrammar.Graph.children {n : } (g : Graph n) (v : Fin n) :
              Finset (Fin n)

              The dependent positions of v.

              Equations
              Instances For
                @[simp]
                theorem DependencyGrammar.Graph.mem_parents {n : } {g : Graph n} {v w : Fin n} :
                v g.parents w g.Adj v w
                @[simp]
                theorem DependencyGrammar.Graph.mem_children {n : } {g : Graph n} {v w : Fin n} :
                w g.children v g.Adj v w

                Constructors #

                def DependencyGrammar.Graph.arcsLabel {n : } (arcs : List (Fin n × Fin n × UD.DepRel)) (v w : Fin n) :
                Option UD.DepRel

                The partial label function induced by a CoNLL-U-style arc list of (head, dependent, relation) triples. First match wins.

                Equations
                Instances For
                  theorem DependencyGrammar.Graph.arcsLabel_isSome_iff {n : } {arcs : List (Fin n × Fin n × UD.DepRel)} {v w : Fin n} :
                  (arcsLabel arcs v w).isSome = true ∃ (r : UD.DepRel), (v, w, r) arcs

                  An arc list labels a pair exactly when some triple mentions it; which relation wins on duplicates is arcsLabel's business, not whether.

                  def DependencyGrammar.Graph.ofArcs (words : List Morphology.Word) (root : Fin words.length) (arcs : List (Fin words.length × Fin words.length × UD.DepRel)) :
                  Graph words.length

                  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
                  Instances For
                    @[simp]
                    theorem DependencyGrammar.Graph.ofArcs_adj {words : List Morphology.Word} {root : Fin words.length} {arcs : List (Fin words.length × Fin words.length × UD.DepRel)} {v w : Fin words.length} :
                    (ofArcs words root arcs).Adj v w ∃ (r : UD.DepRel), (v, w, r) arcs
                    def DependencyGrammar.Graph.enhance {n : } (g : Graph n) (extra : List (Fin n × Fin n × UD.DepRel)) :

                    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
                      @[simp]
                      theorem DependencyGrammar.Graph.enhance_adj {n : } {g : Graph n} {extra : List (Fin n × Fin n × UD.DepRel)} {v w : Fin n} :
                      (g.enhance extra).Adj v w g.Adj v w ∃ (r : UD.DepRel), (v, w, r) extra
                      def DependencyGrammar.HasUnrepresentedArg {n : } (basic enhanced : Graph n) (w : Fin n) :

                      Position w has an argument relation in the enhanced graph that the basic graph fails to encode.

                      Equations
                      Instances For