Open cristcost opened 9 years ago
@cristcost +1
👍
+1. My data values are > 1 almost all the time and I occasionally hit singular values
I agree. I downloaded this library because I assumed it would support singularization too. Sadly, I was mistaken. This project has a lot of potential though!
If anyone is interested, I've ported this to Scala and implemented singularization here: https://github.com/hypertino/inflector To use it add dependency:
<dependency>
<groupId>com.hypertino</groupId>
<artifactId>inflector_2.11</artifactId>
<version>1.0.0</version>
</dependency>
And make a call: com.hypertino.inflector.English.singular("cats")
- returns 'cat'
I realize this is an old issue, but did anyone ever find a way to accomplish this? I saw the Scala port, but would prefer to keep the libraries I use pure Java. In addition when I tried pumping many values through the Scala port I got exceptions. For example:
System.out.println(English.singular("days"));
produces this exception
java.lang.IllegalArgumentException: Illegal group reference
at java.base/java.util.regex.Matcher.appendExpandedReplacement(Matcher.java:1068) ~[na:na]
at java.base/java.util.regex.Matcher.appendReplacement(Matcher.java:998) ~[na:na]
at java.base/java.util.regex.Matcher.replaceFirst(Matcher.java:1408) ~[na:na]
at scala.util.matching.Regex.replaceFirstIn(Regex.scala:516) ~[scala-library-2.11.8.jar:na]
at com.hypertino.inflector.RegExpRule.getSingular(TwoFormInflector.scala:46) ~[inflector_2.11-1.0.0.jar:1.0.0]
at com.hypertino.inflector.TwoFormInflector$$anonfun$singular$1.apply(TwoFormInflector.scala:88) ~[inflector_2.11-1.0.0.jar:1.0.0]
at com.hypertino.inflector.TwoFormInflector$$anonfun$singular$1.apply(TwoFormInflector.scala:88) ~[inflector_2.11-1.0.0.jar:1.0.0]
at scala.collection.immutable.Stream.flatMap(Stream.scala:493) ~[scala-library-2.11.8.jar:na]
at com.hypertino.inflector.TwoFormInflector.singular(TwoFormInflector.scala:88) ~[inflector_2.11-1.0.0.jar:1.0.0]
at com.hypertino.inflector.English.singular(English.scala) ~[inflector_2.11-1.0.0.jar:1.0.0]
Many other words do work so I don't know what is wrong with that.
@ctmay4 thanks, I fixed that error in latest version 1.0.11
, if you find any other issue please report to https://github.com/hypertino/inflector/issues/new
Would be interesting to have the capability to transform plurals to singular: