hashpikh parikh

fukurou

the supreme coder
ADMIN
Java:
public class DiRail extends Skill {
    // DiRail skill for testing purposes
    private RailBot railBot = new RailBot();
    public DiRail() {
        super();
    }
    public static boolean endsWithOk(String input) {
        return input != null && input.endsWith("ok");
    }
    public static String stripOk(String input) {
        return input.substring(0, input.length() - 2);
    }


    @Override
    public void input(String ear, String skin, String eye) {
        if(!endsWithOk(ear)){return;}
        String temp = stripOk(ear);
        String temp2 = railBot.respondDialog(temp);
        if(!temp2.isEmpty()){setSimpleAlg(temp2);}
        railBot.learn(temp);
    }

    @Override
    public String skillNotes(String param) {
        if ("notes".equals(param)) {
            return "experimental chatbot";
        } else if ("triggers".equals(param)) {
            return "end input with the word ok";
        }
        return "note unavailable";
    }
}

jizzy jizz
 

fukurou

the supreme coder
ADMIN
Java:
public class QuestionChecker {
    // Using a switch expression (Java 14+) for maximum performance
    private static boolean isQuestionWord(String word) {
        return switch (word) {
            case "what", "who", "where", "when", "why", "how",
                 "is", "are", "was", "were", "do", "does", "did",
                 "can", "could", "would", "will", "shall", "should",
                 "have", "has", "am", "may", "might" -> true;
            default -> false;
        };
    }

    public static boolean isQuestion(String input) {
        if (input == null || input.isEmpty()) {
            return false;
        }

        // Fast check for question mark first
        if (input.charAt(input.length() - 1) == '?') {
            return true;
        }

        // Trim and get first word
        String trimmed = input.trim().toLowerCase();
        int spaceIdx = trimmed.indexOf(' ');
        String firstWord = spaceIdx == -1 ? trimmed : trimmed.substring(0, spaceIdx);

        // Handle contractions
        int apostropheIdx = firstWord.indexOf('\'');
        if (apostropheIdx > 0) {
            firstWord = firstWord.substring(0, apostropheIdx);
        }

        return isQuestionWord(firstWord);
    }
}
 

fukurou

the supreme coder
ADMIN
Java:
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

public class QuestionChecker {
    private static final Set<String> QUESTION_WORDS = new HashSet<>();

    static {
        // Initialize the set of question words
        String[] words = {
                "what", "who", "where", "when", "why", "how",
                "is", "are", "was", "were", "do", "does", "did",
                "can", "could", "would", "will", "shall", "should",
                "have", "has", "am", "may", "might"
        };
        QUESTION_WORDS.addAll(Arrays.asList(words));
    }

    public static boolean isQuestion(String input) {
        if (input == null || input.trim().isEmpty()) {
            return false;
        }

        String trimmed = input.trim().toLowerCase();

        // Check for question mark
        if (trimmed.endsWith("?")) {
            return true;
        }

        // Extract the first word
        int firstSpace = trimmed.indexOf(' ');
        String firstWord = firstSpace == -1 ? trimmed : trimmed.substring(0, firstSpace);

        // Check for contractions like "who's"
        if (firstWord.contains("'")) {
            firstWord = firstWord.substring(0, firstWord.indexOf("'"));
        }

        // Check if first word is a question word
        return QUESTION_WORDS.contains(firstWord);
    }
}
 
Top