有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java从句子中提取动词

我想知道是否有办法从字符串中提取动词

例如:

I'll eliminate you.

我希望它只提取“消除”


共 (1) 个答案

  1. # 1 楼答案

    ArrayList<String> verbs = new ArrayList<>();
    verbs.add("eliminate");
    
    String yourtext = "I'll eliminate you";
    
    for (String verb : verbs) {
        int index = yourtext.indexOf(verb);
        if (index >= 0) {
            System.out.println("Found verb: " + verb + " at position: " + index);
        }
    }
    

    我将把动词数组的填充留给你