從這裡看到的,似乎還有些問題。我原本是用Code Auto Escape,功能陽春但還過得去的plugin。先繼續用Code Auto Escape吧。
Ruby
test ruby
#!/usr/local/bin/ruby
exit if ARGV.length < 2
# read stop words
stop = File.new(ARGV[0])
stop_words = Hash.new()
while line = stop.gets
line.split.each { |e| stop_words[e] = 1}
end
stop.close
# read text
text = File.new(ARGV[1])
count = Hash.new(0)
while line = text.gets
line.split.each { |e| count[e] += 1 if stop_words[e] == nil }
end
text.close
# dump results
count.keys.each { |key| puts "#{count[key]} #{key}" }
Java
test java
Table stopTable = buildStopWordTable(args[0]); // store String
Table doc = new HashTableLL(); // store Count
BufferedReader br = openFile(args[1]);
String s;
while ((s=br.readLine()) != null) {
StringTokenizer stk = new StringTokenizer(s);
while (stk.hasMoreTokens()) {
s = stk.nextToken();
if (s.length() == 0 || stopTable.find(s) != null)
continue;
Count nc = new Count(s);
Count c = (Count)doc.find(nc);
if (c != null)
c.count++;
else {
doc.add(nc);
}
}
}
br.close();
Iterator iterator = doc.getIterator();
while(iterator.hasNext()) {
System.out.println(iterator.next());
}
沒有留言:
張貼留言