Documentation

Linglib.Theories.Morphology.FragmentGrammars.CFGFragment

Partial derivation trees (fragments) for context-free grammars #

@cite{odonnell-2015}

A fragment of a context-free grammar g is a partial derivation tree some of whose leaves are nonterminal "open slots" rather than terminal symbols. Fragments are the units of storage in fragment grammars (@cite{odonnell-2015} §2.3.6) and adaptor grammars (§2.3.4): a fragment-grammar analysis of an utterance partitions the full derivation tree into fragments stored in memoized Pitman–Yor tables.

This file provides the partial-tree data type and the embedding from CFGTree (which represents complete derivations only).

Main definitions #

Relation to CFGTree #

CFGTree T N is a derivation tree where every leaf carries a terminal T. CFGFragment T N allows leaves to carry either a terminal T or an open nonterminal N. Every CFGTree embeds as a complete CFGFragment via ofCFGTree; the inverse projection (complete fragment → CFGTree) and the round-trip theorems are deferred to a Phase 3 file when fragment-grammar composition needs them.

References #

inductive CFGFragment (T N : Type) :

A partial derivation tree of a CFG: leaves carry a Symbol T N (terminal or open nonterminal slot); internal nodes carry an N and a list of children.

  • leaf {T N : Type} (s : Symbol T N) : CFGFragment T N

    Leaf carrying either a terminal or an open NT slot.

  • node {T N : Type} (nt : N) (children : List (CFGFragment T N)) : CFGFragment T N

    Internal node with nonterminal label and children.

Instances For
    def CFGFragment.yieldT {T N : Type} :
    CFGFragment T NList T

    Terminal yield, ignoring open NT slots, left to right.

    Equations
    Instances For
      def CFGFragment.yieldTList {T N : Type} :
      List (CFGFragment T N)List T

      Concatenated terminal yields of a list of fragments.

      Equations
      Instances For
        def CFGFragment.yieldNT {T N : Type} :
        CFGFragment T NList N

        The list of open NT slots at the leaves, left to right.

        Equations
        Instances For
          def CFGFragment.yieldNTList {T N : Type} :
          List (CFGFragment T N)List N

          Concatenated open-slot lists of a list of fragments.

          Equations
          Instances For
            def CFGFragment.isComplete {T N : Type} :
            CFGFragment T NBool

            true iff the fragment has no open NT slots — i.e. it is a complete derivation tree.

            Equations
            Instances For
              def CFGFragment.isCompleteList {T N : Type} :
              List (CFGFragment T N)Bool

              true iff every fragment in the list is complete.

              Equations
              Instances For

                Embed a CFGTree (which has only terminal leaves) as a complete CFGFragment.

                Equations
                Instances For
                  def CFGFragment.ofCFGTreeList {T N : Type} :
                  List (CFGTree T N)List (CFGFragment T N)

                  Pointwise lift of ofCFGTree to lists.

                  Equations
                  Instances For
                    theorem CFGFragment.ofCFGTree_isComplete {T N : Type} (t : CFGTree T N) :

                    ofCFGTree always produces a complete fragment.

                    theorem CFGFragment.yieldT_ofCFGTree {T N : Type} (t : CFGTree T N) :

                    Yields agree under the ofCFGTree embedding.

                    theorem CFGFragment.yieldNT_ofCFGTree {T N : Type} (t : CFGTree T N) :

                    The embedding produces no open slots.

                    theorem CFGFragment.yieldNTList_ofCFGTreeList {T N : Type} (ts : List (CFGTree T N)) :

                    List version of yieldNT_ofCFGTree.