Exemplo n.º 1
0
  /**
   * Count the max score from occurance count list
   *
   * @param rules Vector of RegexRule objects
   * @param occurances list of occurances for each rule in rules
   * @return the total score in range of 0 to 100
   */
  public static int countMaxScore(Vector<RegexRule> rules, int[] occurances) {
    int maxScore = 0;

    if (rules.size() != occurances.length) {
      throw new IndexOutOfBoundsException("countTotalScore parameters don't " + "match");
    }

    for (int ruleNum = 0; ruleNum < rules.size(); ruleNum++) {
      RegexRule rule = (RegexRule) rules.get(ruleNum);
      if (rule.getScore() > 0) {
        maxScore = maxScore + rule.getScore();
      }
    }

    return maxScore;
  }
Exemplo n.º 2
0
  /**
   * Count the total score from occurance count list
   *
   * @param rules Vector of RegexRule objects
   * @param occurances list of occurances for each rule in rules
   * @return the total score in range of 0 to 100
   */
  public static int countScore(Vector<RegexRule> rules, int[] occurances) {
    int totalScore = 0;

    if (rules.size() != occurances.length) {
      throw new IndexOutOfBoundsException("countTotalScore parameters don't " + "match");
    }

    for (int ruleNum = 0; ruleNum < rules.size(); ruleNum++) {
      RegexRule rule = (RegexRule) rules.get(ruleNum);
      // Score from this rule
      int subScore = rule.countScore(occurances[ruleNum]);
      totalScore = totalScore + subScore;
    }

    return totalScore;
  }
Exemplo n.º 3
0
  /**
   * Count the total score from occurance count list
   *
   * @param rules Vector of RegexRule objects
   * @param occurances list of occurances for each rule in rules
   * @return feedback string
   */
  public static String feedbackString(Vector<RegexRule> rules, int[] occurances) {
    int cumulativeScore = 0;
    int cumulativeMaxScore = 0;

    StringBuffer feedback = new StringBuffer();
    feedback.append("test min max cnt mrk oof cum oof lost RE\n");
    for (int i = 0; i < rules.size(); i++) {
      RegexRule rule = (RegexRule) rules.get(i);

      // Max score from this rule
      int thisMaxScore = rule.getScore();
      int thisScore = rule.countScore(occurances[i]);
      if (thisMaxScore > 0) {
        cumulativeMaxScore = cumulativeMaxScore + thisMaxScore;
      }
      cumulativeScore = cumulativeScore + thisScore;

      int lostScore = 0;
      if (thisMaxScore >= 0) {
        lostScore = thisMaxScore - thisScore;
      } else if (thisScore < 0) {
        lostScore = 0 - thisScore;
      }

      // test number
      addNum(feedback, 4, i + 1);
      feedback.append(" ");

      // min
      addNum(feedback, 3, rule.rangeStart);
      feedback.append(" ");
      // max
      addNum(feedback, 3, rule.rangeEnd);
      feedback.append(" ");
      // match count for this rule
      addNum(feedback, 3, occurances[i]);
      feedback.append(" ");
      // score from this rule
      addNum(feedback, 3, thisScore);
      feedback.append(" ");
      // max score from this rule
      addNum(feedback, 3, thisMaxScore);
      feedback.append(" ");
      // total score this far
      addNum(feedback, 3, cumulativeScore);
      feedback.append(" ");
      // max total score this far
      addNum(feedback, 3, cumulativeMaxScore);
      feedback.append(" ");
      // score missed from this rule (very redundant information)
      addNum(feedback, 3, lostScore);
      feedback.append(" ");

      // The pattern string, truncate at 48 chars to fit on a line
      String patternStr = rule.patternString;
      if (patternStr.length() > 48) {
        patternStr = patternStr.substring(0, 48);
      }
      feedback.append(patternStr);

      feedback.append("\n");
    }

    feedback.append("Awarded " + cumulativeScore + "/" + cumulativeMaxScore + " marks\n");

    return feedback.toString();
  }