Mercurial > hg > Database > Alice
view src/main/java/alice/test/codesegment/local/wordcount/WordCount.java @ 547:e91a574b69de dispose
remove index
author | Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 18 Aug 2015 16:15:17 +0900 |
parents | 15eeb439830c |
children |
line wrap: on
line source
package alice.test.codesegment.local.wordcount; import alice.codesegment.CodeSegment; import alice.datasegment.CommandType; import alice.datasegment.Receiver; public class WordCount extends CodeSegment{ private Receiver info1 = ids.create(CommandType.TAKE); public WordCount(){ info1.setKey("array", this); } @Override public void run() { Range r = info1.asClass(Range.class); int word_flag = 0; int word_num = 0; int line_num = 0; int i = 0; for (; i < r.array.length; i++) { if (r.array[i] == 0x20) { // 空白 word_flag = 1; } else if (r.array[i] == 0x0A) { // 改行 line_num += 1; word_flag = 1; } else { word_num += word_flag; word_flag = 0; } } word_num += word_flag; if (r.nextchar!='\0'){ // null means last block if ((r.array[i-1] == 0x0A||r.array[i-1] == 0x20) && (r.nextchar == 0x0A||r.nextchar == 0x20)){ word_num--; } } Result result = new Result(line_num,word_num); ods.put("result", result); recycle();//new WordCount(); } }