PRIVATE>
+CONSTANT: vowels "aeiou"
+
+: vowel? ( ch -- ? )
+ vowels member? ; inline
+
: singularize ( word -- singular )
dup >lower {
{ [ dup empty? ] [ ] }
{ [ dup "s" tail? not ] [ ] }
{
[
- dup "ies" ?tail [
- last "aeiou" member? not
- ] [ drop f ] if
+ dup "ies" ?tail [ last vowel? not ] [ drop f ] if
] [ 3 head* "y" append ]
}
{ [ dup "es" tail? ] [ 2 head* ] }
{ [ singular-to-plural ?at ] [ ] }
{
[
- dup "y" ?tail [
- last "aeiou" member? not
- ] [ drop f ] if
+ dup "y" ?tail [ last vowel? not ] [ drop f ] if
] [ but-last "ies" append ]
}
{
] when ;
: a/an ( word -- article )
- [ first ] [ length ] bi 1 = "afhilmnorsx" "aeiou" ?
+ [ first ] [ length ] bi 1 = "afhilmnorsx" vowels ?
member? "an" "a" ? ;
: ?plural-article ( word -- article )
! Copyright (C) 2005, 2009 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
USING: accessors arrays assocs combinators compiler.units
-definitions.icons effects hashtables help.stylesheet help.topics
-io io.styles kernel make math namespaces present prettyprint
-prettyprint.stylesheet quotations see sequences
+definitions.icons effects english hashtables help.stylesheet
+help.topics io io.styles kernel make math namespaces present
+prettyprint prettyprint.stylesheet quotations see sequences
sequences.private sets sorting splitting strings urls vocabs
words words.symbol ;
FROM: prettyprint.sections => with-pprint ;
: a/an ( str -- str )
[ first ] [ length ] bi 1 =
- "afhilmnorsx" "aeiou" ? member? "an" "a" ? ;
+ "afhilmnorsx" vowels ? member? "an" "a" ? ;
GENERIC: ($instance) ( element -- )
-USING: combinators kernel math parser sequences splitting ;
+USING: combinators english kernel math parser sequences
+splitting ;
IN: porter-stemmer
: consonant? ( i str -- ? )
- 2dup nth dup "aeiou" member? [
+ 2dup nth dup vowel? [
3drop f
] [
CHAR: y = [