Racket implementation of string operations
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#lang racket | |
(define (clean-up s) | |
(first (split-into-sentences (fix-hyphenation (fix-whitespace s))))) | |
(define (fix-whitespace s) | |
(string-replace s "\n" " ")) | |
(define (fix-hyphenation s) | |
(string-replace s "- " "")) | |
(define (split-into-sentences s) | |
(map ensure-ends-with-period (string-split s ". "))) | |
(define (ensure-ends-with-period s) | |
(if (char=? (string-ref s (- (string-length s) 1)) #\.) | |
s | |
(string-append s "."))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(module+ test | |
(require rackunit) | |
(check-equal? (fix-whitespace "new\nline") "new line") | |
(check-equal? (fix-hyphenation "auto- mobile") "automobile") | |
(check-equal? (clean-up "Relating to the state transient lodging tax; creating\nnew provisions; amending ORS 284.131 and\n320.305; prescribing an effective date; and pro-\nviding for revenue raising that requires approval\nby a three-fifths majority.\nWhereas Enrolled House Bill 2267 (chapter 818,") | |
"Relating to the state transient lodging tax; creating new provisions; amending ORS 284.131 and 320.305; prescribing an effective date; and providing for revenue raising that requires approval by a three-fifths majority.")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment