请在下面找到我的示例代码:

    String[] tempCrfFC = crfFC;                //crfFC is a String[] itself
    for(int i = 0; i < crfFC.length; i++) {
        String[] crfTok = tempCrfFC[i].split("\\s");
        if(crfTok.length == 40) {
            if(crfTok[39].split("/")[0].equals("O")) {
                Double v = Double.parseDouble(crfTok[39].split("/")[1]);
                if (v <= d && (i == 0 || prevTagged != i-1)) {
                    tempCrfFC[i].split("\\s")[39] = "A";    //<-------
                    System.out.println("val: "+tempCrfFC[i].split("\\s")[39]);
                    System.out.println("tempCrfFC: "+tempCrfFC[i]);
                    prevTagged = i;
                }
             }
        }
    }


tempCrfFC行的示例:

The  T       Th      The     null    e       he      The     null   Aaa     Aa    1       1       1       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       O       B       O       B       O       0       DT      O       O/0.892667


我希望在标有“
谢谢。

最佳答案

尝试

String[] tempCrfFC = crfFC;                //crfFC is a String[] itself
for(int i = 0; i < crfFC.length; i++) {
    String[] crfTok = tempCrfFC[i].split("\\s");
    if(crfTok.length == 40) {
        String[] parts = crfTok[39].split("/");
        if (parts[0].equals("O")) {
            Double v = Double.parseDouble(parts[1]);
            if (v <= d && (i == 0 || prevTagged != i-1)) {
                cfTok[39] = "A";    //<-------
                System.out.println("val: " + cfTok[39]);
                tempCrfFC[i] = join(cfTok);
                System.out.println("tempCrfFC: " + tempCrfFC[i]);
                prevTagged = i;
            }
         }
    }
}


其中,join是一种从数组将字符串连接回去的方法。

07-24 18:22
查看更多