regex - Search true if the word is Singular or Plural Java -


i trying achieve result in if user enters word, in plural or singular, regex should return true

for example 'i want drone' or 'i want drones'.

    @test     public void testproductsearchregexp() {         string regexp = "(?i).*?\\b%s\\b.*?";          string query = "i want drone flir duo";          string data1 = "drone";         string data2 = "flir duo";         string data3 = "flir";         string data4 = "drones";          boolean isdata1 = query.matches(string.format(regexp, data1));         boolean isdata2 = query.matches(string.format(regexp, data2));         boolean isdata3 = query.matches(string.format(regexp, data3));         boolean isdata4 = query.matches(string.format(regexp, data4));          asserttrue(isdata1);         asserttrue(isdata2);         asserttrue(isdata3);         asserttrue(isdata4);//test fails here (obviously)      } 

your valuable time on question appreciated.

english language many exceptions. checking whether word ends in 's' not sufficient determine whether it's plural.

the best way solve problem not solve problem. it's been done before. take advantage of that. 1 solution make use of third party api. the oed have one, example.

if make request api such as:

/entries/en/mice 

you json response containing:

"crossreferencemarkers": [     "plural form of mouse" ], 

from there should easy parse. checking presence of word 'plural' may sufficient.

they have working java examples can copy , paste.


an advantage of approach there's no compile-time dependency. disadvantage you're relying on being able make http requests. you're limited restrictions impose. oed allows 3k requests/month , 60 requests/minute on free plan, seems pretty reasonable me.


Comments

Popular posts from this blog

html - How to set bootstrap input responsive width? -

javascript - Highchart x and y axes data from json -

javascript - Get js console.log as python variable in QWebView pyqt -