Using StringTokenizer in Coverting words to number

你。 提交于 2019-12-06 13:17:54

I think stringtokenizer is not enough, you need a dictionary to transalate from your language to number

see also http://nlp.stanford.edu/nlp/javadoc/javanlp/edu/stanford/nlp/ie/NumberNormalizer.html

Provides functions for converting words to numbers Unlike QuantifiableEntityNormalizer that normalizes various types of quantifiable entities like money and dates, NumberNormalizer only normalizes numeric expressions (e.g. one => 1, two hundred => 200.0 )

The StringTokenizer has a constructor that allows specific delimiters. Assuming you wish to delimit each token by a mere space " " you could use a ArrayList with each token pre-specifically placed using numbers 0-9.

 ArrayList<String> token;

 token.add("zero");
 token.add("one"); ... etc

 StringTokenizer s = new StringTokenizer("four zero four", " ");
 String num_rep = token.indexOf(s.nextToken()) + token.indexOf(s.nextToken()) + token.indexOf(s.nextToken());

You need to write a logic for comparing the string with standard words, and then building the number on the go.

Just an observation: StackOverflow is not a place to get your assignments solved.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!