-
Notifications
You must be signed in to change notification settings - Fork 3
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
Singularize edge cases #2
Comments
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))
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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:
The text was updated successfully, but these errors were encountered: