Example #1
0
 protected void addToTokenList(List tokenList, Token token) {
   for (int i = 0; i < tokenList.size(); i++) {
     Token currentToken = (Token) tokenList.get(i);
     if (token.start() < currentToken.start()) {
       tokenList.add(i, token);
       return;
     }
   }
   tokenList.add(token);
 }
Example #2
0
  public String process(String input, Map postProcessInfo) {
    List tokenList = new ArrayList();
    postProcessInfo.put("remark", tokenList);
    Iterator itr = ruleList.iterator();

    while (itr.hasNext()) {
      int count = 0;
      Rule rule = (Rule) itr.next();

      while (count < input.length()) {
        int start = -1;
        int end = -1;
        String tokenStr;

        start = input.indexOf(rule.start, count);
        if (start >= 0) {
          count = start + rule.start.length();
          if (rule.end.equals("")) {
            end = start;
          } else {
            end = input.indexOf(rule.end, count);
          }
          if (end >= 0) {
            if (rule.end.equals("")) {
              end += rule.start.length();
            } else {
              end += rule.end.length();
            }
            count = end;
            tokenStr = input.substring(start, end);
            input = replaceToSpace(input, start, end);
            Token token = new Token();
            token.setPos(rule.pos);
            token.setStart(start);
            token.setLength(end - start);
            token.setSurface(tokenStr);
            token.setBasicString(tokenStr);
            token.setPronunciation(tokenStr);
            token.setReading(tokenStr);
            token.setCost(0);
            token.setAddInfo("");
            token.setCform("*");
            token.setTermInfo("");
            addToTokenList(tokenList, token);
          } else {
            count = input.length();
          }
        } else {
          count = input.length();
        }
      }
    }
    return input;
  }