public boolean areOutcomesCompatible()

in opennlp-tools/src/main/java/opennlp/tools/namefind/BilouCodec.java [147:192]


  public boolean areOutcomesCompatible(String[] outcomes) {
    Set<String> start = new HashSet<>();
    Set<String> cont = new HashSet<>();
    Set<String> last = new HashSet<>();
    Set<String> unit = new HashSet<>();

    for (String outcome : outcomes) {
      if (outcome.endsWith(BilouCodec.START)) {
        start.add(outcome.substring(0, outcome.length() - BilouCodec.START.length()));
      } else if (outcome.endsWith(BilouCodec.CONTINUE)) {
        cont.add(outcome.substring(0, outcome.length() - BilouCodec.CONTINUE.length()));
      } else if (outcome.endsWith(BilouCodec.LAST)) {
        last.add(outcome.substring(0, outcome.length() - BilouCodec.LAST.length()));
      } else if (outcome.endsWith(BilouCodec.UNIT)) {
        unit.add(outcome.substring(0, outcome.length() - BilouCodec.UNIT.length()));
      } else if (!outcome.equals(BilouCodec.OTHER)) {
        return false;
      }
    }

    if (start.isEmpty() && unit.isEmpty()) {
      return false;
    } else {
      // Start, must have matching Last
      for (String startPrefix : start) {
        if (!last.contains(startPrefix)) {
          return false;
        }
      }
      // Cont, must have matching Start and Last
      for (String contPrefix : cont) {
        if (!start.contains(contPrefix) && !last.contains(contPrefix)) {
          return false;
        }
      }
      // Last, must have matching Start
      for (String lastPrefix : last) {
        if (!start.contains(lastPrefix)) {
          return false;
        }
      }

    }

    return true;
  }