Forum: JRuby Ruby string -> toCharArray

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
669ad65a6aaefa1b5e6353cea9fe26c0?d=identicon&s=25 Tomasz Bak (linus)
on 2008-10-08 22:52
Hello,
I get fallowing error:

$ jruby jr.rb
jr.rb:33: for method tokenizer expected [[C, int, int]; got:
[java.lang.String,j
ava.lang.Integer,java.lang.Integer]; error: argument type mismatch
(TypeError)

It is caused by this code (commented fragemts in Java):

#String line = bufReader.readLine();
#...
# char[] cs = line.toCharArray();
cs = String.new("The import statement can be used to import a Java
Class.")

# char[] cs = line.toCharArray();
# Tokenizer tokenizer = TOKENIZER_FACTORY.tokenizer(cs,0,cs.length);
tokenizer = tokenizer_factory.tokenizer(cs, 0, cs.length) # this line 33
tokens = tokenizer.tokenize()

How to modify that code to pass?

Cheers,
Tomasz Bak

PS There is the full code:

# jr.rb
=begin

based on
http://alias-i.com/lingpipe/demos/tutorial/posTags...

$ jruby jr.rb
jr.rb:33: for method tokenizer expected [[C, int, int]; got:
[java.lang.String,j
ava.lang.Integer,java.lang.Integer]; error: argument type mismatch
(TypeError)

=end

require 'java'
require 'lingpipe-3.6.0' #
http://alias-i.com/lingpipe/web/downloadJarOrDistro.html

include_class 'com.aliasi.hmm.HiddenMarkovModel'
include_class 'com.aliasi.hmm.HmmDecoder'
include_class 'com.aliasi.hmm.TagWordLattice'

include_class 'com.aliasi.symbol.SymbolTable'

include_class 'com.aliasi.tokenizer.Tokenizer'
include_class 'com.aliasi.tokenizer.TokenizerFactory'
include_class 'com.aliasi.tokenizer.RegExTokenizerFactory'

include_class 'com.aliasi.util.ScoredObject'
include_class 'com.aliasi.util.Streams'
include_class 'com.aliasi.util.Strings'

include_class 'java.io.BufferedReader'
include_class 'java.io.FileInputStream'
include_class 'java.io.InputStreamReader'
include_class 'java.io.IOException'
include_class 'java.io.ObjectInputStream'

include_class 'java.util.Arrays'

#estimator = HmmCharLmEstimator.new(8,256,8.0)
#parser = MedPostPosParser.new
#parser.setHandler(estimator)

tokenizer_factory = RegExTokenizerFactory.new("(-|'|\\d|\\p{L})+|\\S")

#String line = bufReader.readLine();
#...
# char[] cs = line.toCharArray();
cs = String.new("The import statement can be used to import a Java
Class.")

# char[] cs = line.toCharArray();
# Tokenizer tokenizer = TOKENIZER_FACTORY.tokenizer(cs,0,cs.length);
tokenizer = tokenizer_factory.tokenizer(cs, 0, cs.length)
tokens = tokenizer.tokenize()

puts "Success!"
This topic is locked and can not be replied to.