public Predicate parsePredicate(String input) throws ParseException {
        Matcher matcher = predicatePattern.matcher(input);
        if (!matcher.matches()) {
            throw new ParseException(
                "The given input '" + input + "' is not a valid predicate.");
        }

        List<Term> arguments = new ArrayList<Term>();
        for (int i = 2; i <= matcher.groupCount(); i++) {
            String argument = matcher.group(i);
            if (argument != null) {
                if (argument.equals("_")) {
                    arguments.add(new Variable());    
                } else if (Character.isUpperCase(argument.charAt(0))) {
                    arguments.add(new Variable(argument));
                } else {
                    try {
                        arguments.add(new uk.ac.ucl.cs.programming.coursework.terms.Number(
                                Integer.parseInt(argument)));
                    } catch (NumberFormatException ex) {
                        arguments.add(new Constant(argument));
                    }
                }
            }
        }

        return new Predicate(matcher.group(1), arguments);
    }