SentiWord 方法采用字符串参数并使用标记器方法将单词标记为动词或名词......等当我运行此代码时,我得到“java.lang.StringIndexOutOfBoundsException:字符串索引超出范围:-3 ”。我知道有类似的问题,但我无法应用它们来消除异常。
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);
....
...
}
我正在尝试:
if (words[i].length()>0) // This line
tail = taggedWords[i].substring(words[i].length() + 1);
但异常似乎没有发生。请帮忙。
最佳答案
显然 words[i]
比 taggedWords[i]
长
尝试打印它们以进行调试,我打赌这就是您会看到的内容。
关于java - 我收到 "java.lang.StringIndexOutOfBoundsException: String index out of range: -3 ",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36686383/