Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve tech normalization of plural words #252

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion scribble-doc/scribblings/scribble/manual.scrbl
Original file line number Diff line number Diff line change
Expand Up @@ -1791,7 +1791,10 @@ normalized as follows:

@item{A trailing ``ies'' is replaced by ``y''.}

@item{A trailing ``s'' is removed.}
@item{A trailing ``es'' is removed if it was preceded by an ``s'', ``x'',
``z'', ``ch'', or an ``sh''.}

@item{A trailing ``s'' is removed if it was not preceded by an ``s''.}

@item{Consecutive hyphens and whitespaces are all replaced by a
single space.}
Expand Down
23 changes: 15 additions & 8 deletions scribble-lib/scribble/private/manual-tech.rkt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#lang scheme/base
#lang racket/base
(require racket/contract/base
"../decode.rkt"
"../struct.rkt"
Expand Down Expand Up @@ -28,13 +28,7 @@
(define (*tech make-elem style doc prefix s key normalize?)
(let* ([c (decode-content s)]
[s (or key (content->string c))]
[s (if normalize?
(let* ([s (string-foldcase s)]
[s (regexp-replace #rx"ies$" s "y")]
[s (regexp-replace #rx"s$" s "")]
[s (regexp-replace* #px"[-\\s]+" s " ")])
s)
s)]
[s (if normalize? (normalize s) s)]
[s (datum-intern-literal s)])
(make-elem style c (list 'tech (doc-prefix doc prefix s)))))

Expand Down Expand Up @@ -74,3 +68,16 @@
#:normalize? [normalize? #t]
. s)
(*tech make-link-element #f doc prefix s key normalize?))

(define (normalize raw-string)
(define folded (string-foldcase raw-string))
;; This logic was derived from the rules for singular and plural words
;; described here: https://www.ef.com/wwen/english-resources/english-grammar/singular-and-plural-nouns/
(define singular
(cond
[(regexp-match? #rx"ies$" folded) (regexp-replace #rx"ies$" folded "y")]
[(regexp-match? #rx"(s|x|z|ch|sh)es$" folded)
(regexp-replace #rx"es$" folded "")]
[(regexp-match? #rx"[^s]s%" folded) (regexp-replace #rx"s$" folded "")]
[else folded]))
(regexp-replace* #px"[-\\s]+" singular " "))