[英]I am getting “ java.lang.StringIndexOutOfBoundsException: String index out of range: -3 ”
SentiWord method takes String arguments and uses tagger method to tag a word as verb or noun....etc When I run this code I get " java.lang.StringIndexOutOfBoundsException: String index out of range: -3 ". SentiWord方法使用String参数,并使用tagger方法将单词标记为动词或名词。...等当我运行此代码时,我得到“ java.lang.StringIndexOutOfBoundsException:字符串索引超出范围:-3”。 I know there are similar questions like this, but I am unable to apply them to get rid of exception.
我知道也有类似的问题,但是我无法应用它们摆脱异常。
public static String SentiWord(String stri) {
MaxentTagger tagger = new MaxentTagger("taggers/english-left3words-distsim.tagger");
String sample=stri;
sample = sample.replaceAll("([^a-zA-Z\\s])", "");
String[] words = sample.split("\\s+");
String taggedSample = tagger.tagString(sample);
String[] taggedWords = taggedSample.split("\\s+");
double totalScore = 0;
SWN3 test = new SWN3();
for (int i=0; i<taggedWords.length;i++) {
String tail = taggedWords[i].substring(words[i].length() + 1);
....
...
}
What I am trying: 我正在尝试:
if (words[i].length()>0) // This line
tail = taggedWords[i].substring(words[i].length() + 1);
But exception doesnt seem to go.Please help. 但是异常似乎没有消失。请帮助。
显然, words[i]
的长度比taggedWords[i]
尝试出于调试目的同时打印它们,我敢打赌,这就是您所看到的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.