Commit 0e9fb2e2 authored by Steffen Michels's avatar Steffen Michels

Merge branch 'pluralise' into 'master'

Add Text.Language

See merge request !92
parents 5ea478c5 babfd181
Pipeline #8802 passed with stage
in 1 minute and 28 seconds
definition module Text.Language
/**
* A natural language.
*/
:: Language = English
/**
* Check whether a character is a vowel.
*/
isVowel :: Language Char -> Bool
/**
* Check whether a character is a consonant.
*/
isConsonant :: Language Char -> Bool
/**
* Pluralise a noun.
*/
pluralise :: Language String -> String
/**
* Construct a string like "3 items" based on a number and a noun.
*/
pluralisen :: Language Int String -> String
implementation module Text.Language
import StdArray
import StdBool
import StdChar
from StdFunc import id
import StdList
import StdString
import Text
isVowel :: Language Char -> Bool
isVowel English c = isMember c ['aeiou']
isConsonant :: Language Char -> Bool
isConsonant l c = isAlpha c && not (isVowel l c)
pluralise :: Language String -> String
pluralise English s
| last == 'y' && (isConsonant English forelast || forelast == 'u')
= s % (0, size s-2) +++ "ies"
= s +++ "s"
where (last, forelast) = (s.[size s-1], s.[size s-2])
pluralisen :: Language Int String -> String
pluralisen English n s = n <+ " " <+ if (n == 1) id (pluralise English) s
......@@ -132,6 +132,7 @@ import qualified Text.Encodings.MIME
import qualified Text.Encodings.UrlEncoding
import qualified Text.HTML
import qualified Text.JSON
import qualified Text.Language
import qualified Text.LaTeX
import qualified Text.PPrint
import qualified Text.Parsers.CParsers.ParserCombinators
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment