From 20e799733851a6ac93b30d54e966de14c29c9bb1 Mon Sep 17 00:00:00 2001 From: Tam Nguyen Duc <1218621+tamnd@users.noreply.github.com> Date: Thu, 5 Nov 2026 14:09:17 +0700 Subject: [PATCH] Drop a leading The from heading names in corpus adopt --- importer/wikipedia/adopt.go | 8 ++++++-- importer/wikipedia/adopt_test.go | 14 ++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/importer/wikipedia/adopt.go b/importer/wikipedia/adopt.go index 125e374..db0b88e 100644 --- a/importer/wikipedia/adopt.go +++ b/importer/wikipedia/adopt.go @@ -105,7 +105,7 @@ var genericName = regexp.MustCompile(`(?i)^(theorem|lemma|corollary|proposition| var labelName = regexp.MustCompile(`(?i)^(axiom|theorem|lemma|corollary|proposition|claim|conjecture|definition|fact|step|case|rule|property|observation|remark|example|exercise|problem|condition|assumption|hypothesis)s? ([0-9]+[a-z]?|[A-Z]|[IVX]+)(\.[0-9]+)*$`) // headingPrefix matches a heading that names a part of the text about an item and not the item, such as "Precise statement of the Adyan–Rabin theorem" or "History: the lemma that is not Burnside's". -var headingPrefix = regexp.MustCompile(`(?i)^(proof of|disproof of|disproved|variants? of|interpretations? (of|via)|relations? (with|to)|extension to include|incompatibility with|modern approach|general formulas|general statement|particular values|analytic criteria|geometry of|conjectures? (on|of)|criterion for|degree of|classical integral|extended|weaker|stronger|original|history|accuracy|an?|theorems?|importance|sharpness|via|equivalence|connections|explicit|formulas?|identity group|another|alternative|connection|derivation|equivalent forms|from|comparison|relationship|relation to|validity|an introduction|theorems proved|precise statement|formal statement|statements?|definitions?|examples?|applications?|consequences|corollary|corollaries|involving|proofs?|outline|sketch|overview|generali[sz]ations?|properties|results|facts|motivation|background|introduction|some|other|further|basic|main|key)\b`) +var headingPrefix = regexp.MustCompile(`(?i)^(characteri[sz]ations?|equivalent formulations|proof of|disproof of|disproved|variants? of|interpretations? (of|via)|relations? (with|to)|extension to include|incompatibility with|modern approach|general formulas|general statement|particular values|analytic criteria|geometry of|conjectures? (on|of)|criterion for|degree of|classical integral|extended|weaker|stronger|original|history|accuracy|an?|theorems?|importance|sharpness|via|equivalence|connections|explicit|formulas?|identity group|another|alternative|connection|derivation|equivalent forms|from|comparison|relationship|relation to|validity|an introduction|theorems proved|precise statement|formal statement|statements?|definitions?|examples?|applications?|consequences|corollary|corollaries|involving|proofs?|outline|sketch|overview|generali[sz]ations?|properties|results|facts|motivation|background|introduction|some|other|further|basic|main|key)\b`) // pluralTail matches a heading that names a group of items, such as "Freudenthal-Hopf theorems". var pluralTail = regexp.MustCompile(`(?i)\b(theorems|results|facts|properties|lemmas|formulas|formulae|conjectures|identities|axioms|inequalities|relations|criteria|propositions|principles|primes|graphs)$`) @@ -141,7 +141,7 @@ var otherName = regexp.MustCompile(`(?i)\([^)]*\b(theorem|lemma|formula|identity // pluralWord matches a list entry that is one word in the plural, as "Lattices". The entry names a group of items. var pluralWord = regexp.MustCompile(`^[A-Z][a-z]+s$`) -var oddName = regexp.MustCompile(`[?"#]|^'|'$|\s\([0-9]{4}\)$|\s\([A-Z]{2,6}\)$|-$| / `) +var oddName = regexp.MustCompile(`\(or |[?"#]|^'|'$|\s\([0-9]{4}\)$|\s\([A-Z]{2,6}\)$|-$| / `) // questionHead matches a name that is a question, as "How many unit distances". var questionHead = regexp.MustCompile(`^(How|Can|Are|Is|Does|Do|What|Which|Why|When)\b`) @@ -632,6 +632,10 @@ func displayName(m *inventory.Mention) string { if m.Cue == "lead" && !strings.Contains(m.ID, "#") && m.NativeID != Name(m.NativeID) && inventory.NameKey(m.Name) == inventory.NameKey(Name(m.NativeID)) { return m.NativeID } + // A heading such as "The Routh criterion" names the item with "The", and the node takes "Routh criterion". + if rest, ok := strings.CutPrefix(m.Name, "The "); ok && m.Cue != "lead" && m.Cue != "term" && rest != "" && unicode.IsUpper([]rune(rest)[0]) { + return rest + } if m.Cue != "term" || m.Name == "" { return m.Name } diff --git a/importer/wikipedia/adopt_test.go b/importer/wikipedia/adopt_test.go index ea0f598..cf21854 100644 --- a/importer/wikipedia/adopt_test.go +++ b/importer/wikipedia/adopt_test.go @@ -341,6 +341,9 @@ func TestWhyName(t *testing.T) { {"list-entry", "Lattices", true}, {"named-heading", "Identity / neutral elements", true}, {"named-heading", "Variants of Wilson's theorem", true}, + {"named-heading", "Characterization by a convolution identity", true}, + {"named-heading", "Equivalent formulations of locality axiom", true}, + {"list-entry", "Root (or zero) of a polynomial", true}, {"named-heading", "Bhargava's approach to the composition law", true}, {"named-heading", "Interpretation via the Chinese Remainder Theorem", true}, {"named-heading", "Extension to include the Goldbach conjecture", true}, @@ -457,6 +460,17 @@ func TestDisplayNameQualifier(t *testing.T) { } } +func TestDisplayNameThe(t *testing.T) { + m := &inventory.Mention{ID: "wikipedia://en/3#o4", Cue: "named-heading", Name: "The Routh criterion"} + if got := displayName(m); got != "Routh criterion" { + t.Errorf("got %q", got) + } + m = &inventory.Mention{ID: "wikipedia://en/4", Cue: "lead", Name: "The Pirates of Penzance"} + if got := displayName(m); got != "The Pirates of Penzance" { + t.Errorf("got %q", got) + } +} + func TestDropNotes(t *testing.T) { notes := map[string]string{"n3": "Serre (1977).", "o6": "See Logic programming."} for in, want := range map[string]string{