Documentation

Linglib.Data.Examples.Readers

Reading example data #

This file defines the lookups a study makes on the rows of Data/Examples/, the Datums of Data/Examples/Schema.lean, and the statements it makes by fitting a prediction to them. A reader Datum → Option α reads a value off a row; a fit compares a prediction about that value with the row's judgment, through the three bands of the severity order of judgments, or with its truth-value verdict, and a check bundles the fit over a cluster of rows with the number of rows the reader reads, so that the fit cannot go silently vacuous.

Main definitions #

Main statements #

Implementation notes #

inductive Judgment.Band :

The three bands of the severity order that a prediction targets: the unmarked judgment, the middle marks ? and %, on which speakers or grammars divide, and the rejected marks ??, # and *. Which mark a paper prints within a band is its editorial choice, not a prediction.

Instances For
    @[instance_reducible]
    instance Judgment.instDecidableEqBand :
    DecidableEq Band
    Equations
    def Judgment.instReprBand.repr :
    Band → ℕ → Std.Format
    Equations
    Instances For
      @[instance_reducible]
      Equations
      def Judgment.Band.ofProp (p : Prop) [Decidable p] :

      The band of a two-way prediction: accepted where p holds and rejected where it fails.

      Equations
      Instances For
        def Datum.digits? (cs : List Char) :
        Option ℕ

        digits? cs is the number that the nonempty string of decimal digits cs denotes.

        Equations
        • Datum.digits? cs = if cs ≠ [] ∧ cs.all Char.isDigit = true then some (List.foldl (fun (n : ℕ) (c : Char) => 10 * n + (c.toNat - '0'.toNat)) 0 cs) else none
        Instances For
          def Datum.surfaceTokens (e : Datum) :
          List String

          e.surfaceTokens is the Analyzed_Word column, the words of e.glossedTokens.

          Equations
          Instances For
            def Datum.glossLine (e : Datum) :
            List String

            e.glossLine is the Gloss column, the glosses of e.glossedTokens.

            Equations
            Instances For
              def Datum.feature? (e : Datum) (key : String) :
              Option String

              e.feature? key is the first value of key in e.paperFeatures, if there is one.

              Equations
              Instances For
                def Datum.features (e : Datum) (key : String) :
                List String

                e.features key is the list of values of key in e.paperFeatures, in order.

                Equations
                • e.features key = List.filterMap (fun (kv : String × String) => if kv.1 = key then some kv.2 else none) e.paperFeatures
                Instances For
                  def Datum.parse? (e : Datum) (key : String) {α : Type u_1} (table : List (String × α)) :
                  Option α

                  e.parse? key table is the entry of table under the first value of key in e, if e has the key and table lists its value.

                  Equations
                  • e.parse? key table = (e.feature? key).bind fun (x : String) => List.lookup x table
                  Instances For
                    def Datum.parseAll? (e : Datum) (key : String) {α : Type u_1} (table : List (String × α)) :
                    Option (List α)

                    e.parseAll? key table is every value of key in e read through table, if table lists them all.

                    Equations
                    • e.parseAll? key table = List.mapM (fun (x : String) => List.lookup x table) (e.features key)
                    Instances For
                      def Datum.byLanguage (e : Datum) {α : Type u_1} (table : List (Glottocode × α)) :
                      Option α

                      e.byLanguage table is the entry of table under the language of e, if table lists it: how a study reads a row through the languages of its sample.

                      Equations
                      Instances For
                        def Datum.nat? (e : Datum) (key : String) :
                        Option ℕ

                        e.nat? key is the first value of key in e read as a decimal numeral.

                        Equations
                        Instances For
                          def Datum.int? (e : Datum) (key : String) :
                          Option ℤ

                          e.int? key is the first value of key in e read as a decimal integer, an optional - followed by digits.

                          Equations
                          • One or more equations did not get rendered due to their size.
                          Instances For
                            def Datum.decimal? (e : Datum) (key : String) :
                            Option Rat

                            e.decimal? key is the first value of key in e read as an unsigned decimal numeral, digits with an optional fractional part after a point.

                            Equations
                            • One or more equations did not get rendered due to their size.
                            Instances For
                              def Datum.bool? (e : Datum) (key : String) :
                              Option Bool

                              e.bool? key is the first value of key in e read as true or false.

                              Equations
                              • e.bool? key = e.parse? key [("true", true), ("false", false)]
                              Instances For

                                e.judgments is every mark the paper prints on e: its judgment, then the further marks of a split mark such as ??/*, recorded as alsoJudged.

                                Equations
                                Instances For

                                  The paper judges e felicitous: it prints no mark on e, and its prose does not call e infelicitous, which the row records as felicity: infelicitous.

                                  Equations
                                  Instances For
                                    @[instance_reducible]
                                    Equations
                                    def Datum.Fits (e : Datum) {α : Type u_1} (f : Datum → Option α) (P : α → Judgment.Band) :

                                    The prediction P over what the reader f reads off e fits the row: the band of e's judgment is the predicted band. A row the reader does not read is unconstrained, so a Fits theorem is paired with a Datum.ReadCount for its reader.

                                    Equations
                                    Instances For
                                      @[instance_reducible]
                                      instance Datum.instDecidableFits (e : Datum) {α : Type u_1} (f : Datum → Option α) (P : α → Judgment.Band) :
                                      Decidable (e.Fits f P)
                                      Equations
                                      def Datum.FitsVerdict (e : Datum) {α : Type u_1} (f : Datum → Option α) (P : α → Bool) :

                                      The prediction P over what the reader f reads off e fits the row's truth-value judgment: where the source reports a verdict, it is the predicted one. The judgment of such a row records only that the expression is well formed, so a truth-value row is read by FitsVerdict, not Fits.

                                      Equations
                                      Instances For
                                        @[instance_reducible]
                                        instance Datum.instDecidableFitsVerdict (e : Datum) {α : Type u_1} (f : Datum → Option α) (P : α → Bool) :
                                        Decidable (e.FitsVerdict f P)
                                        Equations
                                        def Datum.ReadCount {α : Type u_1} (f : Datum → Option α) (rows : List Datum) (n : ℕ) :

                                        The reader f reads exactly n of rows: the coverage witness beside a Fits or other row-quantified theorem, without which the theorem goes silently vacuous when a feature key or a table value drifts.

                                        Equations
                                        Instances For
                                          @[instance_reducible]
                                          instance Datum.instDecidableReadCount {α : Type u_1} (f : Datum → Option α) (rows : List Datum) (n : ℕ) :
                                          Decidable (ReadCount f rows n)
                                          Equations
                                          def Datum.Checks {α : Type u_1} (f : Datum → Option α) (P : α → Judgment.Band) (rows : List Datum) (n : ℕ) :

                                          The prediction P fits every row of rows the reader f reads, and f reads exactly n of them: the one statement a study makes about a cluster of rows.

                                          Equations
                                          Instances For
                                            @[instance_reducible]
                                            instance Datum.instDecidableChecks {α : Type u_1} (f : Datum → Option α) (P : α → Judgment.Band) (rows : List Datum) (n : ℕ) :
                                            Decidable (Checks f P rows n)
                                            Equations
                                            def Datum.ChecksVerdict {α : Type u_1} (f : Datum → Option α) (P : α → Bool) (rows : List Datum) (n : ℕ) :

                                            The truth-value counterpart of Datum.Checks: the prediction matches every reported verdict on a row the reader reads, and exactly n rows have both.

                                            Equations
                                            Instances For
                                              @[instance_reducible]
                                              instance Datum.instDecidableChecksVerdict {α : Type u_1} (f : Datum → Option α) (P : α → Bool) (rows : List Datum) (n : ℕ) :
                                              Decidable (ChecksVerdict f P rows n)
                                              Equations
                                              • One or more equations did not get rendered due to their size.
                                              @[simp]
                                              theorem Datum.mem_features {e : Datum} {key v : String} :
                                              v ∈ e.features key ↔ (key, v) ∈ e.paperFeatures
                                              theorem Datum.features_eq_nil {e : Datum} {key : String} :
                                              e.features key = [] ↔ ∀ (v : String), (key, v) ∉ e.paperFeatures
                                              @[simp]
                                              theorem Datum.head?_features {e : Datum} {key : String} :
                                              (e.features key).head? = e.feature? key
                                              theorem Datum.feature?_eq_none {e : Datum} {key : String} :
                                              e.feature? key = none ↔ ∀ (v : String), (key, v) ∉ e.paperFeatures