diff --git a/importer/wikipedia/adopt.go b/importer/wikipedia/adopt.go index db0b88e..b7051ad 100644 --- a/importer/wikipedia/adopt.go +++ b/importer/wikipedia/adopt.go @@ -688,6 +688,9 @@ var sentenceEnd = regexp.MustCompile(`[.!?](\s|$)`) // bareName matches an entry that is only the name of a person, as "Emil Artin.". var bareName = regexp.MustCompile(`^[A-Z]\pL+( [A-Z][\pL.]*)+\.$`) +// usageEntry matches a glossary entry that tells how a word is used and does not define one item, as `The word "big" when applied to a module` or "Named after Richard P. Stanley". +var usageEntry = regexp.MustCompile(`^(The (word|term|prefix|adjective|adverb) |This (often |usually )?(refers|means)|Named after |(Occasionally|Often|Usually|Sometimes) used|An? (alternative|other|older) (term|name) for |(Usually|Often) means )`) + // nameWord matches the first use of a word in a text, with the word or the "'s" that follows it. var nameWord = regexp.MustCompile(`^('s\b|\s+[\p{Ll}-]{3,}\b)`) @@ -700,16 +703,35 @@ func modifierEntry(name, text string) bool { if bareName.MatchString(first) || strings.EqualFold(strings.TrimSuffix(first, "."), name) { return true } - if regexp.MustCompile(`(?i)\b(called|said to be) \*?` + regexp.QuoteMeta(name) + `\b[^.]{0,12}?\s(if|when)\b`).MatchString(first) { + if usageEntry.MatchString(first) { + return true + } + q := regexp.QuoteMeta(name) + if regexp.MustCompile(`(?i)\b(called|said to( be| hold)?) [*\[]{0,2}` + q + `\b|\bis \*{0,2}` + q + `\*{0,2} (if|when)\b`).MatchString(first) { return true } if strings.ContainsAny(name, " ") { return false } + // The name is the head noun of a longer term, as "Hull" in "An injective hull" or "Regularity" in "Castelnuovo–Mumford regularity". + if w := strings.Fields(first); len(w) > 2 { + if w[0] == "A" || w[0] == "An" || w[0] == "The" { + w = w[1:] + } + if !strings.EqualFold(w[0], name) && strings.EqualFold(strings.Trim(w[1], ".,;:*"), name) { + return true + } + } + if strings.Contains(name, "-") && !strings.Contains(strings.ToLower(first), strings.ToLower(name)) { + name = strings.ReplaceAll(name, "-", "") + } at := strings.Index(strings.ToLower(first), strings.ToLower(name)) for at >= 0 { if at == 0 || !isLetter(first[at-1]) { rest := first[at+len(name):] + if len(rest) > 1 && rest[0] == '-' && isLetter(rest[1]) { + return true + } if rest == "" || !isLetter(rest[0]) { w := nameWord.FindStringSubmatch(rest) if w == nil { diff --git a/importer/wikipedia/adopt_test.go b/importer/wikipedia/adopt_test.go index cf21854..2d226b2 100644 --- a/importer/wikipedia/adopt_test.go +++ b/importer/wikipedia/adopt_test.go @@ -561,6 +561,18 @@ func TestModifierEntry(t *testing.T) { {"Dominant", "The representations are indexed by their highest weight. These *dominant weights* form a lattice."}, {"Admissible", "A representation is called admissible if it has finite multiplicities."}, {"Defined over", "A representation is said to be defined over *F* if it comes from F."}, + {"Quasi", "A quasi-excellent ring is a Grothendieck ring such that the singular points form a closed subset."}, + {"Reflexive", "A module *M* is reflexive if the canonical map is an isomorphism."}, + {"Dominate", "A local ring *B* is said to dominate a local ring *A* if it contains *A*."}, + {"Irreducible", "An element of a ring is called [[irreducible|052SDEPZH7]] if it cannot be written as a product."}, + {"Universally", "A property is said to hold universally if it holds for various base changes."}, + {"Big", "The word \"big\" when applied to a module emphasizes that the module is not finitely generated."}, + {"Stanley", "Named after Richard P. Stanley A Stanley–Reisner ring is a quotient of a polynomial algebra."}, + {"Separated", "An alternative term for Hausdorff, usually applied to a topology on a ring."}, + {"Neat", "Occasionally used to mean \"unramified\"."}, + {"Hull", "An injective hull (or envelope) of a module is a minimal injective module containing it."}, + {"Regularity", "Castelnuovo–Mumford regularity is an invariant of a graded module."}, + {"Semi-local", "A semilocal ring is a ring with only a finite number of maximal ideals."}, } { if !modifierEntry(c[0], c[1]) { t.Errorf("%q with %q is not found as a modifier entry", c[0], c[1]) @@ -571,6 +583,9 @@ func TestModifierEntry(t *testing.T) { {"Girth", "The girth of a graph is the length of its shortest cycle."}, {"Source", "A vertex with no incoming edges."}, {"Ideal", "An ideal I of a ring R is a subgroup."}, + {"Syzygy", "A syzygy of a module is an element of the kernel of a map."}, + {"Completion", "The completion of a ring at an ideal is the inverse limit."}, + {"Girth", "The length of the shortest cycle of a graph."}, } { if modifierEntry(c[0], c[1]) { t.Errorf("%q with %q is found as a modifier entry", c[0], c[1])