Open missinglink opened 8 years ago
thanks for the feedback, @missinglink -- I'll patch this ASAP!
cool thanks @chuckpreslar, I sourced them from https://en.wikipedia.org/wiki/English_plurals
here's a copy of my test case:
package token
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestSingular(t *testing.T) {
var text, expected []string
// identical singular and plural
text = []string{"bison", "buffalo", "deer", "duck", "fish", "moose", "pike", "plankton", "salmon", "sheep", "quid", "swine", "trout"}
expected = []string{"bison", "buffalo", "deer", "duck", "fish", "moose", "pike", "plankton", "salmon", "sheep", "quid", "swine", "trout"}
assert.Equal(t, expected, Singular(text))
// sibilant sound
// @todo: these are techinally not quite correct but will do for autocomplete
text = []string{"kisses", "phases", "dishes", "massages", "witches", "judges"}
expected = []string{"kiss", "phas", "dish", "massage", "witch", "judge"}
// expected = []string{"kiss", "phase", "dish", "massage", "witch", "judge"} // error
assert.Equal(t, expected, Singular(text))
// voiceless consonant
text = []string{"laps", "cats", "clocks", "cuffs", "deaths"}
expected = []string{"lap", "cat", "clock", "cuff", "death"}
assert.Equal(t, expected, Singular(text))
// regular plural
text = []string{"boys", "girls", "chairs"}
expected = []string{"boy", "girl", "chair"}
assert.Equal(t, expected, Singular(text))
// nouns ending in -o
text = []string{"heroes", "potatoes", "volcanoes", "volcanos"}
expected = []string{"hero", "potato", "volcanoe", "volcano"}
// expected = []string{"hero", "potato", "volcano", "volcano"} // error
assert.Equal(t, expected, Singular(text))
// nouns ending in -o (Italian loanwords)
text = []string{"cantos", "heteros", "photos", "zeros", "pianos", "porticos", "pros", "quartos", "kimonos"}
expected = []string{"canto", "hetero", "photo", "zero", "piano", "portico", "pro", "quarto", "kimono"}
assert.Equal(t, expected, Singular(text))
// nouns ending in -y
text = []string{"cherries", "ladies", "skies"}
expected = []string{"cherry", "lady", "sky"}
assert.Equal(t, expected, Singular(text))
// nouns ending in -guy
text = []string{"soliloquies"}
expected = []string{"soliloquy"}
assert.Equal(t, expected, Singular(text))
// voiceless fricatives
text = []string{"baths", "mouths", "calves", "leaves", "knives", "lives", "houses", "moths", "proofs"}
expected = []string{"bath", "mouth", "calf", "leave", "knife", "life", "hous", "moth", "proof"}
// expected = []string{"bath", "mouth", "calf", "leave", "knife", "live", "house", "moth", "proof"} // error
assert.Equal(t, expected, Singular(text))
// nouns ending in -f
// @todo: not so easy for autocomplete
// text = []string{"dwarves", "hooves", "elves", "staves", "turves"}
// expected = []string{"dwarf", "hoof", "elf", "staff", "turf"}
// assert.Equal(t, expected, Singular(text))
}
awesome lib thanks!
I noticed a couple edge cases for
Singularize()
which didn't quite work as expected:... plus some really difficult cases from old english: