how to replace variables like two-third, one-fifth, two-hundreth number form using java -


i want take input in name form two-third or one-fifth , want system convert numerical form , give answer.

que: two-third of thirty is?

the system should output 20

how can program it?

as general problem natural language processing (nlp) - you're talking - difficult open-ended problem.

there lots of libraries stuff. if want background here:

is there natural language processing library

or natural language processing in wikipedia.

however said want , you're new programming. first thing need break problem down. that's how solve programming problems.

so first try writing program can read string containing single word , map number. example "one" outputs 1, "two" outputs 2, "thirty" outputs 30.

next try , write program cuts string constituent words. want use array here. that's process called tokenizing , java has built in stringtokenizer that. might want code yourself, you're learning , might moment start learning using library code.

when you've got try combining them program can convert "thirty seven" 37 (i.e. numbers under 100). new program should combine ideas of program can convert "thirty" , "seven" , 1 can split words up.

this other thing in programming - combining things. break down smaller problems solve them , build them solve bigger problems. (i apologize if i'm patronizing have no idea of experience).

after might add logic handles "five hundred , thirty seven". again, notice how spotting 5 followed hundred converting 5 , finding token tells multiply saw 100. go on handle thousands, hundred thousand etc.

or branch off fractions. that's similar have different vocabulary. 7 forty-seconds = 7/42.

as learning challenge suggest you'll have come long way if program handles things "forty 2 ninety-thirds of 8 hundred , eighty nine".

the easy solution outputs 0.000508 - floating point answer (42/93)*889. credit solution outputs 2/3937 - (42/93)*889 can simplified rational number 2/3937.

to honest, you'll doing if can handle "nine-ninths of ninety nine". notice first word numerator (n). second denominator (d). third 'of'. forth word either tens (t) or units (u). if forth units you're done otherwise if there fifth word it's units.
answer in case n/d*(t*10+u). if tens or units missing they're 0 - obviously. ps: might need special handling 0 if object typing in ninety zero. means ninety don't in english!


Comments

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -